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 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | @testcase(286) |
| 34 | def test_ccache_tool(self): |
| 35 | bitbake("ccache-native") |
| 36 | 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'))) |
| 37 | self.write_config('INHERIT += "ccache"') |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 38 | self.add_command_to_tearDown('bitbake -c clean m4') |
| 39 | bitbake("m4 -f -c compile") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | res = runCmd("grep ccache %s" % (os.path.join(get_bb_var("WORKDIR","m4"),"temp/log.do_compile")), ignore_status=True) |
| 41 | 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")) |
| 42 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 43 | @testcase(1435) |
| 44 | def test_read_only_image(self): |
| 45 | self.write_config('IMAGE_FEATURES += "read-only-rootfs"') |
| 46 | bitbake("core-image-sato") |
| 47 | # do_image will fail if there are any pending postinsts |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | |
| 49 | class DiskMonTest(oeSelfTest): |
| 50 | |
| 51 | @testcase(277) |
| 52 | def test_stoptask_behavior(self): |
| 53 | self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"') |
| 54 | res = bitbake("m4", ignore_status = True) |
| 55 | 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) |
| 56 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 57 | self.write_config('BB_DISKMON_DIRS = "ABORT,${TMPDIR},100000G,100K"') |
| 58 | res = bitbake("m4", ignore_status = True) |
| 59 | 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) |
| 60 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 61 | self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"') |
| 62 | res = bitbake("m4") |
| 63 | 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) |
| 64 | |
| 65 | class SanityOptionsTest(oeSelfTest): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 66 | def getline(self, res, line): |
| 67 | for l in res.output.split('\n'): |
| 68 | if line in l: |
| 69 | return l |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
| 71 | @testcase(927) |
| 72 | def test_options_warnqa_errorqa_switch(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 74 | self.write_config("INHERIT_remove = \"report-error\"") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | if "packages-list" not in get_bb_var("ERROR_QA"): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 76 | self.append_config("ERROR_QA_append = \" packages-list\"") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | |
| 78 | self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"') |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 79 | self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme') |
| 80 | res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | self.delete_recipeinc('xcursor-transparent-theme') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.") |
| 83 | self.assertTrue(line and line.startswith("ERROR:"), msg=res.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 85 | self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"') |
| 86 | self.append_config('ERROR_QA_remove = "packages-list"') |
| 87 | self.append_config('WARN_QA_append = " packages-list"') |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 88 | res = bitbake("xcursor-transparent-theme -f -c package") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | self.delete_recipeinc('xcursor-transparent-theme') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 90 | line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.") |
| 91 | self.assertTrue(line and line.startswith("WARNING:"), msg=res.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | |
| 93 | @testcase(278) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 94 | def test_sanity_unsafe_script_references(self): |
| 95 | self.write_config('WARN_QA_append = " unsafe-references-in-scripts"') |
| 96 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 97 | self.add_command_to_tearDown('bitbake -c clean gzip') |
| 98 | res = bitbake("gzip -f -c package_qa") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 99 | line = self.getline(res, "QA Issue: gzip") |
| 100 | self.assertFalse(line, "WARNING: QA Issue: gzip message is present in bitbake's output and shouldn't be: %s" % res.output) |
| 101 | |
| 102 | self.append_config(""" |
| 103 | do_install_append_pn-gzip () { |
| 104 | echo "\n${bindir}/test" >> ${D}${bindir}/zcat |
| 105 | } |
| 106 | """) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 107 | res = bitbake("gzip -f -c package_qa") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 108 | line = self.getline(res, "QA Issue: gzip") |
| 109 | self.assertTrue(line and line.startswith("WARNING:"), "WARNING: QA Issue: gzip message is not present in bitbake's output: %s" % res.output) |
| 110 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 111 | @testcase(1421) |
| 112 | def test_layer_without_git_dir(self): |
| 113 | """ |
| 114 | Summary: Test that layer git revisions are displayed and do not fail without git repository |
| 115 | Expected: The build to be successful and without "fatal" errors |
| 116 | Product: oe-core |
| 117 | Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 118 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 119 | """ |
| 120 | |
| 121 | dirpath = tempfile.mkdtemp() |
| 122 | |
| 123 | dummy_layer_name = 'meta-dummy' |
| 124 | dummy_layer_path = os.path.join(dirpath, dummy_layer_name) |
| 125 | dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf') |
| 126 | os.makedirs(dummy_layer_conf_dir) |
| 127 | dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf') |
| 128 | |
| 129 | dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \ |
| 130 | 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \ |
| 131 | 'BBFILE_COLLECTIONS += "%s"\n' \ |
| 132 | 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \ |
| 133 | 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name) |
| 134 | |
| 135 | ftools.write_file(dummy_layer_conf_path, dummy_layer_content) |
| 136 | |
| 137 | bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path |
| 138 | self.write_bblayers_config(bblayers_conf) |
| 139 | |
| 140 | test_recipe = 'ed' |
| 141 | |
| 142 | ret = bitbake('-n %s' % test_recipe) |
| 143 | |
| 144 | err = 'fatal: Not a git repository' |
| 145 | |
| 146 | shutil.rmtree(dirpath) |
| 147 | |
| 148 | self.assertNotIn(err, ret.output) |
| 149 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | |
| 151 | class BuildhistoryTests(BuildhistoryBase): |
| 152 | |
| 153 | @testcase(293) |
| 154 | def test_buildhistory_basic(self): |
| 155 | self.run_buildhistory_operation('xcursor-transparent-theme') |
| 156 | self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.") |
| 157 | |
| 158 | @testcase(294) |
| 159 | def test_buildhistory_buildtime_pr_backwards(self): |
| 160 | self.add_command_to_tearDown('cleanup-workdir') |
| 161 | target = 'xcursor-transparent-theme' |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 162 | 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] | 163 | self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True) |
| 164 | self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error) |
| 165 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | class ArchiverTest(oeSelfTest): |
| 167 | @testcase(926) |
| 168 | def test_arch_work_dir_and_export_source(self): |
| 169 | """ |
| 170 | Test for archiving the work directory and exporting the source files. |
| 171 | """ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 172 | self.add_command_to_tearDown('cleanup-workdir') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | 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] | 174 | res = bitbake("xcursor-transparent-theme", ignore_status=True) |
| 175 | self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output) |
| 176 | pkgs_path = g.glob(str(self.builddir) + "/tmp/deploy/sources/allarch*/xcurs*") |
| 177 | src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm" |
| 178 | tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.gz" |
| 179 | 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*") |