Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import os |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | import re |
| 3 | import glob as g |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4 | import shutil |
| 5 | import tempfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | from oeqa.selftest.base import oeSelfTest |
| 7 | from oeqa.selftest.buildhistory import BuildhistoryBase |
| 8 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var |
| 9 | import oeqa.utils.ftools as ftools |
| 10 | from oeqa.utils.decorators import testcase |
| 11 | |
| 12 | class ImageOptionsTests(oeSelfTest): |
| 13 | |
| 14 | @testcase(761) |
| 15 | def test_incremental_image_generation(self): |
| 16 | image_pkgtype = get_bb_var("IMAGE_PKGTYPE") |
| 17 | if image_pkgtype != 'rpm': |
| 18 | self.skipTest('Not using RPM as main package format') |
| 19 | bitbake("-c cleanall core-image-minimal") |
| 20 | self.write_config('INC_RPM_IMAGE_GEN = "1"') |
| 21 | self.append_config('IMAGE_FEATURES += "ssh-server-openssh"') |
| 22 | bitbake("core-image-minimal") |
| 23 | log_data_file = os.path.join(get_bb_var("WORKDIR", "core-image-minimal"), "temp/log.do_rootfs") |
| 24 | log_data_created = ftools.read_file(log_data_file) |
| 25 | 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) |
| 26 | self.remove_config('IMAGE_FEATURES += "ssh-server-openssh"') |
| 27 | self.assertTrue(incremental_created, msg = "Match failed in:\n%s" % log_data_created) |
| 28 | bitbake("core-image-minimal") |
| 29 | log_data_removed = ftools.read_file(log_data_file) |
| 30 | 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) |
| 31 | self.assertTrue(incremental_removed, msg = "Match failed in:\n%s" % log_data_removed) |
| 32 | |
| 33 | @testcase(925) |
| 34 | def test_rm_old_image(self): |
| 35 | bitbake("core-image-minimal") |
| 36 | deploydir = get_bb_var("DEPLOY_DIR_IMAGE", target="core-image-minimal") |
| 37 | imagename = get_bb_var("IMAGE_LINK_NAME", target="core-image-minimal") |
| 38 | deploydir_files = os.listdir(deploydir) |
| 39 | track_original_files = [] |
| 40 | for image_file in deploydir_files: |
| 41 | if imagename in image_file and os.path.islink(os.path.join(deploydir, image_file)): |
| 42 | track_original_files.append(os.path.realpath(os.path.join(deploydir, image_file))) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 43 | self.write_config("RM_OLD_IMAGE = \"1\"") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | bitbake("-C rootfs core-image-minimal") |
| 45 | deploydir_files = os.listdir(deploydir) |
| 46 | remaining_not_expected = [path for path in track_original_files if os.path.basename(path) in deploydir_files] |
| 47 | self.assertFalse(remaining_not_expected, msg="\nThe following image files were not removed: %s" % ', '.join(map(str, remaining_not_expected))) |
| 48 | |
| 49 | @testcase(286) |
| 50 | def test_ccache_tool(self): |
| 51 | bitbake("ccache-native") |
| 52 | 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'))) |
| 53 | self.write_config('INHERIT += "ccache"') |
| 54 | bitbake("m4 -c cleansstate") |
| 55 | bitbake("m4 -c compile") |
| 56 | self.addCleanup(bitbake, 'ccache-native -ccleansstate') |
| 57 | res = runCmd("grep ccache %s" % (os.path.join(get_bb_var("WORKDIR","m4"),"temp/log.do_compile")), ignore_status=True) |
| 58 | 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")) |
| 59 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 60 | @testcase(1435) |
| 61 | def test_read_only_image(self): |
| 62 | self.write_config('IMAGE_FEATURES += "read-only-rootfs"') |
| 63 | bitbake("core-image-sato") |
| 64 | # do_image will fail if there are any pending postinsts |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | |
| 66 | class DiskMonTest(oeSelfTest): |
| 67 | |
| 68 | @testcase(277) |
| 69 | def test_stoptask_behavior(self): |
| 70 | self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"') |
| 71 | res = bitbake("m4", ignore_status = True) |
| 72 | 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) |
| 73 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 74 | self.write_config('BB_DISKMON_DIRS = "ABORT,${TMPDIR},100000G,100K"') |
| 75 | res = bitbake("m4", ignore_status = True) |
| 76 | 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) |
| 77 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 78 | self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"') |
| 79 | res = bitbake("m4") |
| 80 | 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) |
| 81 | |
| 82 | class SanityOptionsTest(oeSelfTest): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 83 | def getline(self, res, line): |
| 84 | for l in res.output.split('\n'): |
| 85 | if line in l: |
| 86 | return l |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | |
| 88 | @testcase(927) |
| 89 | def test_options_warnqa_errorqa_switch(self): |
| 90 | bitbake("xcursor-transparent-theme -ccleansstate") |
| 91 | |
| 92 | if "packages-list" not in get_bb_var("ERROR_QA"): |
| 93 | self.write_config("ERROR_QA_append = \" packages-list\"") |
| 94 | |
| 95 | self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"') |
| 96 | res = bitbake("xcursor-transparent-theme", ignore_status=True) |
| 97 | self.delete_recipeinc('xcursor-transparent-theme') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 98 | line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.") |
| 99 | self.assertTrue(line and line.startswith("ERROR:"), msg=res.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 101 | self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"') |
| 102 | self.append_config('ERROR_QA_remove = "packages-list"') |
| 103 | self.append_config('WARN_QA_append = " packages-list"') |
| 104 | bitbake("xcursor-transparent-theme -ccleansstate") |
| 105 | res = bitbake("xcursor-transparent-theme") |
| 106 | self.delete_recipeinc('xcursor-transparent-theme') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 107 | line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.") |
| 108 | self.assertTrue(line and line.startswith("WARNING:"), msg=res.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | |
| 110 | @testcase(278) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 111 | def test_sanity_unsafe_script_references(self): |
| 112 | self.write_config('WARN_QA_append = " unsafe-references-in-scripts"') |
| 113 | |
| 114 | bitbake("-ccleansstate gzip") |
| 115 | res = bitbake("gzip") |
| 116 | line = self.getline(res, "QA Issue: gzip") |
| 117 | self.assertFalse(line, "WARNING: QA Issue: gzip message is present in bitbake's output and shouldn't be: %s" % res.output) |
| 118 | |
| 119 | self.append_config(""" |
| 120 | do_install_append_pn-gzip () { |
| 121 | echo "\n${bindir}/test" >> ${D}${bindir}/zcat |
| 122 | } |
| 123 | """) |
| 124 | res = bitbake("gzip") |
| 125 | line = self.getline(res, "QA Issue: gzip") |
| 126 | self.assertTrue(line and line.startswith("WARNING:"), "WARNING: QA Issue: gzip message is not present in bitbake's output: %s" % res.output) |
| 127 | |
| 128 | @testcase(1434) |
| 129 | def test_sanity_unsafe_binary_references(self): |
| 130 | self.write_config('WARN_QA_append = " unsafe-references-in-binaries"') |
| 131 | |
| 132 | bitbake("-ccleansstate nfs-utils") |
| 133 | #res = bitbake("nfs-utils") |
| 134 | # FIXME when nfs-utils passes this test |
| 135 | #line = self.getline(res, "QA Issue: nfs-utils") |
| 136 | #self.assertFalse(line, "WARNING: QA Issue: nfs-utils message is present in bitbake's output and shouldn't be: %s" % res.output) |
| 137 | |
| 138 | # self.append_config(""" |
| 139 | #do_install_append_pn-nfs-utils () { |
| 140 | # echo "\n${bindir}/test" >> ${D}${base_sbindir}/osd_login |
| 141 | #} |
| 142 | #""") |
| 143 | res = bitbake("nfs-utils") |
| 144 | line = self.getline(res, "QA Issue: nfs-utils") |
| 145 | self.assertTrue(line and line.startswith("WARNING:"), "WARNING: QA Issue: nfs-utils message is not present in bitbake's output: %s" % res.output) |
| 146 | |
| 147 | @testcase(1421) |
| 148 | def test_layer_without_git_dir(self): |
| 149 | """ |
| 150 | Summary: Test that layer git revisions are displayed and do not fail without git repository |
| 151 | Expected: The build to be successful and without "fatal" errors |
| 152 | Product: oe-core |
| 153 | Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 154 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 155 | """ |
| 156 | |
| 157 | dirpath = tempfile.mkdtemp() |
| 158 | |
| 159 | dummy_layer_name = 'meta-dummy' |
| 160 | dummy_layer_path = os.path.join(dirpath, dummy_layer_name) |
| 161 | dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf') |
| 162 | os.makedirs(dummy_layer_conf_dir) |
| 163 | dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf') |
| 164 | |
| 165 | dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \ |
| 166 | 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \ |
| 167 | 'BBFILE_COLLECTIONS += "%s"\n' \ |
| 168 | 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \ |
| 169 | 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name) |
| 170 | |
| 171 | ftools.write_file(dummy_layer_conf_path, dummy_layer_content) |
| 172 | |
| 173 | bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path |
| 174 | self.write_bblayers_config(bblayers_conf) |
| 175 | |
| 176 | test_recipe = 'ed' |
| 177 | |
| 178 | ret = bitbake('-n %s' % test_recipe) |
| 179 | |
| 180 | err = 'fatal: Not a git repository' |
| 181 | |
| 182 | shutil.rmtree(dirpath) |
| 183 | |
| 184 | self.assertNotIn(err, ret.output) |
| 185 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | |
| 187 | class BuildhistoryTests(BuildhistoryBase): |
| 188 | |
| 189 | @testcase(293) |
| 190 | def test_buildhistory_basic(self): |
| 191 | self.run_buildhistory_operation('xcursor-transparent-theme') |
| 192 | self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.") |
| 193 | |
| 194 | @testcase(294) |
| 195 | def test_buildhistory_buildtime_pr_backwards(self): |
| 196 | self.add_command_to_tearDown('cleanup-workdir') |
| 197 | target = 'xcursor-transparent-theme' |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 198 | error = "ERROR:.*QA Issue: Package version for package %s went backwards which would break package feeds from (.*-r1.* to .*-r0.*)" % target |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True) |
| 200 | self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error) |
| 201 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 202 | @testcase(1386) |
| 203 | def test_buildhistory_does_not_change_signatures(self): |
| 204 | """ |
| 205 | Summary: Ensure that buildhistory does not change signatures |
| 206 | Expected: Only 'do_rootfs' task should be rerun |
| 207 | Product: oe-core |
| 208 | Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 209 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 210 | """ |
| 211 | |
| 212 | tmpdir1_name = 'tmpsig1' |
| 213 | tmpdir2_name = 'tmpsig2' |
| 214 | builddir = os.environ.get('BUILDDIR') |
| 215 | tmpdir1 = os.path.join(builddir, tmpdir1_name) |
| 216 | tmpdir2 = os.path.join(builddir, tmpdir2_name) |
| 217 | |
| 218 | self.track_for_cleanup(tmpdir1) |
| 219 | self.track_for_cleanup(tmpdir2) |
| 220 | |
| 221 | features = 'TMPDIR = "%s"\n' % tmpdir1 |
| 222 | self.write_config(features) |
| 223 | bitbake('core-image-minimal -S none -c rootfs') |
| 224 | |
| 225 | features = 'TMPDIR = "%s"\n' % tmpdir2 |
| 226 | features += 'INHERIT += "buildhistory"\n' |
| 227 | self.write_config(features) |
| 228 | bitbake('core-image-minimal -S none -c rootfs') |
| 229 | |
| 230 | def get_files(d): |
| 231 | f = [] |
| 232 | for root, dirs, files in os.walk(d): |
| 233 | for name in files: |
| 234 | f.append(os.path.join(root, name)) |
| 235 | return f |
| 236 | |
| 237 | files1 = get_files(tmpdir1 + '/stamps') |
| 238 | files2 = get_files(tmpdir2 + '/stamps') |
| 239 | files2 = [x.replace(tmpdir2_name, tmpdir1_name) for x in files2] |
| 240 | |
| 241 | f1 = set(files1) |
| 242 | f2 = set(files2) |
| 243 | sigdiff = f1 - f2 |
| 244 | |
| 245 | self.assertEqual(len(sigdiff), 1, 'Expected 1 signature differences. Out: %s' % list(sigdiff)) |
| 246 | |
| 247 | unexpected_diff = [] |
| 248 | |
| 249 | # No new signatures should appear apart from do_rootfs |
| 250 | found_do_rootfs_flag = False |
| 251 | |
| 252 | for sig in sigdiff: |
| 253 | if 'do_rootfs' in sig: |
| 254 | found_do_rootfs_flag = True |
| 255 | else: |
| 256 | unexpected_diff.append(sig) |
| 257 | |
| 258 | self.assertTrue(found_do_rootfs_flag, 'Task do_rootfs did not rerun.') |
| 259 | self.assertFalse(unexpected_diff, 'Found unexpected signature differences. Out: %s' % unexpected_diff) |
| 260 | |
| 261 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | class BuildImagesTest(oeSelfTest): |
| 263 | @testcase(563) |
| 264 | def test_directfb(self): |
| 265 | """ |
| 266 | This method is used to test the build of directfb image for arm arch. |
| 267 | In essence we build a coreimagedirectfb and test the exitcode of bitbake that in case of success is 0. |
| 268 | """ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 269 | self.add_command_to_tearDown('cleanup-workdir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | self.write_config("DISTRO_FEATURES_remove = \"x11\"\nDISTRO_FEATURES_append = \" directfb\"\nMACHINE ??= \"qemuarm\"") |
| 271 | res = bitbake("core-image-directfb", ignore_status=True) |
| 272 | self.assertEqual(res.status, 0, "\ncoreimagedirectfb failed to build. Please check logs for further details.\nbitbake output %s" % res.output) |
| 273 | |
| 274 | class ArchiverTest(oeSelfTest): |
| 275 | @testcase(926) |
| 276 | def test_arch_work_dir_and_export_source(self): |
| 277 | """ |
| 278 | Test for archiving the work directory and exporting the source files. |
| 279 | """ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 280 | self.add_command_to_tearDown('cleanup-workdir') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 281 | self.write_config("INHERIT += \"archiver\"\nARCHIVER_MODE[src] = \"original\"\nARCHIVER_MODE[srpm] = \"1\"") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 282 | res = bitbake("xcursor-transparent-theme", ignore_status=True) |
| 283 | self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output) |
| 284 | pkgs_path = g.glob(str(self.builddir) + "/tmp/deploy/sources/allarch*/xcurs*") |
| 285 | src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm" |
| 286 | tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.gz" |
| 287 | 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*") |