blob: f99d74684eb6705bc42cf185cd3e7e5b9d1e8d2f [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import datetime
2import unittest
3import os
4import re
5import shutil
Patrick Williamsd7e96312015-09-22 08:09:05 -05006import glob
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007import subprocess
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008
9import oeqa.utils.ftools as ftools
10from oeqa.selftest.base import oeSelfTest
11from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer
12from oeqa.selftest.sstate import SStateBase
13from oeqa.utils.decorators import testcase
14
15class SStateTests(SStateBase):
16
17 # Test sstate files creation and their location
18 def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
Brad Bishop37a0e4d2017-12-04 01:01:44 -050019 self.config_sstate(temp_sstate_location, [self.sstate_path])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020
21 if self.temp_sstate_location:
22 bitbake(['-cclean'] + targets)
23 else:
24 bitbake(['-ccleansstate'] + targets)
25
26 bitbake(targets)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027 file_tracker = []
28 results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
29 if distro_nonspecific:
30 for r in results:
31 if r.endswith(("_populate_lic.tgz", "_populate_lic.tgz.siginfo", "_fetch.tgz.siginfo", "_unpack.tgz.siginfo", "_patch.tgz.siginfo")):
32 continue
33 file_tracker.append(r)
34 else:
35 file_tracker = results
36
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037 if should_pass:
38 self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
39 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050040 self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041
42 @testcase(975)
43 def test_sstate_creation_distro_specific_pass(self):
44 targetarch = get_bb_var('TUNE_ARCH')
45 self.run_test_sstate_creation(['binutils-cross-'+ targetarch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
46
Patrick Williamsf1e5d692016-03-30 15:21:19 -050047 @testcase(1374)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 def test_sstate_creation_distro_specific_fail(self):
49 targetarch = get_bb_var('TUNE_ARCH')
50 self.run_test_sstate_creation(['binutils-cross-'+ targetarch, 'binutils-native'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True, should_pass=False)
51
52 @testcase(976)
53 def test_sstate_creation_distro_nonspecific_pass(self):
54 self.run_test_sstate_creation(['glibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
55
Patrick Williamsf1e5d692016-03-30 15:21:19 -050056 @testcase(1375)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 def test_sstate_creation_distro_nonspecific_fail(self):
58 self.run_test_sstate_creation(['glibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False)
59
60
61 # Test the sstate files deletion part of the do_cleansstate task
62 def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
Brad Bishop37a0e4d2017-12-04 01:01:44 -050063 self.config_sstate(temp_sstate_location, [self.sstate_path])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064
65 bitbake(['-ccleansstate'] + targets)
66
67 bitbake(targets)
68 tgz_created = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific, distro_nonspecific)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069 self.assertTrue(tgz_created, msg="Could not find sstate .tgz files for: %s (%s)" % (', '.join(map(str, targets)), str(tgz_created)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
71 siginfo_created = self.search_sstate('|'.join(map(str, [s + '.*?\.siginfo$' for s in targets])), distro_specific, distro_nonspecific)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050072 self.assertTrue(siginfo_created, msg="Could not find sstate .siginfo files for: %s (%s)" % (', '.join(map(str, targets)), str(siginfo_created)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
74 bitbake(['-ccleansstate'] + targets)
75 tgz_removed = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific, distro_nonspecific)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076 self.assertTrue(not tgz_removed, msg="do_cleansstate didn't remove .tgz sstate files for: %s (%s)" % (', '.join(map(str, targets)), str(tgz_removed)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077
78 @testcase(977)
79 def test_cleansstate_task_distro_specific_nonspecific(self):
80 targetarch = get_bb_var('TUNE_ARCH')
81 self.run_test_cleansstate_task(['binutils-cross-' + targetarch, 'binutils-native', 'glibc-initial'], distro_specific=True, distro_nonspecific=True, temp_sstate_location=True)
82
Patrick Williamsf1e5d692016-03-30 15:21:19 -050083 @testcase(1376)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 def test_cleansstate_task_distro_nonspecific(self):
85 self.run_test_cleansstate_task(['glibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
86
Patrick Williamsf1e5d692016-03-30 15:21:19 -050087 @testcase(1377)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 def test_cleansstate_task_distro_specific(self):
89 targetarch = get_bb_var('TUNE_ARCH')
90 self.run_test_cleansstate_task(['binutils-cross-'+ targetarch, 'binutils-native', 'glibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
91
92
93 # Test rebuilding of distro-specific sstate files
94 def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True):
Brad Bishop37a0e4d2017-12-04 01:01:44 -050095 self.config_sstate(temp_sstate_location, [self.sstate_path])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096
97 bitbake(['-ccleansstate'] + targets)
98
99 bitbake(targets)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500100 results = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=False, distro_nonspecific=True)
101 filtered_results = []
102 for r in results:
103 if r.endswith(("_populate_lic.tgz", "_populate_lic.tgz.siginfo")):
104 continue
105 filtered_results.append(r)
106 self.assertTrue(filtered_results == [], msg="Found distro non-specific sstate for: %s (%s)" % (', '.join(map(str, targets)), str(filtered_results)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 file_tracker_1 = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=True, distro_nonspecific=False)
108 self.assertTrue(len(file_tracker_1) >= len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
109
110 self.track_for_cleanup(self.distro_specific_sstate + "_old")
111 shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old")
112 shutil.rmtree(self.distro_specific_sstate)
113
114 bitbake(['-cclean'] + targets)
115 bitbake(targets)
116 file_tracker_2 = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=True, distro_nonspecific=False)
117 self.assertTrue(len(file_tracker_2) >= len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
118
119 not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2]
120 self.assertTrue(not_recreated == [], msg="The following sstate files ware not recreated: %s" % ', '.join(map(str, not_recreated)))
121
122 created_once = [x for x in file_tracker_2 if x not in file_tracker_1]
123 self.assertTrue(created_once == [], msg="The following sstate files ware created only in the second run: %s" % ', '.join(map(str, created_once)))
124
125 @testcase(175)
126 def test_rebuild_distro_specific_sstate_cross_native_targets(self):
127 targetarch = get_bb_var('TUNE_ARCH')
128 self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + targetarch, 'binutils-native'], temp_sstate_location=True)
129
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500130 @testcase(1372)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 def test_rebuild_distro_specific_sstate_cross_target(self):
132 targetarch = get_bb_var('TUNE_ARCH')
133 self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + targetarch], temp_sstate_location=True)
134
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500135 @testcase(1373)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 def test_rebuild_distro_specific_sstate_native_target(self):
137 self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True)
138
139
140 # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list
141 # 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)
142 def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=[''], ignore_patterns=[]):
143 self.assertTrue(global_config)
144 self.assertTrue(target_config)
145 self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements')
146 self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path])
147
148 # If buildhistory is enabled, we need to disable version-going-backwards QA checks for this test. It may report errors otherwise.
149 if ('buildhistory' in get_bb_var('USER_CLASSES')) or ('buildhistory' in get_bb_var('INHERIT')):
150 remove_errors_config = 'ERROR_QA_remove = "version-going-backwards"'
151 self.append_config(remove_errors_config)
152
153 # For not this only checks if random sstate tasks are handled correctly as a group.
154 # In the future we should add control over what tasks we check for.
155
156 sstate_archs_list = []
157 expected_remaining_sstate = []
158 for idx in range(len(target_config)):
159 self.append_config(global_config[idx])
160 self.append_recipeinc(target, target_config[idx])
161 sstate_arch = get_bb_var('SSTATE_PKGARCH', target)
162 if not sstate_arch in sstate_archs_list:
163 sstate_archs_list.append(sstate_arch)
164 if target_config[idx] == target_config[-1]:
165 target_sstate_before_build = self.search_sstate(target + '.*?\.tgz$')
166 bitbake("-cclean %s" % target)
167 result = bitbake(target, ignore_status=True)
168 if target_config[idx] == target_config[-1]:
169 target_sstate_after_build = self.search_sstate(target + '.*?\.tgz$')
170 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)]
171 self.remove_config(global_config[idx])
172 self.remove_recipeinc(target, target_config[idx])
173 self.assertEqual(result.status, 0, msg = "build of %s failed with %s" % (target, result.output))
174
175 runCmd("sstate-cache-management.sh -y --cache-dir=%s --remove-duplicated --extra-archs=%s" % (self.sstate_path, ','.join(map(str, sstate_archs_list))))
176 actual_remaining_sstate = [x for x in self.search_sstate(target + '.*?\.tgz$') if not any(pattern in x for pattern in ignore_patterns)]
177
178 actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate]
179 self.assertFalse(actual_not_expected, msg="Files should have been removed but ware not: %s" % ', '.join(map(str, actual_not_expected)))
180 expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate]
181 self.assertFalse(expected_not_actual, msg="Extra files ware removed: %s" ', '.join(map(str, expected_not_actual)))
182
183 @testcase(973)
184 def test_sstate_cache_management_script_using_pr_1(self):
185 global_config = []
186 target_config = []
187 global_config.append('')
188 target_config.append('PR = "0"')
189 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
190
191 @testcase(978)
192 def test_sstate_cache_management_script_using_pr_2(self):
193 global_config = []
194 target_config = []
195 global_config.append('')
196 target_config.append('PR = "0"')
197 global_config.append('')
198 target_config.append('PR = "1"')
199 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
200
201 @testcase(979)
202 def test_sstate_cache_management_script_using_pr_3(self):
203 global_config = []
204 target_config = []
205 global_config.append('MACHINE = "qemux86-64"')
206 target_config.append('PR = "0"')
207 global_config.append(global_config[0])
208 target_config.append('PR = "1"')
209 global_config.append('MACHINE = "qemux86"')
210 target_config.append('PR = "1"')
211 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
212
213 @testcase(974)
214 def test_sstate_cache_management_script_using_machine(self):
215 global_config = []
216 target_config = []
217 global_config.append('MACHINE = "qemux86-64"')
218 target_config.append('')
219 global_config.append('MACHINE = "qemux86"')
220 target_config.append('')
221 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
222
223 @testcase(1270)
224 def test_sstate_32_64_same_hash(self):
225 """
226 The sstate checksums for both native and target should not vary whether
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500227 they're built on a 32 or 64 bit system. Rather than requiring two different
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 build machines and running a builds, override the variables calling uname()
229 manually and check using bitbake -S.
230 """
231
232 topdir = get_bb_var('TOPDIR')
233 targetvendor = get_bb_var('TARGET_VENDOR')
234 self.write_config("""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500235MACHINE = "qemux86"
236TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
237BUILD_ARCH = "x86_64"
238BUILD_OS = "linux"
239SDKMACHINE = "x86_64"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600240PACKAGE_CLASSES = "package_rpm package_ipk package_deb"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241""")
242 self.track_for_cleanup(topdir + "/tmp-sstatesamehash")
243 bitbake("core-image-sato -S none")
244 self.write_config("""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500245MACHINE = "qemux86"
246TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
247BUILD_ARCH = "i686"
248BUILD_OS = "linux"
249SDKMACHINE = "i686"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600250PACKAGE_CLASSES = "package_rpm package_ipk package_deb"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251""")
252 self.track_for_cleanup(topdir + "/tmp-sstatesamehash2")
253 bitbake("core-image-sato -S none")
254
255 def get_files(d):
256 f = []
257 for root, dirs, files in os.walk(d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500258 if "core-image-sato" in root:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500259 # SDKMACHINE changing will change
260 # do_rootfs/do_testimage/do_build stamps of images which
261 # is safe to ignore.
262 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263 f.extend(os.path.join(root, name) for name in files)
264 return f
265 files1 = get_files(topdir + "/tmp-sstatesamehash/stamps/")
266 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/")
267 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash").replace("i686-linux", "x86_64-linux").replace("i686" + targetvendor + "-linux", "x86_64" + targetvendor + "-linux", ) for x in files2]
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500268 self.maxDiff = None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600269 self.assertCountEqual(files1, files2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270
271
272 @testcase(1271)
273 def test_sstate_nativelsbstring_same_hash(self):
274 """
275 The sstate checksums should be independent of whichever NATIVELSBSTRING is
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500276 detected. Rather than requiring two different build machines and running
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277 builds, override the variables manually and check using bitbake -S.
278 """
279
280 topdir = get_bb_var('TOPDIR')
281 self.write_config("""
282TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
283NATIVELSBSTRING = \"DistroA\"
284""")
285 self.track_for_cleanup(topdir + "/tmp-sstatesamehash")
286 bitbake("core-image-sato -S none")
287 self.write_config("""
288TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
289NATIVELSBSTRING = \"DistroB\"
290""")
291 self.track_for_cleanup(topdir + "/tmp-sstatesamehash2")
292 bitbake("core-image-sato -S none")
293
294 def get_files(d):
295 f = []
296 for root, dirs, files in os.walk(d):
297 f.extend(os.path.join(root, name) for name in files)
298 return f
299 files1 = get_files(topdir + "/tmp-sstatesamehash/stamps/")
300 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/")
301 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500302 self.maxDiff = None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600303 self.assertCountEqual(files1, files2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500305 @testcase(1368)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306 def test_sstate_allarch_samesigs(self):
307 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500308 The sstate checksums of allarch packages should be independent of whichever
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 MACHINE is set. Check this using bitbake -S.
Patrick Williamsd7e96312015-09-22 08:09:05 -0500310 Also, rather than duplicate the test, check nativesdk stamps are the same between
311 the two MACHINE values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312 """
313
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600314 configA = """
315TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
316MACHINE = \"qemux86-64\"
317"""
318 configB = """
319TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
320MACHINE = \"qemuarm\"
321"""
322 self.sstate_allarch_samesigs(configA, configB)
323
324 def test_sstate_allarch_samesigs_multilib(self):
325 """
326 The sstate checksums of allarch multilib packages should be independent of whichever
327 MACHINE is set. Check this using bitbake -S.
328 Also, rather than duplicate the test, check nativesdk stamps are the same between
329 the two MACHINE values.
330 """
331
332 configA = """
333TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
334MACHINE = \"qemux86-64\"
335require conf/multilib.conf
336MULTILIBS = \"multilib:lib32\"
337DEFAULTTUNE_virtclass-multilib-lib32 = \"x86\"
338"""
339 configB = """
340TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
341MACHINE = \"qemuarm\"
342require conf/multilib.conf
343MULTILIBS = \"\"
344"""
345 self.sstate_allarch_samesigs(configA, configB)
346
347 def sstate_allarch_samesigs(self, configA, configB):
348
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500349 topdir = get_bb_var('TOPDIR')
350 targetos = get_bb_var('TARGET_OS')
351 targetvendor = get_bb_var('TARGET_VENDOR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600352 self.write_config(configA)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353 self.track_for_cleanup(topdir + "/tmp-sstatesamehash")
Patrick Williamsd7e96312015-09-22 08:09:05 -0500354 bitbake("world meta-toolchain -S none")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600355 self.write_config(configB)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356 self.track_for_cleanup(topdir + "/tmp-sstatesamehash2")
Patrick Williamsd7e96312015-09-22 08:09:05 -0500357 bitbake("world meta-toolchain -S none")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500358
359 def get_files(d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500360 f = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361 for root, dirs, files in os.walk(d):
362 for name in files:
Patrick Williamsd7e96312015-09-22 08:09:05 -0500363 if "meta-environment" in root or "cross-canadian" in root:
364 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500365 if "do_build" not in name:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500366 # 1.4.1+gitAUTOINC+302fca9f4c-r0.do_package_write_ipk.sigdata.f3a2a38697da743f0dbed8b56aafcf79
367 (_, task, _, shash) = name.rsplit(".", 3)
368 f[os.path.join(os.path.basename(root), task)] = shash
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369 return f
370 files1 = get_files(topdir + "/tmp-sstatesamehash/stamps/all" + targetvendor + "-" + targetos)
371 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/all" + targetvendor + "-" + targetos)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500372 self.maxDiff = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500373 self.assertEqual(files1, files2)
Patrick Williamsd7e96312015-09-22 08:09:05 -0500374
375 nativesdkdir = os.path.basename(glob.glob(topdir + "/tmp-sstatesamehash/stamps/*-nativesdk*-linux")[0])
376
377 files1 = get_files(topdir + "/tmp-sstatesamehash/stamps/" + nativesdkdir)
378 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/" + nativesdkdir)
Patrick Williamsd7e96312015-09-22 08:09:05 -0500379 self.maxDiff = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500380 self.assertEqual(files1, files2)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500381
382 @testcase(1369)
383 def test_sstate_sametune_samesigs(self):
384 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500385 The sstate checksums of two identical machines (using the same tune) should be the
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500386 same, apart from changes within the machine specific stamps directory. We use the
387 qemux86copy machine to test this. Also include multilibs in the test.
388 """
389
390 topdir = get_bb_var('TOPDIR')
391 targetos = get_bb_var('TARGET_OS')
392 targetvendor = get_bb_var('TARGET_VENDOR')
393 self.write_config("""
394TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
395MACHINE = \"qemux86\"
396require conf/multilib.conf
397MULTILIBS = "multilib:lib32"
398DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
399""")
400 self.track_for_cleanup(topdir + "/tmp-sstatesamehash")
401 bitbake("world meta-toolchain -S none")
402 self.write_config("""
403TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
404MACHINE = \"qemux86copy\"
405require conf/multilib.conf
406MULTILIBS = "multilib:lib32"
407DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
408""")
409 self.track_for_cleanup(topdir + "/tmp-sstatesamehash2")
410 bitbake("world meta-toolchain -S none")
411
412 def get_files(d):
413 f = []
414 for root, dirs, files in os.walk(d):
415 for name in files:
416 if "meta-environment" in root or "cross-canadian" in root:
417 continue
418 if "qemux86copy-" in root or "qemux86-" in root:
419 continue
420 if "do_build" not in name and "do_populate_sdk" not in name:
421 f.append(os.path.join(root, name))
422 return f
423 files1 = get_files(topdir + "/tmp-sstatesamehash/stamps")
424 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps")
425 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
426 self.maxDiff = None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600427 self.assertCountEqual(files1, files2)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500428
429
430 def test_sstate_noop_samesigs(self):
431 """
432 The sstate checksums of two builds with these variables changed or
433 classes inherits should be the same.
434 """
435
436 topdir = get_bb_var('TOPDIR')
437 targetvendor = get_bb_var('TARGET_VENDOR')
438 self.write_config("""
439TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
440BB_NUMBER_THREADS = "1"
441PARALLEL_MAKE = "-j 1"
442DL_DIR = "${TOPDIR}/download1"
443TIME = "111111"
444DATE = "20161111"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600445INHERIT_remove = "buildstats-summary buildhistory uninative"
446http_proxy = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500447""")
448 self.track_for_cleanup(topdir + "/tmp-sstatesamehash")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600449 self.track_for_cleanup(topdir + "/download1")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500450 bitbake("world meta-toolchain -S none")
451 self.write_config("""
452TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
453BB_NUMBER_THREADS = "2"
454PARALLEL_MAKE = "-j 2"
455DL_DIR = "${TOPDIR}/download2"
456TIME = "222222"
457DATE = "20161212"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600458# Always remove uninative as we're changing proxies
459INHERIT_remove = "uninative"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500460INHERIT += "buildstats-summary buildhistory"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600461http_proxy = "http://example.com/"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500462""")
463 self.track_for_cleanup(topdir + "/tmp-sstatesamehash2")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600464 self.track_for_cleanup(topdir + "/download2")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500465 bitbake("world meta-toolchain -S none")
466
467 def get_files(d):
468 f = {}
469 for root, dirs, files in os.walk(d):
470 for name in files:
471 name, shash = name.rsplit('.', 1)
472 # Extract just the machine and recipe name
473 base = os.sep.join(root.rsplit(os.sep, 2)[-2:] + [name])
474 f[base] = shash
475 return f
476 files1 = get_files(topdir + "/tmp-sstatesamehash/stamps/")
477 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/")
478 # Remove items that are identical in both sets
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600479 for k,v in files1.items() & files2.items():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500480 del files1[k]
481 del files2[k]
482 if not files1 and not files2:
483 # No changes, so we're done
484 return
485
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600486 for k in files1.keys() | files2.keys():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500487 if k in files1 and k in files2:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600488 print("%s differs:" % k)
489 print(subprocess.check_output(("bitbake-diffsigs",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500490 topdir + "/tmp-sstatesamehash/stamps/" + k + "." + files1[k],
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600491 topdir + "/tmp-sstatesamehash2/stamps/" + k + "." + files2[k])))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500492 elif k in files1 and k not in files2:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600493 print("%s in files1" % k)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500494 elif k not in files1 and k in files2:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600495 print("%s in files2" % k)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500496 else:
497 assert "shouldn't reach here"
498 self.fail("sstate hashes not identical.")