sstatetests.py 24 KB

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