blob: f99881758e3a5955c7f19783efbf0eb49d17d1f8 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import os
6import re
7import glob as g
8import shutil
9import tempfile
10from oeqa.selftest.case import OESelftestTestCase
11from oeqa.selftest.cases.buildhistory import BuildhistoryBase
12from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
13import oeqa.utils.ftools as ftools
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014
15class ImageOptionsTests(OESelftestTestCase):
16
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 def test_incremental_image_generation(self):
18 image_pkgtype = get_bb_var("IMAGE_PKGTYPE")
19 if image_pkgtype != 'rpm':
20 self.skipTest('Not using RPM as main package format')
21 bitbake("-c clean core-image-minimal")
22 self.write_config('INC_RPM_IMAGE_GEN = "1"')
23 self.append_config('IMAGE_FEATURES += "ssh-server-openssh"')
24 bitbake("core-image-minimal")
25 log_data_file = os.path.join(get_bb_var("WORKDIR", "core-image-minimal"), "temp/log.do_rootfs")
26 log_data_created = ftools.read_file(log_data_file)
27 incremental_created = re.search(r"Installing\s*:\s*packagegroup-core-ssh-openssh", log_data_created)
28 self.remove_config('IMAGE_FEATURES += "ssh-server-openssh"')
29 self.assertTrue(incremental_created, msg = "Match failed in:\n%s" % log_data_created)
30 bitbake("core-image-minimal")
31 log_data_removed = ftools.read_file(log_data_file)
32 incremental_removed = re.search(r"Erasing\s*:\s*packagegroup-core-ssh-openssh", log_data_removed)
33 self.assertTrue(incremental_removed, msg = "Match failed in:\n%s" % log_data_removed)
34
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035 def test_ccache_tool(self):
Andrew Geissler706d5aa2021-02-12 15:55:30 -060036 bitbake("ccache-native")
37 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native')
38 p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache"
39 self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050040 self.write_config('INHERIT += "ccache"')
Andrew Geisslerd1e89492021-02-12 15:35:20 -060041 recipe = "libgcc-initial"
42 self.add_command_to_tearDown('bitbake -c clean %s' % recipe)
43 bitbake("%s -c clean" % recipe)
44 bitbake("%s -f -c compile" % recipe)
45 log_compile = os.path.join(get_bb_var("WORKDIR", recipe), "temp/log.do_compile")
Brad Bishopf86d0552018-12-04 14:18:15 -080046 with open(log_compile, "r") as f:
47 loglines = "".join(f.readlines())
Andrew Geisslerd1e89492021-02-12 15:35:20 -060048 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 -050049
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050 def test_read_only_image(self):
51 distro_features = get_bb_var('DISTRO_FEATURES')
52 if not ('x11' in distro_features and 'opengl' in distro_features):
Andrew Geisslerc926e172021-05-07 16:11:35 -050053 self.skipTest('core-image-sato/weston requires x11 and opengl in distro features')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050054 self.write_config('IMAGE_FEATURES += "read-only-rootfs"')
Andrew Geisslerc926e172021-05-07 16:11:35 -050055 bitbake("core-image-sato core-image-weston")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056 # do_image will fail if there are any pending postinsts
57
58class DiskMonTest(OESelftestTestCase):
59
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060 def test_stoptask_behavior(self):
Andrew Geisslerc926e172021-05-07 16:11:35 -050061 self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080062 res = bitbake("delay -c delay", ignore_status = True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 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)
64 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 -050065 self.write_config('BB_DISKMON_DIRS = "ABORT,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080066 res = bitbake("delay -c delay", ignore_status = True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067 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)
68 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 -050069 self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
Brad Bishopf86d0552018-12-04 14:18:15 -080070 res = bitbake("delay -c delay")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 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)
72
73class SanityOptionsTest(OESelftestTestCase):
74 def getline(self, res, line):
75 for l in res.output.split('\n'):
76 if line in l:
77 return l
78
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 def test_options_warnqa_errorqa_switch(self):
80
Patrick Williams213cb262021-08-07 19:21:33 -050081 self.write_config("INHERIT:remove = \"report-error\"")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050082 if "packages-list" not in get_bb_var("ERROR_QA"):
Patrick Williams213cb262021-08-07 19:21:33 -050083 self.append_config("ERROR_QA:append = \" packages-list\"")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050084
85 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
86 self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme')
87 res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True)
88 self.delete_recipeinc('xcursor-transparent-theme')
89 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
90 self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
91 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
92 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
Patrick Williams213cb262021-08-07 19:21:33 -050093 self.append_config('ERROR_QA:remove = "packages-list"')
94 self.append_config('WARN_QA:append = " packages-list"')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050095 res = bitbake("xcursor-transparent-theme -f -c package")
96 self.delete_recipeinc('xcursor-transparent-theme')
97 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
98 self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
99
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500100 def test_layer_without_git_dir(self):
101 """
102 Summary: Test that layer git revisions are displayed and do not fail without git repository
103 Expected: The build to be successful and without "fatal" errors
104 Product: oe-core
105 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
106 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
107 """
108
109 dirpath = tempfile.mkdtemp()
110
111 dummy_layer_name = 'meta-dummy'
112 dummy_layer_path = os.path.join(dirpath, dummy_layer_name)
113 dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf')
114 os.makedirs(dummy_layer_conf_dir)
115 dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf')
116
117 dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \
118 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \
119 'BBFILE_COLLECTIONS += "%s"\n' \
120 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \
121 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name)
122
123 ftools.write_file(dummy_layer_conf_path, dummy_layer_content)
124
125 bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path
126 self.write_bblayers_config(bblayers_conf)
127
128 test_recipe = 'ed'
129
130 ret = bitbake('-n %s' % test_recipe)
131
132 err = 'fatal: Not a git repository'
133
134 shutil.rmtree(dirpath)
135
136 self.assertNotIn(err, ret.output)
137
138
139class BuildhistoryTests(BuildhistoryBase):
140
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141 def test_buildhistory_basic(self):
142 self.run_buildhistory_operation('xcursor-transparent-theme')
143 self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.")
144
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145 def test_buildhistory_buildtime_pr_backwards(self):
146 target = 'xcursor-transparent-theme'
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500147 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 -0500148 self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
149 self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error)
150
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500151 def test_fileinfo(self):
152 self.config_buildhistory()
153 bitbake('hicolor-icon-theme')
154 history_dir = get_bb_var('BUILDHISTORY_DIR_PACKAGE', 'hicolor-icon-theme')
155 self.assertTrue(os.path.isdir(history_dir), 'buildhistory dir was not created.')
156
157 def load_bh(f):
158 d = {}
159 for line in open(f):
160 split = [s.strip() for s in line.split('=', 1)]
161 if len(split) > 1:
162 d[split[0]] = split[1]
163 return d
164
165 data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme', 'latest'))
166 self.assertIn('FILELIST', data)
167 self.assertEqual(data['FILELIST'], '/usr/share/icons/hicolor/index.theme')
168 self.assertGreater(int(data['PKGSIZE']), 0)
169
170 data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme-dev', 'latest'))
171 if 'FILELIST' in data:
172 self.assertEqual(data['FILELIST'], '')
173 self.assertEqual(int(data['PKGSIZE']), 0)
174
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500175class ArchiverTest(OESelftestTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500176 def test_arch_work_dir_and_export_source(self):
177 """
178 Test for archiving the work directory and exporting the source files.
179 """
180 self.write_config("INHERIT += \"archiver\"\nARCHIVER_MODE[src] = \"original\"\nARCHIVER_MODE[srpm] = \"1\"")
181 res = bitbake("xcursor-transparent-theme", ignore_status=True)
182 self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output)
183 deploy_dir_src = get_bb_var('DEPLOY_DIR_SRC')
184 pkgs_path = g.glob(str(deploy_dir_src) + "/allarch*/xcurs*")
185 src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm"
186 tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.gz"
187 self.assertTrue((g.glob(src_file_glob) and g.glob(tar_file_glob)), "Couldn't find .src.rpm and .tar.gz files under %s/allarch*/xcursor*" % deploy_dir_src)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400188
189class ToolchainOptions(OESelftestTestCase):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400190 def test_toolchain_fortran(self):
191 """
Brad Bishop96ff1982019-08-19 13:50:42 -0400192 Test that Fortran works by building a Hello, World binary.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400193 """
194
Patrick Williams213cb262021-08-07 19:21:33 -0500195 features = 'FORTRAN:forcevariable = ",fortran"\n'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400196 self.write_config(features)
Brad Bishop96ff1982019-08-19 13:50:42 -0400197 bitbake('fortran-helloworld')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400198
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800199class SourceMirroring(OESelftestTestCase):
200 # Can we download everything from the Yocto Sources Mirror over http only
201 def test_yocto_source_mirror(self):
202 self.write_config("""
203BB_ALLOWED_NETWORKS = "downloads.yoctoproject.org"
204MIRRORS = ""
205DL_DIR = "${TMPDIR}/test_downloads"
Brad Bishop19323692019-04-05 15:28:33 -0400206STAMPS_DIR = "${TMPDIR}/test_stamps"
207SSTATE_DIR = "${TMPDIR}/test_sstate-cache"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800208PREMIRRORS = "\\
209 bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
210 cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
211 git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
212 gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
213 hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
214 osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
215 p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
216 svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
217 ftp://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
218 http://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
219 https://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n"
220""")
221
222 bitbake("world --runall fetch")
223
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500224
225class Poisoning(OESelftestTestCase):
226 def test_poisoning(self):
227 res = bitbake("poison", ignore_status=True)
228 self.assertNotEqual(res.status, 0)
229 self.assertTrue("is unsafe for cross-compilation" in res.output)