Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import os |
| 8 | import re |
| 9 | import glob as g |
| 10 | import shutil |
| 11 | import tempfile |
| 12 | from oeqa.selftest.case import OESelftestTestCase |
| 13 | from oeqa.selftest.cases.buildhistory import BuildhistoryBase |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 14 | from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 15 | import oeqa.utils.ftools as ftools |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | |
| 17 | class ImageOptionsTests(OESelftestTestCase): |
| 18 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | def test_incremental_image_generation(self): |
| 20 | image_pkgtype = get_bb_var("IMAGE_PKGTYPE") |
| 21 | if image_pkgtype != 'rpm': |
| 22 | self.skipTest('Not using RPM as main package format') |
| 23 | bitbake("-c clean core-image-minimal") |
| 24 | self.write_config('INC_RPM_IMAGE_GEN = "1"') |
| 25 | self.append_config('IMAGE_FEATURES += "ssh-server-openssh"') |
| 26 | bitbake("core-image-minimal") |
| 27 | log_data_file = os.path.join(get_bb_var("WORKDIR", "core-image-minimal"), "temp/log.do_rootfs") |
| 28 | log_data_created = ftools.read_file(log_data_file) |
| 29 | incremental_created = re.search(r"Installing\s*:\s*packagegroup-core-ssh-openssh", log_data_created) |
| 30 | self.remove_config('IMAGE_FEATURES += "ssh-server-openssh"') |
| 31 | self.assertTrue(incremental_created, msg = "Match failed in:\n%s" % log_data_created) |
| 32 | bitbake("core-image-minimal") |
| 33 | log_data_removed = ftools.read_file(log_data_file) |
| 34 | incremental_removed = re.search(r"Erasing\s*:\s*packagegroup-core-ssh-openssh", log_data_removed) |
| 35 | self.assertTrue(incremental_removed, msg = "Match failed in:\n%s" % log_data_removed) |
| 36 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 37 | def test_ccache_tool(self): |
Andrew Geissler | 706d5aa | 2021-02-12 15:55:30 -0600 | [diff] [blame] | 38 | bitbake("ccache-native") |
| 39 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native') |
| 40 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache" |
| 41 | self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | self.write_config('INHERIT += "ccache"') |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 43 | recipe = "libgcc-initial" |
| 44 | self.add_command_to_tearDown('bitbake -c clean %s' % recipe) |
| 45 | bitbake("%s -c clean" % recipe) |
| 46 | bitbake("%s -f -c compile" % recipe) |
| 47 | log_compile = os.path.join(get_bb_var("WORKDIR", recipe), "temp/log.do_compile") |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 48 | with open(log_compile, "r") as f: |
| 49 | loglines = "".join(f.readlines()) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 50 | self.assertIn("ccache", loglines, msg="No match for ccache in %s log.do_compile. For further details: %s" % (recipe , log_compile)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 51 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 52 | def test_read_only_image(self): |
| 53 | distro_features = get_bb_var('DISTRO_FEATURES') |
| 54 | if not ('x11' in distro_features and 'opengl' in distro_features): |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 55 | self.skipTest('core-image-sato/weston requires x11 and opengl in distro features') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 56 | self.write_config('IMAGE_FEATURES += "read-only-rootfs"') |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 57 | bitbake("core-image-sato core-image-weston") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 58 | # do_image will fail if there are any pending postinsts |
| 59 | |
| 60 | class DiskMonTest(OESelftestTestCase): |
| 61 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 62 | def test_stoptask_behavior(self): |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 63 | self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"') |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 64 | res = bitbake("delay -c delay", ignore_status = True) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 65 | 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) |
| 66 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 67 | self.write_config('BB_DISKMON_DIRS = "HALT,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"') |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 68 | res = bitbake("delay -c delay", ignore_status = True) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 69 | self.assertTrue('ERROR: Immediately halt since the disk space monitor action is "HALT"!' in res.output, "Tasks should have been halted immediately. Disk monitor is set to HALT: %s" % res.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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)) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 71 | self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"') |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 72 | res = bitbake("delay -c delay") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 73 | 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) |
| 74 | |
| 75 | class SanityOptionsTest(OESelftestTestCase): |
| 76 | def getline(self, res, line): |
| 77 | for l in res.output.split('\n'): |
| 78 | if line in l: |
| 79 | return l |
| 80 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 81 | def test_options_warnqa_errorqa_switch(self): |
| 82 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 83 | self.write_config("INHERIT:remove = \"report-error\"") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 84 | if "packages-list" not in get_bb_var("ERROR_QA"): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 85 | self.append_config("ERROR_QA:append = \" packages-list\"") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 86 | |
| 87 | self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"') |
| 88 | self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme') |
| 89 | res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True) |
| 90 | self.delete_recipeinc('xcursor-transparent-theme') |
| 91 | line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.") |
| 92 | self.assertTrue(line and line.startswith("ERROR:"), msg=res.output) |
| 93 | self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output)) |
| 94 | self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"') |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 95 | self.append_config('ERROR_QA:remove = "packages-list"') |
| 96 | self.append_config('WARN_QA:append = " packages-list"') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 97 | res = bitbake("xcursor-transparent-theme -f -c package") |
| 98 | self.delete_recipeinc('xcursor-transparent-theme') |
| 99 | line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.") |
| 100 | self.assertTrue(line and line.startswith("WARNING:"), msg=res.output) |
| 101 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 102 | def test_layer_without_git_dir(self): |
| 103 | """ |
| 104 | Summary: Test that layer git revisions are displayed and do not fail without git repository |
| 105 | Expected: The build to be successful and without "fatal" errors |
| 106 | Product: oe-core |
| 107 | Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 108 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 109 | """ |
| 110 | |
| 111 | dirpath = tempfile.mkdtemp() |
| 112 | |
| 113 | dummy_layer_name = 'meta-dummy' |
| 114 | dummy_layer_path = os.path.join(dirpath, dummy_layer_name) |
| 115 | dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf') |
| 116 | os.makedirs(dummy_layer_conf_dir) |
| 117 | dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf') |
| 118 | |
| 119 | dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \ |
| 120 | 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \ |
| 121 | 'BBFILE_COLLECTIONS += "%s"\n' \ |
| 122 | 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \ |
| 123 | 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name) |
| 124 | |
| 125 | ftools.write_file(dummy_layer_conf_path, dummy_layer_content) |
| 126 | |
| 127 | bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path |
| 128 | self.write_bblayers_config(bblayers_conf) |
| 129 | |
| 130 | test_recipe = 'ed' |
| 131 | |
| 132 | ret = bitbake('-n %s' % test_recipe) |
| 133 | |
| 134 | err = 'fatal: Not a git repository' |
| 135 | |
| 136 | shutil.rmtree(dirpath) |
| 137 | |
| 138 | self.assertNotIn(err, ret.output) |
| 139 | |
| 140 | |
| 141 | class BuildhistoryTests(BuildhistoryBase): |
| 142 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 143 | def test_buildhistory_basic(self): |
| 144 | self.run_buildhistory_operation('xcursor-transparent-theme') |
| 145 | self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.") |
| 146 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 147 | def test_buildhistory_buildtime_pr_backwards(self): |
| 148 | target = 'xcursor-transparent-theme' |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 149 | error = "ERROR:.*QA Issue: Package version for package %s went backwards which would break package feeds \(from .*-r1.* to .*-r0.*\)" % target |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 150 | self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True) |
| 151 | self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error) |
| 152 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 153 | def test_fileinfo(self): |
| 154 | self.config_buildhistory() |
| 155 | bitbake('hicolor-icon-theme') |
| 156 | history_dir = get_bb_var('BUILDHISTORY_DIR_PACKAGE', 'hicolor-icon-theme') |
| 157 | self.assertTrue(os.path.isdir(history_dir), 'buildhistory dir was not created.') |
| 158 | |
| 159 | def load_bh(f): |
| 160 | d = {} |
| 161 | for line in open(f): |
| 162 | split = [s.strip() for s in line.split('=', 1)] |
| 163 | if len(split) > 1: |
| 164 | d[split[0]] = split[1] |
| 165 | return d |
| 166 | |
| 167 | data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme', 'latest')) |
| 168 | self.assertIn('FILELIST', data) |
| 169 | self.assertEqual(data['FILELIST'], '/usr/share/icons/hicolor/index.theme') |
| 170 | self.assertGreater(int(data['PKGSIZE']), 0) |
| 171 | |
| 172 | data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme-dev', 'latest')) |
| 173 | if 'FILELIST' in data: |
| 174 | self.assertEqual(data['FILELIST'], '') |
| 175 | self.assertEqual(int(data['PKGSIZE']), 0) |
| 176 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 177 | class ArchiverTest(OESelftestTestCase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 178 | def test_arch_work_dir_and_export_source(self): |
| 179 | """ |
| 180 | Test for archiving the work directory and exporting the source files. |
| 181 | """ |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 182 | self.write_config(""" |
| 183 | INHERIT += "archiver" |
| 184 | PACKAGE_CLASSES = "package_rpm" |
| 185 | ARCHIVER_MODE[src] = "original" |
| 186 | ARCHIVER_MODE[srpm] = "1" |
| 187 | """) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | res = bitbake("xcursor-transparent-theme", ignore_status=True) |
| 189 | self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output) |
| 190 | deploy_dir_src = get_bb_var('DEPLOY_DIR_SRC') |
| 191 | pkgs_path = g.glob(str(deploy_dir_src) + "/allarch*/xcurs*") |
| 192 | src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 193 | tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.xz" |
| 194 | self.assertTrue((g.glob(src_file_glob) and g.glob(tar_file_glob)), "Couldn't find .src.rpm and .tar.xz files under %s/allarch*/xcursor*" % deploy_dir_src) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 195 | |
| 196 | class ToolchainOptions(OESelftestTestCase): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 197 | def test_toolchain_fortran(self): |
| 198 | """ |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 199 | Test that Fortran works by building a Hello, World binary. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 200 | """ |
| 201 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 202 | features = 'FORTRAN:forcevariable = ",fortran"\n' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 203 | self.write_config(features) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 204 | bitbake('fortran-helloworld') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 205 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 206 | class SourceMirroring(OESelftestTestCase): |
| 207 | # Can we download everything from the Yocto Sources Mirror over http only |
| 208 | def test_yocto_source_mirror(self): |
| 209 | self.write_config(""" |
| 210 | BB_ALLOWED_NETWORKS = "downloads.yoctoproject.org" |
| 211 | MIRRORS = "" |
| 212 | DL_DIR = "${TMPDIR}/test_downloads" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 213 | STAMPS_DIR = "${TMPDIR}/test_stamps" |
| 214 | SSTATE_DIR = "${TMPDIR}/test_sstate-cache" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 215 | PREMIRRORS = "\\ |
| 216 | bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 217 | cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 218 | git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 219 | gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 220 | hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 221 | osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 222 | p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 223 | svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 224 | ftp://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 225 | http://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\ |
| 226 | https://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n" |
| 227 | """) |
| 228 | |
| 229 | bitbake("world --runall fetch") |
| 230 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 231 | |
| 232 | class Poisoning(OESelftestTestCase): |
| 233 | def test_poisoning(self): |
| 234 | res = bitbake("poison", ignore_status=True) |
| 235 | self.assertNotEqual(res.status, 0) |
| 236 | self.assertTrue("is unsafe for cross-compilation" in res.output) |