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