blob: 01ea4dce39554b4e7913039d6c6b1b87f13ba575 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import os
8import re
9import glob as g
10import shutil
11import tempfile
12from oeqa.selftest.case import OESelftestTestCase
13from oeqa.selftest.cases.buildhistory import BuildhistoryBase
Patrick Williams7784c422022-11-17 07:29:11 -060014from oeqa.core.decorator.data import skipIfMachine
Patrick Williams45852732022-04-02 08:58:32 -050015from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016import oeqa.utils.ftools as ftools
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017
18class ImageOptionsTests(OESelftestTestCase):
19
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020 def test_incremental_image_generation(self):
21 image_pkgtype = get_bb_var("IMAGE_PKGTYPE")
22 if image_pkgtype != 'rpm':
23 self.skipTest('Not using RPM as main package format')
24 bitbake("-c clean core-image-minimal")
25 self.write_config('INC_RPM_IMAGE_GEN = "1"')
26 self.append_config('IMAGE_FEATURES += "ssh-server-openssh"')
27 bitbake("core-image-minimal")
28 log_data_file = os.path.join(get_bb_var("WORKDIR", "core-image-minimal"), "temp/log.do_rootfs")
29 log_data_created = ftools.read_file(log_data_file)
30 incremental_created = re.search(r"Installing\s*:\s*packagegroup-core-ssh-openssh", log_data_created)
31 self.remove_config('IMAGE_FEATURES += "ssh-server-openssh"')
32 self.assertTrue(incremental_created, msg = "Match failed in:\n%s" % log_data_created)
33 bitbake("core-image-minimal")
34 log_data_removed = ftools.read_file(log_data_file)
35 incremental_removed = re.search(r"Erasing\s*:\s*packagegroup-core-ssh-openssh", log_data_removed)
36 self.assertTrue(incremental_removed, msg = "Match failed in:\n%s" % log_data_removed)
37
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038 def test_ccache_tool(self):
Andrew Geissler706d5aa2021-02-12 15:55:30 -060039 bitbake("ccache-native")
40 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native')
41 p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache"
42 self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050043 self.write_config('INHERIT += "ccache"')
Andrew Geisslerd1e89492021-02-12 15:35:20 -060044 recipe = "libgcc-initial"
45 self.add_command_to_tearDown('bitbake -c clean %s' % recipe)
46 bitbake("%s -c clean" % recipe)
47 bitbake("%s -f -c compile" % recipe)
48 log_compile = os.path.join(get_bb_var("WORKDIR", recipe), "temp/log.do_compile")
Brad Bishopf86d0552018-12-04 14:18:15 -080049 with open(log_compile, "r") as f:
50 loglines = "".join(f.readlines())
Andrew Geisslerd1e89492021-02-12 15:35:20 -060051 self.assertIn("ccache", loglines, msg="No match for ccache in %s log.do_compile. For further details: %s" % (recipe , log_compile))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052
Patrick Williams7784c422022-11-17 07:29:11 -060053 # https://bugzilla.yoctoproject.org/show_bug.cgi?id=14962
54 @skipIfMachine("qemuarm64", "fails on qemuarm64 (uses SERIAL_CONSOLES_CHECK)")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 def test_read_only_image(self):
56 distro_features = get_bb_var('DISTRO_FEATURES')
57 if not ('x11' in distro_features and 'opengl' in distro_features):
Andrew Geisslerc926e172021-05-07 16:11:35 -050058 self.skipTest('core-image-sato/weston requires x11 and opengl in distro features')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050059 self.write_config('IMAGE_FEATURES += "read-only-rootfs"')
Andrew Geisslerc926e172021-05-07 16:11:35 -050060 bitbake("core-image-sato core-image-weston")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050061 # do_image will fail if there are any pending postinsts
62
63class DiskMonTest(OESelftestTestCase):
64
Brad Bishopd7bf8c12018-02-25 22:55:05 -050065 def test_stoptask_behavior(self):
Andrew Geisslerc926e172021-05-07 16:11:35 -050066 self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080067 res = bitbake("delay -c delay", ignore_status = True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068 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)
69 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 Geissler7e0e3c02022-02-25 20:34:39 +000070 self.write_config('BB_DISKMON_DIRS = "HALT,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080071 res = bitbake("delay -c delay", ignore_status = True)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000072 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 Bishopd7bf8c12018-02-25 22:55:05 -050073 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 Geisslerc926e172021-05-07 16:11:35 -050074 self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080075 res = bitbake("delay -c delay")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 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)
77
78class SanityOptionsTest(OESelftestTestCase):
79 def getline(self, res, line):
80 for l in res.output.split('\n'):
81 if line in l:
82 return l
83
Brad Bishopd7bf8c12018-02-25 22:55:05 -050084 def test_options_warnqa_errorqa_switch(self):
85
Patrick Williams213cb262021-08-07 19:21:33 -050086 self.write_config("INHERIT:remove = \"report-error\"")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087 if "packages-list" not in get_bb_var("ERROR_QA"):
Patrick Williams213cb262021-08-07 19:21:33 -050088 self.append_config("ERROR_QA:append = \" packages-list\"")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050089
90 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
91 self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme')
92 res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True)
93 self.delete_recipeinc('xcursor-transparent-theme')
94 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
95 self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
96 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
97 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
Patrick Williams213cb262021-08-07 19:21:33 -050098 self.append_config('ERROR_QA:remove = "packages-list"')
99 self.append_config('WARN_QA:append = " packages-list"')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500100 res = bitbake("xcursor-transparent-theme -f -c package")
101 self.delete_recipeinc('xcursor-transparent-theme')
102 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
103 self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
104
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500105 def test_layer_without_git_dir(self):
106 """
107 Summary: Test that layer git revisions are displayed and do not fail without git repository
108 Expected: The build to be successful and without "fatal" errors
109 Product: oe-core
110 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
111 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
112 """
113
114 dirpath = tempfile.mkdtemp()
115
116 dummy_layer_name = 'meta-dummy'
117 dummy_layer_path = os.path.join(dirpath, dummy_layer_name)
118 dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf')
119 os.makedirs(dummy_layer_conf_dir)
120 dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf')
121
122 dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \
123 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \
124 'BBFILE_COLLECTIONS += "%s"\n' \
125 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \
126 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name)
127
128 ftools.write_file(dummy_layer_conf_path, dummy_layer_content)
129
130 bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path
131 self.write_bblayers_config(bblayers_conf)
132
133 test_recipe = 'ed'
134
135 ret = bitbake('-n %s' % test_recipe)
136
137 err = 'fatal: Not a git repository'
138
139 shutil.rmtree(dirpath)
140
141 self.assertNotIn(err, ret.output)
142
143
144class BuildhistoryTests(BuildhistoryBase):
145
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500146 def test_buildhistory_basic(self):
147 self.run_buildhistory_operation('xcursor-transparent-theme')
148 self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.")
149
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500150 def test_buildhistory_buildtime_pr_backwards(self):
151 target = 'xcursor-transparent-theme'
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500152 error = "ERROR:.*QA Issue: Package version for package %s went backwards which would break package feeds \(from .*-r1.* to .*-r0.*\)" % target
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500153 self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
154 self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error)
155
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500156 def test_fileinfo(self):
157 self.config_buildhistory()
158 bitbake('hicolor-icon-theme')
159 history_dir = get_bb_var('BUILDHISTORY_DIR_PACKAGE', 'hicolor-icon-theme')
160 self.assertTrue(os.path.isdir(history_dir), 'buildhistory dir was not created.')
161
162 def load_bh(f):
163 d = {}
164 for line in open(f):
165 split = [s.strip() for s in line.split('=', 1)]
166 if len(split) > 1:
167 d[split[0]] = split[1]
168 return d
169
170 data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme', 'latest'))
171 self.assertIn('FILELIST', data)
172 self.assertEqual(data['FILELIST'], '/usr/share/icons/hicolor/index.theme')
173 self.assertGreater(int(data['PKGSIZE']), 0)
174
175 data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme-dev', 'latest'))
176 if 'FILELIST' in data:
177 self.assertEqual(data['FILELIST'], '')
178 self.assertEqual(int(data['PKGSIZE']), 0)
179
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500180class ArchiverTest(OESelftestTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500181 def test_arch_work_dir_and_export_source(self):
182 """
183 Test for archiving the work directory and exporting the source files.
184 """
Patrick Williams45852732022-04-02 08:58:32 -0500185 self.write_config("""
186INHERIT += "archiver"
187PACKAGE_CLASSES = "package_rpm"
188ARCHIVER_MODE[src] = "original"
189ARCHIVER_MODE[srpm] = "1"
190""")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500191 res = bitbake("xcursor-transparent-theme", ignore_status=True)
192 self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output)
193 deploy_dir_src = get_bb_var('DEPLOY_DIR_SRC')
194 pkgs_path = g.glob(str(deploy_dir_src) + "/allarch*/xcurs*")
195 src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm"
Andrew Geissler595f6302022-01-24 19:11:47 +0000196 tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.xz"
197 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 Bishop316dfdd2018-06-25 12:45:53 -0400198
199class ToolchainOptions(OESelftestTestCase):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400200 def test_toolchain_fortran(self):
201 """
Brad Bishop96ff1982019-08-19 13:50:42 -0400202 Test that Fortran works by building a Hello, World binary.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400203 """
204
Patrick Williams213cb262021-08-07 19:21:33 -0500205 features = 'FORTRAN:forcevariable = ",fortran"\n'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400206 self.write_config(features)
Brad Bishop96ff1982019-08-19 13:50:42 -0400207 bitbake('fortran-helloworld')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400208
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800209class SourceMirroring(OESelftestTestCase):
210 # Can we download everything from the Yocto Sources Mirror over http only
211 def test_yocto_source_mirror(self):
212 self.write_config("""
213BB_ALLOWED_NETWORKS = "downloads.yoctoproject.org"
214MIRRORS = ""
215DL_DIR = "${TMPDIR}/test_downloads"
Brad Bishop19323692019-04-05 15:28:33 -0400216STAMPS_DIR = "${TMPDIR}/test_stamps"
217SSTATE_DIR = "${TMPDIR}/test_sstate-cache"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800218PREMIRRORS = "\\
219 bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
220 cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
221 git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
222 gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
223 hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
224 osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
225 p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
226 svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
227 ftp://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
228 http://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
229 https://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n"
230""")
231
232 bitbake("world --runall fetch")
233
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500234
235class Poisoning(OESelftestTestCase):
236 def test_poisoning(self):
237 res = bitbake("poison", ignore_status=True)
238 self.assertNotEqual(res.status, 0)
239 self.assertTrue("is unsafe for cross-compilation" in res.output)