Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import os |
| 8 | import shutil |
| 9 | import glob |
| 10 | import subprocess |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 11 | import tempfile |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 12 | import datetime |
| 13 | import re |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 14 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 15 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer, get_bb_vars |
| 16 | from oeqa.selftest.case import OESelftestTestCase |
| 17 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 18 | import oe |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | import bb.siggen |
| 20 | |
Patrick Williams | b542dec | 2023-06-09 01:26:37 -0500 | [diff] [blame] | 21 | # Set to True to preserve stamp files after test execution for debugging failures |
| 22 | keep_temp_files = False |
| 23 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 24 | class SStateBase(OESelftestTestCase): |
| 25 | |
| 26 | def setUpLocal(self): |
| 27 | super(SStateBase, self).setUpLocal() |
| 28 | self.temp_sstate_location = None |
| 29 | needed_vars = ['SSTATE_DIR', 'NATIVELSBSTRING', 'TCLIBC', 'TUNE_ARCH', |
| 30 | 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS'] |
| 31 | bb_vars = get_bb_vars(needed_vars) |
| 32 | self.sstate_path = bb_vars['SSTATE_DIR'] |
| 33 | self.hostdistro = bb_vars['NATIVELSBSTRING'] |
| 34 | self.tclibc = bb_vars['TCLIBC'] |
| 35 | self.tune_arch = bb_vars['TUNE_ARCH'] |
| 36 | self.topdir = bb_vars['TOPDIR'] |
| 37 | self.target_vendor = bb_vars['TARGET_VENDOR'] |
| 38 | self.target_os = bb_vars['TARGET_OS'] |
| 39 | self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro) |
| 40 | |
Patrick Williams | b542dec | 2023-06-09 01:26:37 -0500 | [diff] [blame] | 41 | def track_for_cleanup(self, path): |
| 42 | if not keep_temp_files: |
| 43 | super().track_for_cleanup(path) |
| 44 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 45 | # Creates a special sstate configuration with the option to add sstate mirrors |
| 46 | def config_sstate(self, temp_sstate_location=False, add_local_mirrors=[]): |
| 47 | self.temp_sstate_location = temp_sstate_location |
| 48 | |
| 49 | if self.temp_sstate_location: |
| 50 | temp_sstate_path = os.path.join(self.builddir, "temp_sstate_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')) |
| 51 | config_temp_sstate = "SSTATE_DIR = \"%s\"" % temp_sstate_path |
| 52 | self.append_config(config_temp_sstate) |
| 53 | self.track_for_cleanup(temp_sstate_path) |
| 54 | bb_vars = get_bb_vars(['SSTATE_DIR', 'NATIVELSBSTRING']) |
| 55 | self.sstate_path = bb_vars['SSTATE_DIR'] |
| 56 | self.hostdistro = bb_vars['NATIVELSBSTRING'] |
| 57 | self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro) |
| 58 | |
| 59 | if add_local_mirrors: |
| 60 | config_set_sstate_if_not_set = 'SSTATE_MIRRORS ?= ""' |
| 61 | self.append_config(config_set_sstate_if_not_set) |
| 62 | for local_mirror in add_local_mirrors: |
| 63 | self.assertFalse(os.path.join(local_mirror) == os.path.join(self.sstate_path), msg='Cannot add the current sstate path as a sstate mirror') |
| 64 | config_sstate_mirror = "SSTATE_MIRRORS += \"file://.* file:///%s/PATH\"" % local_mirror |
| 65 | self.append_config(config_sstate_mirror) |
| 66 | |
| 67 | # Returns a list containing sstate files |
| 68 | def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True): |
| 69 | result = [] |
| 70 | for root, dirs, files in os.walk(self.sstate_path): |
| 71 | if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root): |
| 72 | for f in files: |
| 73 | if re.search(filename_regex, f): |
| 74 | result.append(f) |
| 75 | if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root): |
| 76 | for f in files: |
| 77 | if re.search(filename_regex, f): |
| 78 | result.append(f) |
| 79 | return result |
| 80 | |
| 81 | # Test sstate files creation and their location |
| 82 | def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): |
| 83 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
| 84 | |
| 85 | if self.temp_sstate_location: |
| 86 | bitbake(['-cclean'] + targets) |
| 87 | else: |
| 88 | bitbake(['-ccleansstate'] + targets) |
| 89 | |
| 90 | bitbake(targets) |
| 91 | file_tracker = [] |
| 92 | results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific) |
| 93 | if distro_nonspecific: |
| 94 | for r in results: |
| 95 | if r.endswith(("_populate_lic.tar.zst", "_populate_lic.tar.zst.siginfo", "_fetch.tar.zst.siginfo", "_unpack.tar.zst.siginfo", "_patch.tar.zst.siginfo")): |
| 96 | continue |
| 97 | file_tracker.append(r) |
| 98 | else: |
| 99 | file_tracker = results |
| 100 | |
| 101 | if should_pass: |
| 102 | self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets))) |
| 103 | else: |
| 104 | self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker))) |
| 105 | |
| 106 | # Test the sstate files deletion part of the do_cleansstate task |
| 107 | def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): |
| 108 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
| 109 | |
| 110 | bitbake(['-ccleansstate'] + targets) |
| 111 | |
| 112 | bitbake(targets) |
| 113 | archives_created = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific, distro_nonspecific) |
| 114 | self.assertTrue(archives_created, msg="Could not find sstate .tar.zst files for: %s (%s)" % (', '.join(map(str, targets)), str(archives_created))) |
| 115 | |
| 116 | siginfo_created = self.search_sstate('|'.join(map(str, [s + r'.*?\.siginfo$' for s in targets])), distro_specific, distro_nonspecific) |
| 117 | self.assertTrue(siginfo_created, msg="Could not find sstate .siginfo files for: %s (%s)" % (', '.join(map(str, targets)), str(siginfo_created))) |
| 118 | |
| 119 | bitbake(['-ccleansstate'] + targets) |
| 120 | archives_removed = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific, distro_nonspecific) |
| 121 | self.assertTrue(not archives_removed, msg="do_cleansstate didn't remove .tar.zst sstate files for: %s (%s)" % (', '.join(map(str, targets)), str(archives_removed))) |
| 122 | |
| 123 | # Test rebuilding of distro-specific sstate files |
| 124 | def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True): |
| 125 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
| 126 | |
| 127 | bitbake(['-ccleansstate'] + targets) |
| 128 | |
| 129 | bitbake(targets) |
| 130 | results = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific=False, distro_nonspecific=True) |
| 131 | filtered_results = [] |
| 132 | for r in results: |
| 133 | if r.endswith(("_populate_lic.tar.zst", "_populate_lic.tar.zst.siginfo")): |
| 134 | continue |
| 135 | filtered_results.append(r) |
| 136 | self.assertTrue(filtered_results == [], msg="Found distro non-specific sstate for: %s (%s)" % (', '.join(map(str, targets)), str(filtered_results))) |
| 137 | file_tracker_1 = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific=True, distro_nonspecific=False) |
| 138 | self.assertTrue(len(file_tracker_1) >= len(targets), msg = "Not all sstate files were created for: %s" % ', '.join(map(str, targets))) |
| 139 | |
| 140 | self.track_for_cleanup(self.distro_specific_sstate + "_old") |
| 141 | shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old") |
| 142 | shutil.rmtree(self.distro_specific_sstate) |
| 143 | |
| 144 | bitbake(['-cclean'] + targets) |
| 145 | bitbake(targets) |
| 146 | file_tracker_2 = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific=True, distro_nonspecific=False) |
| 147 | self.assertTrue(len(file_tracker_2) >= len(targets), msg = "Not all sstate files were created for: %s" % ', '.join(map(str, targets))) |
| 148 | |
| 149 | not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2] |
| 150 | self.assertTrue(not_recreated == [], msg="The following sstate files were not recreated: %s" % ', '.join(map(str, not_recreated))) |
| 151 | |
| 152 | created_once = [x for x in file_tracker_2 if x not in file_tracker_1] |
| 153 | self.assertTrue(created_once == [], msg="The following sstate files were created only in the second run: %s" % ', '.join(map(str, created_once))) |
| 154 | |
| 155 | def sstate_common_samesigs(self, configA, configB, allarch=False): |
| 156 | |
| 157 | self.write_config(configA) |
| 158 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
| 159 | bitbake("world meta-toolchain -S none") |
| 160 | self.write_config(configB) |
| 161 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
| 162 | bitbake("world meta-toolchain -S none") |
| 163 | |
| 164 | def get_files(d, result): |
| 165 | for root, dirs, files in os.walk(d): |
| 166 | for name in files: |
| 167 | if "meta-environment" in root or "cross-canadian" in root: |
| 168 | continue |
| 169 | if "do_build" not in name: |
| 170 | # 1.4.1+gitAUTOINC+302fca9f4c-r0.do_package_write_ipk.sigdata.f3a2a38697da743f0dbed8b56aafcf79 |
| 171 | (_, task, _, shash) = name.rsplit(".", 3) |
| 172 | result[os.path.join(os.path.basename(root), task)] = shash |
| 173 | |
| 174 | files1 = {} |
| 175 | files2 = {} |
| 176 | subdirs = sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/*-nativesdk*-linux")) |
| 177 | if allarch: |
| 178 | subdirs.extend(sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/all-*-linux"))) |
| 179 | |
| 180 | for subdir in subdirs: |
| 181 | nativesdkdir = os.path.basename(subdir) |
| 182 | get_files(self.topdir + "/tmp-sstatesamehash/stamps/" + nativesdkdir, files1) |
| 183 | get_files(self.topdir + "/tmp-sstatesamehash2/stamps/" + nativesdkdir, files2) |
| 184 | |
| 185 | self.maxDiff = None |
| 186 | self.assertEqual(files1, files2) |
| 187 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | class SStateTests(SStateBase): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 189 | def test_autorev_sstate_works(self): |
| 190 | # Test that a git repository which changes is correctly handled by SRCREV = ${AUTOREV} |
| 191 | # when PV does not contain SRCPV |
| 192 | |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 193 | tempdir = tempfile.mkdtemp(prefix='sstate_autorev') |
| 194 | tempdldir = tempfile.mkdtemp(prefix='sstate_autorev_dldir') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 195 | self.track_for_cleanup(tempdir) |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 196 | self.track_for_cleanup(tempdldir) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 197 | create_temp_layer(tempdir, 'selftestrecipetool') |
| 198 | self.add_command_to_tearDown('bitbake-layers remove-layer %s' % tempdir) |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 199 | self.append_config("DL_DIR = \"%s\"" % tempdldir) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 200 | runCmd('bitbake-layers add-layer %s' % tempdir) |
| 201 | |
| 202 | # Use dbus-wait as a local git repo we can add a commit between two builds in |
| 203 | pn = 'dbus-wait' |
| 204 | srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517' |
| 205 | url = 'git://git.yoctoproject.org/dbus-wait' |
| 206 | result = runCmd('git clone %s noname' % url, cwd=tempdir) |
| 207 | srcdir = os.path.join(tempdir, 'noname') |
| 208 | result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir) |
| 209 | self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory') |
| 210 | |
| 211 | recipefile = os.path.join(tempdir, "recipes-test", "dbus-wait-test", 'dbus-wait-test_git.bb') |
| 212 | os.makedirs(os.path.dirname(recipefile)) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 213 | srcuri = 'git://' + srcdir + ';protocol=file;branch=master' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 214 | result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri]) |
| 215 | self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output) |
| 216 | |
| 217 | with open(recipefile, 'a') as f: |
| 218 | f.write('SRCREV = "${AUTOREV}"\n') |
| 219 | f.write('PV = "1.0"\n') |
| 220 | |
| 221 | bitbake("dbus-wait-test -c fetch") |
| 222 | with open(os.path.join(srcdir, "bar.txt"), "w") as f: |
| 223 | f.write("foo") |
| 224 | result = runCmd('git add bar.txt; git commit -asm "add bar"', cwd=srcdir) |
| 225 | bitbake("dbus-wait-test -c unpack") |
| 226 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 227 | class SStateCreation(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 228 | def test_sstate_creation_distro_specific_pass(self): |
| 229 | self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) |
| 230 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 231 | def test_sstate_creation_distro_specific_fail(self): |
| 232 | self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True, should_pass=False) |
| 233 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 234 | def test_sstate_creation_distro_nonspecific_pass(self): |
| 235 | self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) |
| 236 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 237 | def test_sstate_creation_distro_nonspecific_fail(self): |
| 238 | self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False) |
| 239 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 240 | class SStateCleanup(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 241 | def test_cleansstate_task_distro_specific_nonspecific(self): |
| 242 | targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native'] |
| 243 | targets.append('linux-libc-headers') |
| 244 | self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True) |
| 245 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 246 | def test_cleansstate_task_distro_nonspecific(self): |
| 247 | self.run_test_cleansstate_task(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) |
| 248 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 249 | def test_cleansstate_task_distro_specific(self): |
| 250 | targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native'] |
| 251 | targets.append('linux-libc-headers') |
| 252 | self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) |
| 253 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 254 | class SStateDistroTests(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 255 | def test_rebuild_distro_specific_sstate_cross_native_targets(self): |
| 256 | self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch, 'binutils-native'], temp_sstate_location=True) |
| 257 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 258 | def test_rebuild_distro_specific_sstate_cross_target(self): |
| 259 | self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch], temp_sstate_location=True) |
| 260 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 261 | def test_rebuild_distro_specific_sstate_native_target(self): |
| 262 | self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True) |
| 263 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 264 | class SStateCacheManagement(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 265 | # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list |
| 266 | # global_config elements are expected to not generate any sstate files that would be removed by sstate-cache-management.sh (such as changing the value of MACHINE) |
| 267 | def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=[''], ignore_patterns=[]): |
| 268 | self.assertTrue(global_config) |
| 269 | self.assertTrue(target_config) |
| 270 | self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements') |
| 271 | self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path]) |
| 272 | |
| 273 | # If buildhistory is enabled, we need to disable version-going-backwards |
| 274 | # QA checks for this test. It may report errors otherwise. |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 275 | self.append_config('ERROR_QA:remove = "version-going-backwards"') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 276 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 277 | # For now this only checks if random sstate tasks are handled correctly as a group. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 278 | # In the future we should add control over what tasks we check for. |
| 279 | |
| 280 | sstate_archs_list = [] |
| 281 | expected_remaining_sstate = [] |
| 282 | for idx in range(len(target_config)): |
| 283 | self.append_config(global_config[idx]) |
| 284 | self.append_recipeinc(target, target_config[idx]) |
| 285 | sstate_arch = get_bb_var('SSTATE_PKGARCH', target) |
| 286 | if not sstate_arch in sstate_archs_list: |
| 287 | sstate_archs_list.append(sstate_arch) |
| 288 | if target_config[idx] == target_config[-1]: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 289 | target_sstate_before_build = self.search_sstate(target + r'.*?\.tar.zst$') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 290 | bitbake("-cclean %s" % target) |
| 291 | result = bitbake(target, ignore_status=True) |
| 292 | if target_config[idx] == target_config[-1]: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 293 | target_sstate_after_build = self.search_sstate(target + r'.*?\.tar.zst$') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 294 | expected_remaining_sstate += [x for x in target_sstate_after_build if x not in target_sstate_before_build if not any(pattern in x for pattern in ignore_patterns)] |
| 295 | self.remove_config(global_config[idx]) |
| 296 | self.remove_recipeinc(target, target_config[idx]) |
| 297 | self.assertEqual(result.status, 0, msg = "build of %s failed with %s" % (target, result.output)) |
| 298 | |
| 299 | runCmd("sstate-cache-management.sh -y --cache-dir=%s --remove-duplicated --extra-archs=%s" % (self.sstate_path, ','.join(map(str, sstate_archs_list)))) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 300 | actual_remaining_sstate = [x for x in self.search_sstate(target + r'.*?\.tar.zst$') if not any(pattern in x for pattern in ignore_patterns)] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 301 | |
| 302 | actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate] |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 303 | self.assertFalse(actual_not_expected, msg="Files should have been removed but were not: %s" % ', '.join(map(str, actual_not_expected))) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 304 | expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate] |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 305 | self.assertFalse(expected_not_actual, msg="Extra files were removed: %s" ', '.join(map(str, expected_not_actual))) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 306 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 307 | def test_sstate_cache_management_script_using_pr_1(self): |
| 308 | global_config = [] |
| 309 | target_config = [] |
| 310 | global_config.append('') |
| 311 | target_config.append('PR = "0"') |
| 312 | self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic']) |
| 313 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 314 | def test_sstate_cache_management_script_using_pr_2(self): |
| 315 | global_config = [] |
| 316 | target_config = [] |
| 317 | global_config.append('') |
| 318 | target_config.append('PR = "0"') |
| 319 | global_config.append('') |
| 320 | target_config.append('PR = "1"') |
| 321 | self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic']) |
| 322 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 323 | def test_sstate_cache_management_script_using_pr_3(self): |
| 324 | global_config = [] |
| 325 | target_config = [] |
| 326 | global_config.append('MACHINE = "qemux86-64"') |
| 327 | target_config.append('PR = "0"') |
| 328 | global_config.append(global_config[0]) |
| 329 | target_config.append('PR = "1"') |
| 330 | global_config.append('MACHINE = "qemux86"') |
| 331 | target_config.append('PR = "1"') |
| 332 | self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic']) |
| 333 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 334 | def test_sstate_cache_management_script_using_machine(self): |
| 335 | global_config = [] |
| 336 | target_config = [] |
| 337 | global_config.append('MACHINE = "qemux86-64"') |
| 338 | target_config.append('') |
| 339 | global_config.append('MACHINE = "qemux86"') |
| 340 | target_config.append('') |
| 341 | self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic']) |
| 342 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 343 | class SStateHashSameSigs(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 344 | def test_sstate_32_64_same_hash(self): |
| 345 | """ |
| 346 | The sstate checksums for both native and target should not vary whether |
| 347 | they're built on a 32 or 64 bit system. Rather than requiring two different |
| 348 | build machines and running a builds, override the variables calling uname() |
| 349 | manually and check using bitbake -S. |
| 350 | """ |
| 351 | |
| 352 | self.write_config(""" |
| 353 | MACHINE = "qemux86" |
| 354 | TMPDIR = "${TOPDIR}/tmp-sstatesamehash" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 355 | TCLIBCAPPEND = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 356 | BUILD_ARCH = "x86_64" |
| 357 | BUILD_OS = "linux" |
| 358 | SDKMACHINE = "x86_64" |
| 359 | PACKAGE_CLASSES = "package_rpm package_ipk package_deb" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 360 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 361 | """) |
| 362 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 363 | bitbake("core-image-weston -S none") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 364 | self.write_config(""" |
| 365 | MACHINE = "qemux86" |
| 366 | TMPDIR = "${TOPDIR}/tmp-sstatesamehash2" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 367 | TCLIBCAPPEND = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 368 | BUILD_ARCH = "i686" |
| 369 | BUILD_OS = "linux" |
| 370 | SDKMACHINE = "i686" |
| 371 | PACKAGE_CLASSES = "package_rpm package_ipk package_deb" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 372 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 373 | """) |
| 374 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 375 | bitbake("core-image-weston -S none") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 376 | |
| 377 | def get_files(d): |
| 378 | f = [] |
| 379 | for root, dirs, files in os.walk(d): |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 380 | if "core-image-weston" in root: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 381 | # SDKMACHINE changing will change |
| 382 | # do_rootfs/do_testimage/do_build stamps of images which |
| 383 | # is safe to ignore. |
| 384 | continue |
| 385 | f.extend(os.path.join(root, name) for name in files) |
| 386 | return f |
| 387 | files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/") |
| 388 | files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/") |
| 389 | files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash").replace("i686-linux", "x86_64-linux").replace("i686" + self.target_vendor + "-linux", "x86_64" + self.target_vendor + "-linux", ) for x in files2] |
| 390 | self.maxDiff = None |
| 391 | self.assertCountEqual(files1, files2) |
| 392 | |
| 393 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 394 | def test_sstate_nativelsbstring_same_hash(self): |
| 395 | """ |
| 396 | The sstate checksums should be independent of whichever NATIVELSBSTRING is |
| 397 | detected. Rather than requiring two different build machines and running |
| 398 | builds, override the variables manually and check using bitbake -S. |
| 399 | """ |
| 400 | |
| 401 | self.write_config(""" |
| 402 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 403 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 404 | NATIVELSBSTRING = \"DistroA\" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 405 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 406 | """) |
| 407 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 408 | bitbake("core-image-weston -S none") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 409 | self.write_config(""" |
| 410 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 411 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 412 | NATIVELSBSTRING = \"DistroB\" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 413 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 414 | """) |
| 415 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 416 | bitbake("core-image-weston -S none") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 417 | |
| 418 | def get_files(d): |
| 419 | f = [] |
| 420 | for root, dirs, files in os.walk(d): |
| 421 | f.extend(os.path.join(root, name) for name in files) |
| 422 | return f |
| 423 | files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/") |
| 424 | files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/") |
| 425 | files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] |
| 426 | self.maxDiff = None |
| 427 | self.assertCountEqual(files1, files2) |
| 428 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 429 | class SStateHashSameSigs2(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 430 | def test_sstate_allarch_samesigs(self): |
| 431 | """ |
| 432 | The sstate checksums of allarch packages should be independent of whichever |
| 433 | MACHINE is set. Check this using bitbake -S. |
| 434 | Also, rather than duplicate the test, check nativesdk stamps are the same between |
| 435 | the two MACHINE values. |
| 436 | """ |
| 437 | |
| 438 | configA = """ |
| 439 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 440 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 441 | MACHINE = \"qemux86-64\" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 442 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 443 | """ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 444 | #OLDEST_KERNEL is arch specific so set to a different value here for testing |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 445 | configB = """ |
| 446 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 447 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 448 | MACHINE = \"qemuarm\" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 449 | OLDEST_KERNEL = \"3.3.0\" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 450 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 451 | """ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 452 | self.sstate_common_samesigs(configA, configB, allarch=True) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 453 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 454 | def test_sstate_nativesdk_samesigs_multilib(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 455 | """ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 456 | check nativesdk stamps are the same between the two MACHINE values. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 457 | """ |
| 458 | |
| 459 | configA = """ |
| 460 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 461 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 462 | MACHINE = \"qemux86-64\" |
| 463 | require conf/multilib.conf |
| 464 | MULTILIBS = \"multilib:lib32\" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 465 | DEFAULTTUNE:virtclass-multilib-lib32 = \"x86\" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 466 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 467 | """ |
| 468 | configB = """ |
| 469 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 470 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 471 | MACHINE = \"qemuarm\" |
| 472 | require conf/multilib.conf |
| 473 | MULTILIBS = \"\" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 474 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 475 | """ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 476 | self.sstate_common_samesigs(configA, configB) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 477 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 478 | class SStateHashSameSigs3(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 479 | def test_sstate_sametune_samesigs(self): |
| 480 | """ |
| 481 | The sstate checksums of two identical machines (using the same tune) should be the |
| 482 | same, apart from changes within the machine specific stamps directory. We use the |
| 483 | qemux86copy machine to test this. Also include multilibs in the test. |
| 484 | """ |
| 485 | |
| 486 | self.write_config(""" |
| 487 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 488 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 489 | MACHINE = \"qemux86\" |
| 490 | require conf/multilib.conf |
| 491 | MULTILIBS = "multilib:lib32" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 492 | DEFAULTTUNE:virtclass-multilib-lib32 = "x86" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 493 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 494 | """) |
| 495 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
| 496 | bitbake("world meta-toolchain -S none") |
| 497 | self.write_config(""" |
| 498 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 499 | TCLIBCAPPEND = \"\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 500 | MACHINE = \"qemux86copy\" |
| 501 | require conf/multilib.conf |
| 502 | MULTILIBS = "multilib:lib32" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 503 | DEFAULTTUNE:virtclass-multilib-lib32 = "x86" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 504 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 505 | """) |
| 506 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
| 507 | bitbake("world meta-toolchain -S none") |
| 508 | |
| 509 | def get_files(d): |
| 510 | f = [] |
| 511 | for root, dirs, files in os.walk(d): |
| 512 | for name in files: |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 513 | if "meta-environment" in root or "cross-canadian" in root or 'meta-ide-support' in root: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 514 | continue |
| 515 | if "qemux86copy-" in root or "qemux86-" in root: |
| 516 | continue |
| 517 | if "do_build" not in name and "do_populate_sdk" not in name: |
| 518 | f.append(os.path.join(root, name)) |
| 519 | return f |
| 520 | files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps") |
| 521 | files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps") |
| 522 | files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] |
| 523 | self.maxDiff = None |
| 524 | self.assertCountEqual(files1, files2) |
| 525 | |
| 526 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 527 | def test_sstate_multilib_or_not_native_samesigs(self): |
| 528 | """The sstate checksums of two native recipes (and their dependencies) |
| 529 | where the target is using multilib in one but not the other |
| 530 | should be the same. We use the qemux86copy machine to test |
| 531 | this. |
| 532 | """ |
| 533 | |
| 534 | self.write_config(""" |
| 535 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\" |
| 536 | TCLIBCAPPEND = \"\" |
| 537 | MACHINE = \"qemux86\" |
| 538 | require conf/multilib.conf |
| 539 | MULTILIBS = "multilib:lib32" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 540 | DEFAULTTUNE:virtclass-multilib-lib32 = "x86" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 541 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
| 542 | """) |
| 543 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
| 544 | bitbake("binutils-native -S none") |
| 545 | self.write_config(""" |
| 546 | TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\" |
| 547 | TCLIBCAPPEND = \"\" |
| 548 | MACHINE = \"qemux86copy\" |
| 549 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
| 550 | """) |
| 551 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
| 552 | bitbake("binutils-native -S none") |
| 553 | |
| 554 | def get_files(d): |
| 555 | f = [] |
| 556 | for root, dirs, files in os.walk(d): |
| 557 | for name in files: |
| 558 | f.append(os.path.join(root, name)) |
| 559 | return f |
| 560 | files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps") |
| 561 | files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps") |
| 562 | files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] |
| 563 | self.maxDiff = None |
| 564 | self.assertCountEqual(files1, files2) |
| 565 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 566 | class SStateHashSameSigs4(SStateBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 567 | def test_sstate_noop_samesigs(self): |
| 568 | """ |
| 569 | The sstate checksums of two builds with these variables changed or |
| 570 | classes inherits should be the same. |
| 571 | """ |
| 572 | |
| 573 | self.write_config(""" |
| 574 | TMPDIR = "${TOPDIR}/tmp-sstatesamehash" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 575 | TCLIBCAPPEND = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 576 | BB_NUMBER_THREADS = "${@oe.utils.cpu_count()}" |
| 577 | PARALLEL_MAKE = "-j 1" |
| 578 | DL_DIR = "${TOPDIR}/download1" |
| 579 | TIME = "111111" |
| 580 | DATE = "20161111" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 581 | INHERIT:remove = "buildstats-summary buildhistory uninative" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 582 | http_proxy = "" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 583 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 584 | """) |
| 585 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
| 586 | self.track_for_cleanup(self.topdir + "/download1") |
| 587 | bitbake("world meta-toolchain -S none") |
| 588 | self.write_config(""" |
| 589 | TMPDIR = "${TOPDIR}/tmp-sstatesamehash2" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 590 | TCLIBCAPPEND = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 591 | BB_NUMBER_THREADS = "${@oe.utils.cpu_count()+1}" |
| 592 | PARALLEL_MAKE = "-j 2" |
| 593 | DL_DIR = "${TOPDIR}/download2" |
| 594 | TIME = "222222" |
| 595 | DATE = "20161212" |
| 596 | # Always remove uninative as we're changing proxies |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 597 | INHERIT:remove = "uninative" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 598 | INHERIT += "buildstats-summary buildhistory" |
| 599 | http_proxy = "http://example.com/" |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 600 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 601 | """) |
| 602 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
| 603 | self.track_for_cleanup(self.topdir + "/download2") |
| 604 | bitbake("world meta-toolchain -S none") |
| 605 | |
| 606 | def get_files(d): |
| 607 | f = {} |
| 608 | for root, dirs, files in os.walk(d): |
| 609 | for name in files: |
| 610 | name, shash = name.rsplit('.', 1) |
| 611 | # Extract just the machine and recipe name |
| 612 | base = os.sep.join(root.rsplit(os.sep, 2)[-2:] + [name]) |
| 613 | f[base] = shash |
| 614 | return f |
| 615 | |
| 616 | def compare_sigfiles(files, files1, files2, compare=False): |
| 617 | for k in files: |
| 618 | if k in files1 and k in files2: |
| 619 | print("%s differs:" % k) |
| 620 | if compare: |
| 621 | sigdatafile1 = self.topdir + "/tmp-sstatesamehash/stamps/" + k + "." + files1[k] |
| 622 | sigdatafile2 = self.topdir + "/tmp-sstatesamehash2/stamps/" + k + "." + files2[k] |
| 623 | output = bb.siggen.compare_sigfiles(sigdatafile1, sigdatafile2) |
| 624 | if output: |
| 625 | print('\n'.join(output)) |
| 626 | elif k in files1 and k not in files2: |
| 627 | print("%s in files1" % k) |
| 628 | elif k not in files1 and k in files2: |
| 629 | print("%s in files2" % k) |
| 630 | else: |
| 631 | assert "shouldn't reach here" |
| 632 | |
| 633 | files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/") |
| 634 | files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/") |
| 635 | # Remove items that are identical in both sets |
| 636 | for k,v in files1.items() & files2.items(): |
| 637 | del files1[k] |
| 638 | del files2[k] |
| 639 | if not files1 and not files2: |
| 640 | # No changes, so we're done |
| 641 | return |
| 642 | |
| 643 | files = list(files1.keys() | files2.keys()) |
| 644 | # this is an expensive computation, thus just compare the first 'max_sigfiles_to_compare' k files |
| 645 | max_sigfiles_to_compare = 20 |
| 646 | first, rest = files[:max_sigfiles_to_compare], files[max_sigfiles_to_compare:] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 647 | compare_sigfiles(first, files1, files2, compare=True) |
| 648 | compare_sigfiles(rest, files1, files2, compare=False) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 649 | |
| 650 | self.fail("sstate hashes not identical.") |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 651 | |
| 652 | def test_sstate_movelayer_samesigs(self): |
| 653 | """ |
| 654 | The sstate checksums of two builds with the same oe-core layer in two |
| 655 | different locations should be the same. |
| 656 | """ |
| 657 | core_layer = os.path.join( |
| 658 | self.tc.td["COREBASE"], 'meta') |
| 659 | copy_layer_1 = self.topdir + "/meta-copy1/meta" |
| 660 | copy_layer_2 = self.topdir + "/meta-copy2/meta" |
| 661 | |
| 662 | oe.path.copytree(core_layer, copy_layer_1) |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 663 | os.symlink(os.path.dirname(core_layer) + "/scripts", self.topdir + "/meta-copy1/scripts") |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 664 | self.write_config(""" |
| 665 | TMPDIR = "${TOPDIR}/tmp-sstatesamehash" |
| 666 | """) |
| 667 | bblayers_conf = 'BBLAYERS += "%s"\nBBLAYERS:remove = "%s"' % (copy_layer_1, core_layer) |
| 668 | self.write_bblayers_config(bblayers_conf) |
| 669 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") |
| 670 | bitbake("bash -S none") |
| 671 | |
| 672 | oe.path.copytree(core_layer, copy_layer_2) |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 673 | os.symlink(os.path.dirname(core_layer) + "/scripts", self.topdir + "/meta-copy2/scripts") |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 674 | self.write_config(""" |
| 675 | TMPDIR = "${TOPDIR}/tmp-sstatesamehash2" |
| 676 | """) |
| 677 | bblayers_conf = 'BBLAYERS += "%s"\nBBLAYERS:remove = "%s"' % (copy_layer_2, core_layer) |
| 678 | self.write_bblayers_config(bblayers_conf) |
| 679 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") |
| 680 | bitbake("bash -S none") |
| 681 | |
| 682 | def get_files(d): |
| 683 | f = [] |
| 684 | for root, dirs, files in os.walk(d): |
| 685 | for name in files: |
| 686 | f.append(os.path.join(root, name)) |
| 687 | return f |
| 688 | files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps") |
| 689 | files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps") |
| 690 | files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] |
| 691 | self.maxDiff = None |
| 692 | self.assertCountEqual(files1, files2) |
| 693 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame^] | 694 | class SStateFindSiginfo(SStateBase): |
| 695 | def test_sstate_compare_sigfiles_and_find_siginfo(self): |
| 696 | """ |
| 697 | Test the functionality of the find_siginfo: basic function and callback in compare_sigfiles |
| 698 | """ |
| 699 | self.write_config(""" |
| 700 | TMPDIR = \"${TOPDIR}/tmp-sstates-findsiginfo\" |
| 701 | TCLIBCAPPEND = \"\" |
| 702 | MACHINE = \"qemux86-64\" |
| 703 | require conf/multilib.conf |
| 704 | MULTILIBS = "multilib:lib32" |
| 705 | DEFAULTTUNE:virtclass-multilib-lib32 = "x86" |
| 706 | BB_SIGNATURE_HANDLER = "OEBasicHash" |
| 707 | """) |
| 708 | self.track_for_cleanup(self.topdir + "/tmp-sstates-findsiginfo") |
| 709 | |
| 710 | pns = ["binutils", "binutils-native", "lib32-binutils"] |
| 711 | target_configs = [ |
| 712 | """ |
| 713 | TMPVAL1 = "tmpval1" |
| 714 | TMPVAL2 = "tmpval2" |
| 715 | do_tmptask1() { |
| 716 | echo ${TMPVAL1} |
| 717 | } |
| 718 | do_tmptask2() { |
| 719 | echo ${TMPVAL2} |
| 720 | } |
| 721 | addtask do_tmptask1 |
| 722 | addtask tmptask2 before do_tmptask1 |
| 723 | """, |
| 724 | """ |
| 725 | TMPVAL3 = "tmpval3" |
| 726 | TMPVAL4 = "tmpval4" |
| 727 | do_tmptask1() { |
| 728 | echo ${TMPVAL3} |
| 729 | } |
| 730 | do_tmptask2() { |
| 731 | echo ${TMPVAL4} |
| 732 | } |
| 733 | addtask do_tmptask1 |
| 734 | addtask tmptask2 before do_tmptask1 |
| 735 | """ |
| 736 | ] |
| 737 | |
| 738 | for target_config in target_configs: |
| 739 | self.write_recipeinc("binutils", target_config) |
| 740 | for pn in pns: |
| 741 | bitbake("%s -c do_tmptask1 -S none" % pn) |
| 742 | self.delete_recipeinc("binutils") |
| 743 | |
| 744 | with bb.tinfoil.Tinfoil() as tinfoil: |
| 745 | tinfoil.prepare(config_only=True) |
| 746 | |
| 747 | def find_siginfo(pn, taskname, sigs=None): |
| 748 | result = None |
| 749 | tinfoil.set_event_mask(["bb.event.FindSigInfoResult", |
| 750 | "bb.command.CommandCompleted"]) |
| 751 | ret = tinfoil.run_command("findSigInfo", pn, taskname, sigs) |
| 752 | if ret: |
| 753 | while True: |
| 754 | event = tinfoil.wait_event(1) |
| 755 | if event: |
| 756 | if isinstance(event, bb.command.CommandCompleted): |
| 757 | break |
| 758 | elif isinstance(event, bb.event.FindSigInfoResult): |
| 759 | result = event.result |
| 760 | return result |
| 761 | |
| 762 | def recursecb(key, hash1, hash2): |
| 763 | nonlocal recursecb_count |
| 764 | recursecb_count += 1 |
| 765 | hashes = [hash1, hash2] |
| 766 | hashfiles = find_siginfo(key, None, hashes) |
| 767 | self.assertCountEqual(hashes, hashfiles) |
| 768 | bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb) |
| 769 | |
| 770 | for pn in pns: |
| 771 | recursecb_count = 0 |
| 772 | filedates = find_siginfo(pn, "do_tmptask1") |
| 773 | self.assertGreaterEqual(len(filedates), 2) |
| 774 | latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-2:] |
| 775 | bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb) |
| 776 | self.assertEqual(recursecb_count,1) |