blob: 483803bf8d22f4a18c7f2bf685b918d0c6028d52 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import unittest
2import os
3import logging
4import re
5import glob as g
6import pexpect as p
7
8from oeqa.selftest.base import oeSelfTest
9from oeqa.selftest.buildhistory import BuildhistoryBase
10from oeqa.utils.commands import runCmd, bitbake, get_bb_var
11import oeqa.utils.ftools as ftools
12from oeqa.utils.decorators import testcase
13
14class ImageOptionsTests(oeSelfTest):
15
16 @testcase(761)
17 def test_incremental_image_generation(self):
18 image_pkgtype = get_bb_var("IMAGE_PKGTYPE")
19 if image_pkgtype != 'rpm':
20 self.skipTest('Not using RPM as main package format')
21 bitbake("-c cleanall core-image-minimal")
22 self.write_config('INC_RPM_IMAGE_GEN = "1"')
23 self.append_config('IMAGE_FEATURES += "ssh-server-openssh"')
24 bitbake("core-image-minimal")
25 log_data_file = os.path.join(get_bb_var("WORKDIR", "core-image-minimal"), "temp/log.do_rootfs")
26 log_data_created = ftools.read_file(log_data_file)
27 incremental_created = re.search("NOTE: load old install solution for incremental install\nNOTE: old install solution not exist\nNOTE: creating new install solution for incremental install(\n.*)*NOTE: Installing the following packages:.*packagegroup-core-ssh-openssh", log_data_created)
28 self.remove_config('IMAGE_FEATURES += "ssh-server-openssh"')
29 self.assertTrue(incremental_created, msg = "Match failed in:\n%s" % log_data_created)
30 bitbake("core-image-minimal")
31 log_data_removed = ftools.read_file(log_data_file)
32 incremental_removed = re.search("NOTE: load old install solution for incremental install\nNOTE: creating new install solution for incremental install(\n.*)*NOTE: incremental removed:.*openssh-sshd-.*", log_data_removed)
33 self.assertTrue(incremental_removed, msg = "Match failed in:\n%s" % log_data_removed)
34
35 @testcase(925)
36 def test_rm_old_image(self):
37 bitbake("core-image-minimal")
38 deploydir = get_bb_var("DEPLOY_DIR_IMAGE", target="core-image-minimal")
39 imagename = get_bb_var("IMAGE_LINK_NAME", target="core-image-minimal")
40 deploydir_files = os.listdir(deploydir)
41 track_original_files = []
42 for image_file in deploydir_files:
43 if imagename in image_file and os.path.islink(os.path.join(deploydir, image_file)):
44 track_original_files.append(os.path.realpath(os.path.join(deploydir, image_file)))
45 self.append_config("RM_OLD_IMAGE = \"1\"")
46 bitbake("-C rootfs core-image-minimal")
47 deploydir_files = os.listdir(deploydir)
48 remaining_not_expected = [path for path in track_original_files if os.path.basename(path) in deploydir_files]
49 self.assertFalse(remaining_not_expected, msg="\nThe following image files were not removed: %s" % ', '.join(map(str, remaining_not_expected)))
50
51 @testcase(286)
52 def test_ccache_tool(self):
53 bitbake("ccache-native")
54 self.assertTrue(os.path.isfile(os.path.join(get_bb_var('STAGING_BINDIR_NATIVE', 'ccache-native'), "ccache")), msg = "No ccache found under %s" % str(get_bb_var('STAGING_BINDIR_NATIVE', 'ccache-native')))
55 self.write_config('INHERIT += "ccache"')
56 bitbake("m4 -c cleansstate")
57 bitbake("m4 -c compile")
58 self.addCleanup(bitbake, 'ccache-native -ccleansstate')
59 res = runCmd("grep ccache %s" % (os.path.join(get_bb_var("WORKDIR","m4"),"temp/log.do_compile")), ignore_status=True)
60 self.assertEqual(0, res.status, msg="No match for ccache in m4 log.do_compile. For further details: %s" % os.path.join(get_bb_var("WORKDIR","m4"),"temp/log.do_compile"))
61
62
63class DiskMonTest(oeSelfTest):
64
65 @testcase(277)
66 def test_stoptask_behavior(self):
67 self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"')
68 res = bitbake("m4", ignore_status = True)
69 self.assertTrue('ERROR: No new tasks can be executed since the disk space monitor action is "STOPTASKS"!' in res.output, msg = "Tasks should have stopped. Disk monitor is set to STOPTASK: %s" % res.output)
70 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
71 self.write_config('BB_DISKMON_DIRS = "ABORT,${TMPDIR},100000G,100K"')
72 res = bitbake("m4", ignore_status = True)
73 self.assertTrue('ERROR: Immediately abort since the disk space monitor action is "ABORT"!' in res.output, "Tasks should have been aborted immediatelly. Disk monitor is set to ABORT: %s" % res.output)
74 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
75 self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"')
76 res = bitbake("m4")
77 self.assertTrue('WARNING: The free space' in res.output, msg = "A warning should have been displayed for disk monitor is set to WARN: %s" %res.output)
78
79class SanityOptionsTest(oeSelfTest):
80
81 @testcase(927)
82 def test_options_warnqa_errorqa_switch(self):
83 bitbake("xcursor-transparent-theme -ccleansstate")
84
85 if "packages-list" not in get_bb_var("ERROR_QA"):
86 self.write_config("ERROR_QA_append = \" packages-list\"")
87
88 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
89 res = bitbake("xcursor-transparent-theme", ignore_status=True)
90 self.delete_recipeinc('xcursor-transparent-theme')
91 self.assertTrue("ERROR: QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors." in res.output, msg=res.output)
92 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
93 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
94 self.append_config('ERROR_QA_remove = "packages-list"')
95 self.append_config('WARN_QA_append = " packages-list"')
96 bitbake("xcursor-transparent-theme -ccleansstate")
97 res = bitbake("xcursor-transparent-theme")
98 self.delete_recipeinc('xcursor-transparent-theme')
99 self.assertTrue("WARNING: QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors." in res.output, msg=res.output)
100
101 @testcase(278)
102 def test_sanity_userspace_dependency(self):
103 self.append_config('WARN_QA_append = " unsafe-references-in-binaries unsafe-references-in-scripts"')
104 bitbake("-ccleansstate gzip nfs-utils")
105 res = bitbake("gzip nfs-utils")
106 self.assertTrue("WARNING: QA Issue: gzip" in res.output, "WARNING: QA Issue: gzip message is not present in bitbake's output: %s" % res.output)
107 self.assertTrue("WARNING: QA Issue: nfs-utils" in res.output, "WARNING: QA Issue: nfs-utils message is not present in bitbake's output: %s" % res.output)
108
109class BuildhistoryTests(BuildhistoryBase):
110
111 @testcase(293)
112 def test_buildhistory_basic(self):
113 self.run_buildhistory_operation('xcursor-transparent-theme')
114 self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.")
115
116 @testcase(294)
117 def test_buildhistory_buildtime_pr_backwards(self):
118 self.add_command_to_tearDown('cleanup-workdir')
119 target = 'xcursor-transparent-theme'
120 error = "ERROR: QA Issue: Package version for package %s went backwards which would break package feeds from (.*-r1 to .*-r0)" % target
121 self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
122 self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error)
123
124class BuildImagesTest(oeSelfTest):
125 @testcase(563)
126 def test_directfb(self):
127 """
128 This method is used to test the build of directfb image for arm arch.
129 In essence we build a coreimagedirectfb and test the exitcode of bitbake that in case of success is 0.
130 """
131 self.add_command_to_tearDown('cleanupworkdir')
132 self.write_config("DISTRO_FEATURES_remove = \"x11\"\nDISTRO_FEATURES_append = \" directfb\"\nMACHINE ??= \"qemuarm\"")
133 res = bitbake("core-image-directfb", ignore_status=True)
134 self.assertEqual(res.status, 0, "\ncoreimagedirectfb failed to build. Please check logs for further details.\nbitbake output %s" % res.output)
135
136class ArchiverTest(oeSelfTest):
137 @testcase(926)
138 def test_arch_work_dir_and_export_source(self):
139 """
140 Test for archiving the work directory and exporting the source files.
141 """
142 self.add_command_to_tearDown('cleanupworkdir')
143 self.write_config("INHERIT = \"archiver\"\nARCHIVER_MODE[src] = \"original\"\nARCHIVER_MODE[srpm] = \"1\"")
144 res = bitbake("xcursor-transparent-theme", ignore_status=True)
145 self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output)
146 pkgs_path = g.glob(str(self.builddir) + "/tmp/deploy/sources/allarch*/xcurs*")
147 src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm"
148 tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.gz"
149 self.assertTrue((g.glob(src_file_glob) and g.glob(tar_file_glob)), "Couldn't find .src.rpm and .tar.gz files under tmp/deploy/sources/allarch*/xcursor*")