blob: 47900886a32232cc27e19c6bf128f594e185c1bd [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001import os
2import shutil
3import glob
4import subprocess
5
6from oeqa.selftest.case import OESelftestTestCase
7from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer
8from oeqa.selftest.cases.sstate import SStateBase
9from oeqa.core.decorator.oeid import OETestID
10
11import bb.siggen
12
13class SStateTests(SStateBase):
14
15 # Test sstate files creation and their location
16 def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
17 self.config_sstate(temp_sstate_location, [self.sstate_path])
18
19 if self.temp_sstate_location:
20 bitbake(['-cclean'] + targets)
21 else:
22 bitbake(['-ccleansstate'] + targets)
23
24 bitbake(targets)
25 file_tracker = []
26 results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
27 if distro_nonspecific:
28 for r in results:
29 if r.endswith(("_populate_lic.tgz", "_populate_lic.tgz.siginfo", "_fetch.tgz.siginfo", "_unpack.tgz.siginfo", "_patch.tgz.siginfo")):
30 continue
31 file_tracker.append(r)
32 else:
33 file_tracker = results
34
35 if should_pass:
36 self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
37 else:
38 self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker)))
39
40 @OETestID(975)
41 def test_sstate_creation_distro_specific_pass(self):
42 self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
43
44 @OETestID(1374)
45 def test_sstate_creation_distro_specific_fail(self):
46 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)
47
48 @OETestID(976)
49 def test_sstate_creation_distro_nonspecific_pass(self):
50 self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
51
52 @OETestID(1375)
53 def test_sstate_creation_distro_nonspecific_fail(self):
54 self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False)
55
56 # Test the sstate files deletion part of the do_cleansstate task
57 def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
58 self.config_sstate(temp_sstate_location, [self.sstate_path])
59
60 bitbake(['-ccleansstate'] + targets)
61
62 bitbake(targets)
63 tgz_created = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific, distro_nonspecific)
64 self.assertTrue(tgz_created, msg="Could not find sstate .tgz files for: %s (%s)" % (', '.join(map(str, targets)), str(tgz_created)))
65
66 siginfo_created = self.search_sstate('|'.join(map(str, [s + '.*?\.siginfo$' for s in targets])), distro_specific, distro_nonspecific)
67 self.assertTrue(siginfo_created, msg="Could not find sstate .siginfo files for: %s (%s)" % (', '.join(map(str, targets)), str(siginfo_created)))
68
69 bitbake(['-ccleansstate'] + targets)
70 tgz_removed = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific, distro_nonspecific)
71 self.assertTrue(not tgz_removed, msg="do_cleansstate didn't remove .tgz sstate files for: %s (%s)" % (', '.join(map(str, targets)), str(tgz_removed)))
72
73 @OETestID(977)
74 def test_cleansstate_task_distro_specific_nonspecific(self):
75 targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native']
76 targets.append('linux-libc-headers')
77 self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True)
78
79 @OETestID(1376)
80 def test_cleansstate_task_distro_nonspecific(self):
81 self.run_test_cleansstate_task(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
82
83 @OETestID(1377)
84 def test_cleansstate_task_distro_specific(self):
85 targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native']
86 targets.append('linux-libc-headers')
87 self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
88
89
90 # Test rebuilding of distro-specific sstate files
91 def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True):
92 self.config_sstate(temp_sstate_location, [self.sstate_path])
93
94 bitbake(['-ccleansstate'] + targets)
95
96 bitbake(targets)
97 results = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=False, distro_nonspecific=True)
98 filtered_results = []
99 for r in results:
100 if r.endswith(("_populate_lic.tgz", "_populate_lic.tgz.siginfo")):
101 continue
102 filtered_results.append(r)
103 self.assertTrue(filtered_results == [], msg="Found distro non-specific sstate for: %s (%s)" % (', '.join(map(str, targets)), str(filtered_results)))
104 file_tracker_1 = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=True, distro_nonspecific=False)
105 self.assertTrue(len(file_tracker_1) >= len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
106
107 self.track_for_cleanup(self.distro_specific_sstate + "_old")
108 shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old")
109 shutil.rmtree(self.distro_specific_sstate)
110
111 bitbake(['-cclean'] + targets)
112 bitbake(targets)
113 file_tracker_2 = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=True, distro_nonspecific=False)
114 self.assertTrue(len(file_tracker_2) >= len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
115
116 not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2]
117 self.assertTrue(not_recreated == [], msg="The following sstate files ware not recreated: %s" % ', '.join(map(str, not_recreated)))
118
119 created_once = [x for x in file_tracker_2 if x not in file_tracker_1]
120 self.assertTrue(created_once == [], msg="The following sstate files ware created only in the second run: %s" % ', '.join(map(str, created_once)))
121
122 @OETestID(175)
123 def test_rebuild_distro_specific_sstate_cross_native_targets(self):
124 self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch, 'binutils-native'], temp_sstate_location=True)
125
126 @OETestID(1372)
127 def test_rebuild_distro_specific_sstate_cross_target(self):
128 self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch], temp_sstate_location=True)
129
130 @OETestID(1373)
131 def test_rebuild_distro_specific_sstate_native_target(self):
132 self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True)
133
134
135 # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list
136 # 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)
137 def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=[''], ignore_patterns=[]):
138 self.assertTrue(global_config)
139 self.assertTrue(target_config)
140 self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements')
141 self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path])
142
143 # If buildhistory is enabled, we need to disable version-going-backwards
144 # QA checks for this test. It may report errors otherwise.
145 self.append_config('ERROR_QA_remove = "version-going-backwards"')
146
147 # For not this only checks if random sstate tasks are handled correctly as a group.
148 # In the future we should add control over what tasks we check for.
149
150 sstate_archs_list = []
151 expected_remaining_sstate = []
152 for idx in range(len(target_config)):
153 self.append_config(global_config[idx])
154 self.append_recipeinc(target, target_config[idx])
155 sstate_arch = get_bb_var('SSTATE_PKGARCH', target)
156 if not sstate_arch in sstate_archs_list:
157 sstate_archs_list.append(sstate_arch)
158 if target_config[idx] == target_config[-1]:
159 target_sstate_before_build = self.search_sstate(target + '.*?\.tgz$')
160 bitbake("-cclean %s" % target)
161 result = bitbake(target, ignore_status=True)
162 if target_config[idx] == target_config[-1]:
163 target_sstate_after_build = self.search_sstate(target + '.*?\.tgz$')
164 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)]
165 self.remove_config(global_config[idx])
166 self.remove_recipeinc(target, target_config[idx])
167 self.assertEqual(result.status, 0, msg = "build of %s failed with %s" % (target, result.output))
168
169 runCmd("sstate-cache-management.sh -y --cache-dir=%s --remove-duplicated --extra-archs=%s" % (self.sstate_path, ','.join(map(str, sstate_archs_list))))
170 actual_remaining_sstate = [x for x in self.search_sstate(target + '.*?\.tgz$') if not any(pattern in x for pattern in ignore_patterns)]
171
172 actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate]
173 self.assertFalse(actual_not_expected, msg="Files should have been removed but ware not: %s" % ', '.join(map(str, actual_not_expected)))
174 expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate]
175 self.assertFalse(expected_not_actual, msg="Extra files ware removed: %s" ', '.join(map(str, expected_not_actual)))
176
177 @OETestID(973)
178 def test_sstate_cache_management_script_using_pr_1(self):
179 global_config = []
180 target_config = []
181 global_config.append('')
182 target_config.append('PR = "0"')
183 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
184
185 @OETestID(978)
186 def test_sstate_cache_management_script_using_pr_2(self):
187 global_config = []
188 target_config = []
189 global_config.append('')
190 target_config.append('PR = "0"')
191 global_config.append('')
192 target_config.append('PR = "1"')
193 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
194
195 @OETestID(979)
196 def test_sstate_cache_management_script_using_pr_3(self):
197 global_config = []
198 target_config = []
199 global_config.append('MACHINE = "qemux86-64"')
200 target_config.append('PR = "0"')
201 global_config.append(global_config[0])
202 target_config.append('PR = "1"')
203 global_config.append('MACHINE = "qemux86"')
204 target_config.append('PR = "1"')
205 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
206
207 @OETestID(974)
208 def test_sstate_cache_management_script_using_machine(self):
209 global_config = []
210 target_config = []
211 global_config.append('MACHINE = "qemux86-64"')
212 target_config.append('')
213 global_config.append('MACHINE = "qemux86"')
214 target_config.append('')
215 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
216
217 @OETestID(1270)
218 def test_sstate_32_64_same_hash(self):
219 """
220 The sstate checksums for both native and target should not vary whether
221 they're built on a 32 or 64 bit system. Rather than requiring two different
222 build machines and running a builds, override the variables calling uname()
223 manually and check using bitbake -S.
224 """
225
226 self.write_config("""
227MACHINE = "qemux86"
228TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
229BUILD_ARCH = "x86_64"
230BUILD_OS = "linux"
231SDKMACHINE = "x86_64"
232PACKAGE_CLASSES = "package_rpm package_ipk package_deb"
233""")
234 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
235 bitbake("core-image-sato -S none")
236 self.write_config("""
237MACHINE = "qemux86"
238TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
239BUILD_ARCH = "i686"
240BUILD_OS = "linux"
241SDKMACHINE = "i686"
242PACKAGE_CLASSES = "package_rpm package_ipk package_deb"
243""")
244 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
245 bitbake("core-image-sato -S none")
246
247 def get_files(d):
248 f = []
249 for root, dirs, files in os.walk(d):
250 if "core-image-sato" in root:
251 # SDKMACHINE changing will change
252 # do_rootfs/do_testimage/do_build stamps of images which
253 # is safe to ignore.
254 continue
255 f.extend(os.path.join(root, name) for name in files)
256 return f
257 files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/")
258 files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/")
259 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]
260 self.maxDiff = None
261 self.assertCountEqual(files1, files2)
262
263
264 @OETestID(1271)
265 def test_sstate_nativelsbstring_same_hash(self):
266 """
267 The sstate checksums should be independent of whichever NATIVELSBSTRING is
268 detected. Rather than requiring two different build machines and running
269 builds, override the variables manually and check using bitbake -S.
270 """
271
272 self.write_config("""
273TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
274NATIVELSBSTRING = \"DistroA\"
275""")
276 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
277 bitbake("core-image-sato -S none")
278 self.write_config("""
279TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
280NATIVELSBSTRING = \"DistroB\"
281""")
282 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
283 bitbake("core-image-sato -S none")
284
285 def get_files(d):
286 f = []
287 for root, dirs, files in os.walk(d):
288 f.extend(os.path.join(root, name) for name in files)
289 return f
290 files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/")
291 files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/")
292 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
293 self.maxDiff = None
294 self.assertCountEqual(files1, files2)
295
296 @OETestID(1368)
297 def test_sstate_allarch_samesigs(self):
298 """
299 The sstate checksums of allarch packages should be independent of whichever
300 MACHINE is set. Check this using bitbake -S.
301 Also, rather than duplicate the test, check nativesdk stamps are the same between
302 the two MACHINE values.
303 """
304
305 configA = """
306TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
307MACHINE = \"qemux86-64\"
308"""
309 configB = """
310TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
311MACHINE = \"qemuarm\"
312"""
313 self.sstate_allarch_samesigs(configA, configB)
314
315 @OETestID(1645)
316 def test_sstate_allarch_samesigs_multilib(self):
317 """
318 The sstate checksums of allarch multilib packages should be independent of whichever
319 MACHINE is set. Check this using bitbake -S.
320 Also, rather than duplicate the test, check nativesdk stamps are the same between
321 the two MACHINE values.
322 """
323
324 configA = """
325TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
326MACHINE = \"qemux86-64\"
327require conf/multilib.conf
328MULTILIBS = \"multilib:lib32\"
329DEFAULTTUNE_virtclass-multilib-lib32 = \"x86\"
330"""
331 configB = """
332TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
333MACHINE = \"qemuarm\"
334require conf/multilib.conf
335MULTILIBS = \"\"
336"""
337 self.sstate_allarch_samesigs(configA, configB)
338
339 def sstate_allarch_samesigs(self, configA, configB):
340
341 self.write_config(configA)
342 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
343 bitbake("world meta-toolchain -S none")
344 self.write_config(configB)
345 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
346 bitbake("world meta-toolchain -S none")
347
348 def get_files(d):
349 f = {}
350 for root, dirs, files in os.walk(d):
351 for name in files:
352 if "meta-environment" in root or "cross-canadian" in root:
353 continue
354 if "do_build" not in name:
355 # 1.4.1+gitAUTOINC+302fca9f4c-r0.do_package_write_ipk.sigdata.f3a2a38697da743f0dbed8b56aafcf79
356 (_, task, _, shash) = name.rsplit(".", 3)
357 f[os.path.join(os.path.basename(root), task)] = shash
358 return f
359 files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/all" + self.target_vendor + "-" + self.target_os)
360 files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/all" + self.target_vendor + "-" + self.target_os)
361 self.maxDiff = None
362 self.assertEqual(files1, files2)
363
364 nativesdkdir = os.path.basename(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/*-nativesdk*-linux")[0])
365
366 files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/" + nativesdkdir)
367 files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/" + nativesdkdir)
368 self.maxDiff = None
369 self.assertEqual(files1, files2)
370
371 @OETestID(1369)
372 def test_sstate_sametune_samesigs(self):
373 """
374 The sstate checksums of two identical machines (using the same tune) should be the
375 same, apart from changes within the machine specific stamps directory. We use the
376 qemux86copy machine to test this. Also include multilibs in the test.
377 """
378
379 self.write_config("""
380TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
381MACHINE = \"qemux86\"
382require conf/multilib.conf
383MULTILIBS = "multilib:lib32"
384DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
385""")
386 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
387 bitbake("world meta-toolchain -S none")
388 self.write_config("""
389TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
390MACHINE = \"qemux86copy\"
391require conf/multilib.conf
392MULTILIBS = "multilib:lib32"
393DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
394""")
395 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
396 bitbake("world meta-toolchain -S none")
397
398 def get_files(d):
399 f = []
400 for root, dirs, files in os.walk(d):
401 for name in files:
402 if "meta-environment" in root or "cross-canadian" in root:
403 continue
404 if "qemux86copy-" in root or "qemux86-" in root:
405 continue
406 if "do_build" not in name and "do_populate_sdk" not in name:
407 f.append(os.path.join(root, name))
408 return f
409 files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps")
410 files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps")
411 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
412 self.maxDiff = None
413 self.assertCountEqual(files1, files2)
414
415
416 @OETestID(1498)
417 def test_sstate_noop_samesigs(self):
418 """
419 The sstate checksums of two builds with these variables changed or
420 classes inherits should be the same.
421 """
422
423 self.write_config("""
424TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
425BB_NUMBER_THREADS = "${@oe.utils.cpu_count()}"
426PARALLEL_MAKE = "-j 1"
427DL_DIR = "${TOPDIR}/download1"
428TIME = "111111"
429DATE = "20161111"
430INHERIT_remove = "buildstats-summary buildhistory uninative"
431http_proxy = ""
432""")
433 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
434 self.track_for_cleanup(self.topdir + "/download1")
435 bitbake("world meta-toolchain -S none")
436 self.write_config("""
437TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
438BB_NUMBER_THREADS = "${@oe.utils.cpu_count()+1}"
439PARALLEL_MAKE = "-j 2"
440DL_DIR = "${TOPDIR}/download2"
441TIME = "222222"
442DATE = "20161212"
443# Always remove uninative as we're changing proxies
444INHERIT_remove = "uninative"
445INHERIT += "buildstats-summary buildhistory"
446http_proxy = "http://example.com/"
447""")
448 self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
449 self.track_for_cleanup(self.topdir + "/download2")
450 bitbake("world meta-toolchain -S none")
451
452 def get_files(d):
453 f = {}
454 for root, dirs, files in os.walk(d):
455 for name in files:
456 name, shash = name.rsplit('.', 1)
457 # Extract just the machine and recipe name
458 base = os.sep.join(root.rsplit(os.sep, 2)[-2:] + [name])
459 f[base] = shash
460 return f
461
462 def compare_sigfiles(files, files1, files2, compare=False):
463 for k in files:
464 if k in files1 and k in files2:
465 print("%s differs:" % k)
466 if compare:
467 sigdatafile1 = self.topdir + "/tmp-sstatesamehash/stamps/" + k + "." + files1[k]
468 sigdatafile2 = self.topdir + "/tmp-sstatesamehash2/stamps/" + k + "." + files2[k]
469 output = bb.siggen.compare_sigfiles(sigdatafile1, sigdatafile2)
470 if output:
471 print('\n'.join(output))
472 elif k in files1 and k not in files2:
473 print("%s in files1" % k)
474 elif k not in files1 and k in files2:
475 print("%s in files2" % k)
476 else:
477 assert "shouldn't reach here"
478
479 files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/")
480 files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/")
481 # Remove items that are identical in both sets
482 for k,v in files1.items() & files2.items():
483 del files1[k]
484 del files2[k]
485 if not files1 and not files2:
486 # No changes, so we're done
487 return
488
489 files = list(files1.keys() | files2.keys())
490 # this is an expensive computation, thus just compare the first 'max_sigfiles_to_compare' k files
491 max_sigfiles_to_compare = 20
492 first, rest = files[:max_sigfiles_to_compare], files[max_sigfiles_to_compare:]
493 compare_sigfiles(first, files1.keys(), files2.keys(), compare=True)
494 compare_sigfiles(rest, files1.keys(), files2.keys(), compare=False)
495
496 self.fail("sstate hashes not identical.")