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