blob: 104448442ad168cfdf2442e792b0b65c6c86ddac [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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050053 def test_read_only_image(self):
54 distro_features = get_bb_var('DISTRO_FEATURES')
55 if not ('x11' in distro_features and 'opengl' in distro_features):
Andrew Geisslerc926e172021-05-07 16:11:35 -050056 self.skipTest('core-image-sato/weston requires x11 and opengl in distro features')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057 self.write_config('IMAGE_FEATURES += "read-only-rootfs"')
Andrew Geisslerc926e172021-05-07 16:11:35 -050058 bitbake("core-image-sato core-image-weston")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050059 # do_image will fail if there are any pending postinsts
60
61class DiskMonTest(OESelftestTestCase):
62
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 def test_stoptask_behavior(self):
Andrew Geisslerc926e172021-05-07 16:11:35 -050064 self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080065 res = bitbake("delay -c delay", ignore_status = True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066 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))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000068 self.write_config('BB_DISKMON_DIRS = "HALT,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080069 res = bitbake("delay -c delay", ignore_status = True)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000070 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 -050071 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 -050072 self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080073 res = bitbake("delay -c delay")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050074 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
76class SanityOptionsTest(OESelftestTestCase):
77 def getline(self, res, line):
78 for l in res.output.split('\n'):
79 if line in l:
80 return l
81
Brad Bishopd7bf8c12018-02-25 22:55:05 -050082 def test_options_warnqa_errorqa_switch(self):
83
Patrick Williams213cb262021-08-07 19:21:33 -050084 self.write_config("INHERIT:remove = \"report-error\"")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085 if "packages-list" not in get_bb_var("ERROR_QA"):
Patrick Williams213cb262021-08-07 19:21:33 -050086 self.append_config("ERROR_QA:append = \" packages-list\"")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087
88 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
89 self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme')
90 res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True)
91 self.delete_recipeinc('xcursor-transparent-theme')
92 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
93 self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
94 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
95 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
Patrick Williams213cb262021-08-07 19:21:33 -050096 self.append_config('ERROR_QA:remove = "packages-list"')
97 self.append_config('WARN_QA:append = " packages-list"')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098 res = bitbake("xcursor-transparent-theme -f -c package")
99 self.delete_recipeinc('xcursor-transparent-theme')
100 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
101 self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
102
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500103 def test_layer_without_git_dir(self):
104 """
105 Summary: Test that layer git revisions are displayed and do not fail without git repository
106 Expected: The build to be successful and without "fatal" errors
107 Product: oe-core
108 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
109 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
110 """
111
112 dirpath = tempfile.mkdtemp()
113
114 dummy_layer_name = 'meta-dummy'
115 dummy_layer_path = os.path.join(dirpath, dummy_layer_name)
116 dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf')
117 os.makedirs(dummy_layer_conf_dir)
118 dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf')
119
120 dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \
121 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \
122 'BBFILE_COLLECTIONS += "%s"\n' \
123 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \
124 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name)
125
126 ftools.write_file(dummy_layer_conf_path, dummy_layer_content)
127
128 bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path
129 self.write_bblayers_config(bblayers_conf)
130
131 test_recipe = 'ed'
132
133 ret = bitbake('-n %s' % test_recipe)
134
135 err = 'fatal: Not a git repository'
136
137 shutil.rmtree(dirpath)
138
139 self.assertNotIn(err, ret.output)
140
141
142class BuildhistoryTests(BuildhistoryBase):
143
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144 def test_buildhistory_basic(self):
145 self.run_buildhistory_operation('xcursor-transparent-theme')
146 self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.")
147
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148 def test_buildhistory_buildtime_pr_backwards(self):
149 target = 'xcursor-transparent-theme'
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500150 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 -0500151 self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
152 self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error)
153
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500154 def test_fileinfo(self):
155 self.config_buildhistory()
156 bitbake('hicolor-icon-theme')
157 history_dir = get_bb_var('BUILDHISTORY_DIR_PACKAGE', 'hicolor-icon-theme')
158 self.assertTrue(os.path.isdir(history_dir), 'buildhistory dir was not created.')
159
160 def load_bh(f):
161 d = {}
162 for line in open(f):
163 split = [s.strip() for s in line.split('=', 1)]
164 if len(split) > 1:
165 d[split[0]] = split[1]
166 return d
167
168 data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme', 'latest'))
169 self.assertIn('FILELIST', data)
170 self.assertEqual(data['FILELIST'], '/usr/share/icons/hicolor/index.theme')
171 self.assertGreater(int(data['PKGSIZE']), 0)
172
173 data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme-dev', 'latest'))
174 if 'FILELIST' in data:
175 self.assertEqual(data['FILELIST'], '')
176 self.assertEqual(int(data['PKGSIZE']), 0)
177
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500178class ArchiverTest(OESelftestTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500179 def test_arch_work_dir_and_export_source(self):
180 """
181 Test for archiving the work directory and exporting the source files.
182 """
Patrick Williams45852732022-04-02 08:58:32 -0500183 self.write_config("""
184INHERIT += "archiver"
185PACKAGE_CLASSES = "package_rpm"
186ARCHIVER_MODE[src] = "original"
187ARCHIVER_MODE[srpm] = "1"
188""")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500189 res = bitbake("xcursor-transparent-theme", ignore_status=True)
190 self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output)
191 deploy_dir_src = get_bb_var('DEPLOY_DIR_SRC')
192 pkgs_path = g.glob(str(deploy_dir_src) + "/allarch*/xcurs*")
193 src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm"
Andrew Geissler595f6302022-01-24 19:11:47 +0000194 tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.xz"
195 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 -0400196
197class ToolchainOptions(OESelftestTestCase):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400198 def test_toolchain_fortran(self):
199 """
Brad Bishop96ff1982019-08-19 13:50:42 -0400200 Test that Fortran works by building a Hello, World binary.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400201 """
202
Patrick Williams213cb262021-08-07 19:21:33 -0500203 features = 'FORTRAN:forcevariable = ",fortran"\n'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400204 self.write_config(features)
Brad Bishop96ff1982019-08-19 13:50:42 -0400205 bitbake('fortran-helloworld')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400206
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800207class SourceMirroring(OESelftestTestCase):
208 # Can we download everything from the Yocto Sources Mirror over http only
209 def test_yocto_source_mirror(self):
210 self.write_config("""
211BB_ALLOWED_NETWORKS = "downloads.yoctoproject.org"
212MIRRORS = ""
213DL_DIR = "${TMPDIR}/test_downloads"
Brad Bishop19323692019-04-05 15:28:33 -0400214STAMPS_DIR = "${TMPDIR}/test_stamps"
215SSTATE_DIR = "${TMPDIR}/test_sstate-cache"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800216PREMIRRORS = "\\
217 bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
218 cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
219 git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
220 gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
221 hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
222 osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
223 p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
224 svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
225 ftp://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
226 http://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
227 https://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n"
228""")
229
230 bitbake("world --runall fetch")
231
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500232
233class Poisoning(OESelftestTestCase):
234 def test_poisoning(self):
235 res = bitbake("poison", ignore_status=True)
236 self.assertNotEqual(res.status, 0)
237 self.assertTrue("is unsafe for cross-compilation" in res.output)