blob: 6a5378d3ff6609a4bffca13b0e029c3c3fc30c2a [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):
36 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)
40 self.write_config('INHERIT += "ccache"')
Brad Bishop19323692019-04-05 15:28:33 -040041 self.add_command_to_tearDown('bitbake -c clean m4-native')
42 bitbake("m4-native -c clean")
43 bitbake("m4-native -f -c compile")
44 log_compile = os.path.join(get_bb_var("WORKDIR","m4-native"), "temp/log.do_compile")
Brad Bishopf86d0552018-12-04 14:18:15 -080045 with open(log_compile, "r") as f:
46 loglines = "".join(f.readlines())
Brad Bishop19323692019-04-05 15:28:33 -040047 self.assertIn("ccache", loglines, msg="No match for ccache in m4-native log.do_compile. For further details: %s" % log_compile)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050048
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 def test_read_only_image(self):
50 distro_features = get_bb_var('DISTRO_FEATURES')
51 if not ('x11' in distro_features and 'opengl' in distro_features):
52 self.skipTest('core-image-sato requires x11 and opengl in distro features')
53 self.write_config('IMAGE_FEATURES += "read-only-rootfs"')
54 bitbake("core-image-sato")
55 # do_image will fail if there are any pending postinsts
56
57class DiskMonTest(OESelftestTestCase):
58
Brad Bishopd7bf8c12018-02-25 22:55:05 -050059 def test_stoptask_behavior(self):
60 self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"')
Brad Bishopf86d0552018-12-04 14:18:15 -080061 res = bitbake("delay -c delay", ignore_status = True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050062 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)
63 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
64 self.write_config('BB_DISKMON_DIRS = "ABORT,${TMPDIR},100000G,100K"')
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: 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)
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))
68 self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"')
Brad Bishopf86d0552018-12-04 14:18:15 -080069 res = bitbake("delay -c delay")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 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)
71
72class SanityOptionsTest(OESelftestTestCase):
73 def getline(self, res, line):
74 for l in res.output.split('\n'):
75 if line in l:
76 return l
77
Brad Bishopd7bf8c12018-02-25 22:55:05 -050078 def test_options_warnqa_errorqa_switch(self):
79
80 self.write_config("INHERIT_remove = \"report-error\"")
81 if "packages-list" not in get_bb_var("ERROR_QA"):
82 self.append_config("ERROR_QA_append = \" packages-list\"")
83
84 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
85 self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme')
86 res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True)
87 self.delete_recipeinc('xcursor-transparent-theme')
88 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
89 self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
90 self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
91 self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
92 self.append_config('ERROR_QA_remove = "packages-list"')
93 self.append_config('WARN_QA_append = " packages-list"')
94 res = bitbake("xcursor-transparent-theme -f -c package")
95 self.delete_recipeinc('xcursor-transparent-theme')
96 line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
97 self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
98
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099 def test_layer_without_git_dir(self):
100 """
101 Summary: Test that layer git revisions are displayed and do not fail without git repository
102 Expected: The build to be successful and without "fatal" errors
103 Product: oe-core
104 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
105 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
106 """
107
108 dirpath = tempfile.mkdtemp()
109
110 dummy_layer_name = 'meta-dummy'
111 dummy_layer_path = os.path.join(dirpath, dummy_layer_name)
112 dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf')
113 os.makedirs(dummy_layer_conf_dir)
114 dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf')
115
116 dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \
117 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \
118 'BBFILE_COLLECTIONS += "%s"\n' \
119 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \
120 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name)
121
122 ftools.write_file(dummy_layer_conf_path, dummy_layer_content)
123
124 bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path
125 self.write_bblayers_config(bblayers_conf)
126
127 test_recipe = 'ed'
128
129 ret = bitbake('-n %s' % test_recipe)
130
131 err = 'fatal: Not a git repository'
132
133 shutil.rmtree(dirpath)
134
135 self.assertNotIn(err, ret.output)
136
137
138class BuildhistoryTests(BuildhistoryBase):
139
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140 def test_buildhistory_basic(self):
141 self.run_buildhistory_operation('xcursor-transparent-theme')
142 self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.")
143
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144 def test_buildhistory_buildtime_pr_backwards(self):
145 target = 'xcursor-transparent-theme'
146 error = "ERROR:.*QA Issue: Package version for package %s went backwards which would break package feeds from (.*-r1.* to .*-r0.*)" % target
147 self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
148 self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error)
149
150class ArchiverTest(OESelftestTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151 def test_arch_work_dir_and_export_source(self):
152 """
153 Test for archiving the work directory and exporting the source files.
154 """
155 self.write_config("INHERIT += \"archiver\"\nARCHIVER_MODE[src] = \"original\"\nARCHIVER_MODE[srpm] = \"1\"")
156 res = bitbake("xcursor-transparent-theme", ignore_status=True)
157 self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output)
158 deploy_dir_src = get_bb_var('DEPLOY_DIR_SRC')
159 pkgs_path = g.glob(str(deploy_dir_src) + "/allarch*/xcurs*")
160 src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm"
161 tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.gz"
162 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 -0400163
164class ToolchainOptions(OESelftestTestCase):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400165 def test_toolchain_fortran(self):
166 """
Brad Bishop96ff1982019-08-19 13:50:42 -0400167 Test that Fortran works by building a Hello, World binary.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400168 """
169
170 features = 'FORTRAN_forcevariable = ",fortran"\n'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400171 self.write_config(features)
Brad Bishop96ff1982019-08-19 13:50:42 -0400172 bitbake('fortran-helloworld')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400173
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800174class SourceMirroring(OESelftestTestCase):
175 # Can we download everything from the Yocto Sources Mirror over http only
176 def test_yocto_source_mirror(self):
177 self.write_config("""
178BB_ALLOWED_NETWORKS = "downloads.yoctoproject.org"
179MIRRORS = ""
180DL_DIR = "${TMPDIR}/test_downloads"
Brad Bishop19323692019-04-05 15:28:33 -0400181STAMPS_DIR = "${TMPDIR}/test_stamps"
182SSTATE_DIR = "${TMPDIR}/test_sstate-cache"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800183PREMIRRORS = "\\
184 bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
185 cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
186 git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
187 gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
188 hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
189 osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
190 p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
191 svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
192 ftp://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
193 http://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
194 https://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n"
195""")
196
197 bitbake("world --runall fetch")
198