sstatetests.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import os
  7. import shutil
  8. import glob
  9. import subprocess
  10. import tempfile
  11. import datetime
  12. import re
  13. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer, get_bb_vars
  14. from oeqa.selftest.case import OESelftestTestCase
  15. from oeqa.core.decorator import OETestTag
  16. import oe
  17. import bb.siggen
  18. # Set to True to preserve stamp files after test execution for debugging failures
  19. keep_temp_files = False
  20. class SStateBase(OESelftestTestCase):
  21. def setUpLocal(self):
  22. super(SStateBase, self).setUpLocal()
  23. self.temp_sstate_location = None
  24. needed_vars = ['SSTATE_DIR', 'NATIVELSBSTRING', 'TCLIBC', 'TUNE_ARCH',
  25. 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS']
  26. bb_vars = get_bb_vars(needed_vars)
  27. self.sstate_path = bb_vars['SSTATE_DIR']
  28. self.hostdistro = bb_vars['NATIVELSBSTRING']
  29. self.tclibc = bb_vars['TCLIBC']
  30. self.tune_arch = bb_vars['TUNE_ARCH']
  31. self.topdir = bb_vars['TOPDIR']
  32. self.target_vendor = bb_vars['TARGET_VENDOR']
  33. self.target_os = bb_vars['TARGET_OS']
  34. self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro)
  35. def track_for_cleanup(self, path):
  36. if not keep_temp_files:
  37. super().track_for_cleanup(path)
  38. # Creates a special sstate configuration with the option to add sstate mirrors
  39. def config_sstate(self, temp_sstate_location=False, add_local_mirrors=[]):
  40. self.temp_sstate_location = temp_sstate_location
  41. if self.temp_sstate_location:
  42. temp_sstate_path = os.path.join(self.builddir, "temp_sstate_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
  43. config_temp_sstate = "SSTATE_DIR = \"%s\"" % temp_sstate_path
  44. self.append_config(config_temp_sstate)
  45. self.track_for_cleanup(temp_sstate_path)
  46. bb_vars = get_bb_vars(['SSTATE_DIR', 'NATIVELSBSTRING'])
  47. self.sstate_path = bb_vars['SSTATE_DIR']
  48. self.hostdistro = bb_vars['NATIVELSBSTRING']
  49. self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro)
  50. if add_local_mirrors:
  51. config_set_sstate_if_not_set = 'SSTATE_MIRRORS ?= ""'
  52. self.append_config(config_set_sstate_if_not_set)
  53. for local_mirror in add_local_mirrors:
  54. self.assertFalse(os.path.join(local_mirror) == os.path.join(self.sstate_path), msg='Cannot add the current sstate path as a sstate mirror')
  55. config_sstate_mirror = "SSTATE_MIRRORS += \"file://.* file:///%s/PATH\"" % local_mirror
  56. self.append_config(config_sstate_mirror)
  57. # Returns a list containing sstate files
  58. def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True):
  59. result = []
  60. for root, dirs, files in os.walk(self.sstate_path):
  61. if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root):
  62. for f in files:
  63. if re.search(filename_regex, f):
  64. result.append(f)
  65. if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root):
  66. for f in files:
  67. if re.search(filename_regex, f):
  68. result.append(f)
  69. return result
  70. # Test sstate files creation and their location and directory perms
  71. def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
  72. self.config_sstate(temp_sstate_location, [self.sstate_path])
  73. if self.temp_sstate_location:
  74. bitbake(['-cclean'] + targets)
  75. else:
  76. bitbake(['-ccleansstate'] + targets)
  77. # We need to test that the env umask have does not effect sstate directory creation
  78. # So, first, we'll get the current umask and set it to something we know incorrect
  79. # See: sstate_task_postfunc for correct umask of os.umask(0o002)
  80. import os
  81. def current_umask():
  82. current_umask = os.umask(0)
  83. os.umask(current_umask)
  84. return current_umask
  85. orig_umask = current_umask()
  86. # Set it to a umask we know will be 'wrong'
  87. os.umask(0o022)
  88. bitbake(targets)
  89. file_tracker = []
  90. results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
  91. if distro_nonspecific:
  92. for r in results:
  93. if r.endswith(("_populate_lic.tar.zst", "_populate_lic.tar.zst.siginfo", "_fetch.tar.zst.siginfo", "_unpack.tar.zst.siginfo", "_patch.tar.zst.siginfo")):
  94. continue
  95. file_tracker.append(r)
  96. else:
  97. file_tracker = results
  98. if should_pass:
  99. self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
  100. else:
  101. self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker)))
  102. # Now we'll walk the tree to check the mode and see if things are incorrect.
  103. badperms = []
  104. for root, dirs, files in os.walk(self.sstate_path):
  105. for directory in dirs:
  106. if (os.stat(os.path.join(root, directory)).st_mode & 0o777) != 0o775:
  107. badperms.append(os.path.join(root, directory))
  108. # Return to original umask
  109. os.umask(orig_umask)
  110. if should_pass:
  111. self.assertTrue(badperms , msg="Found sstate directories with the wrong permissions: %s (found %s)" % (', '.join(map(str, targets)), str(badperms)))
  112. # Test the sstate files deletion part of the do_cleansstate task
  113. def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
  114. self.config_sstate(temp_sstate_location, [self.sstate_path])
  115. bitbake(['-ccleansstate'] + targets)
  116. bitbake(targets)
  117. archives_created = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific, distro_nonspecific)
  118. self.assertTrue(archives_created, msg="Could not find sstate .tar.zst files for: %s (%s)" % (', '.join(map(str, targets)), str(archives_created)))
  119. siginfo_created = self.search_sstate('|'.join(map(str, [s + r'.*?\.siginfo$' for s in targets])), distro_specific, distro_nonspecific)
  120. self.assertTrue(siginfo_created, msg="Could not find sstate .siginfo files for: %s (%s)" % (', '.join(map(str, targets)), str(siginfo_created)))
  121. bitbake(['-ccleansstate'] + targets)
  122. archives_removed = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific, distro_nonspecific)
  123. 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)))
  124. # Test rebuilding of distro-specific sstate files
  125. def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True):
  126. self.config_sstate(temp_sstate_location, [self.sstate_path])
  127. bitbake(['-ccleansstate'] + targets)
  128. bitbake(targets)
  129. results = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific=False, distro_nonspecific=True)
  130. filtered_results = []
  131. for r in results:
  132. if r.endswith(("_populate_lic.tar.zst", "_populate_lic.tar.zst.siginfo")):
  133. continue
  134. filtered_results.append(r)
  135. self.assertTrue(filtered_results == [], msg="Found distro non-specific sstate for: %s (%s)" % (', '.join(map(str, targets)), str(filtered_results)))
  136. file_tracker_1 = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific=True, distro_nonspecific=False)
  137. self.assertTrue(len(file_tracker_1) >= len(targets), msg = "Not all sstate files were created for: %s" % ', '.join(map(str, targets)))
  138. self.track_for_cleanup(self.distro_specific_sstate + "_old")
  139. shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old")
  140. shutil.rmtree(self.distro_specific_sstate)
  141. bitbake(['-cclean'] + targets)
  142. bitbake(targets)
  143. file_tracker_2 = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific=True, distro_nonspecific=False)
  144. self.assertTrue(len(file_tracker_2) >= len(targets), msg = "Not all sstate files were created for: %s" % ', '.join(map(str, targets)))
  145. not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2]
  146. self.assertTrue(not_recreated == [], msg="The following sstate files were not recreated: %s" % ', '.join(map(str, not_recreated)))
  147. created_once = [x for x in file_tracker_2 if x not in file_tracker_1]
  148. self.assertTrue(created_once == [], msg="The following sstate files were created only in the second run: %s" % ', '.join(map(str, created_once)))
  149. def sstate_common_samesigs(self, configA, configB, allarch=False):
  150. self.write_config(configA)
  151. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  152. bitbake("world meta-toolchain -S none")
  153. self.write_config(configB)
  154. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  155. bitbake("world meta-toolchain -S none")
  156. def get_files(d, result):
  157. for root, dirs, files in os.walk(d):
  158. for name in files:
  159. if "meta-environment" in root or "cross-canadian" in root:
  160. continue
  161. if "do_build" not in name:
  162. # 1.4.1+gitAUTOINC+302fca9f4c-r0.do_package_write_ipk.sigdata.f3a2a38697da743f0dbed8b56aafcf79
  163. (_, task, _, shash) = name.rsplit(".", 3)
  164. result[os.path.join(os.path.basename(root), task)] = shash
  165. files1 = {}
  166. files2 = {}
  167. subdirs = sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/*-nativesdk*-linux"))
  168. if allarch:
  169. subdirs.extend(sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/all-*-linux")))
  170. for subdir in subdirs:
  171. nativesdkdir = os.path.basename(subdir)
  172. get_files(self.topdir + "/tmp-sstatesamehash/stamps/" + nativesdkdir, files1)
  173. get_files(self.topdir + "/tmp-sstatesamehash2/stamps/" + nativesdkdir, files2)
  174. self.maxDiff = None
  175. self.assertEqual(files1, files2)
  176. class SStateTests(SStateBase):
  177. def test_autorev_sstate_works(self):
  178. # Test that a git repository which changes is correctly handled by SRCREV = ${AUTOREV}
  179. tempdir = tempfile.mkdtemp(prefix='sstate_autorev')
  180. tempdldir = tempfile.mkdtemp(prefix='sstate_autorev_dldir')
  181. self.track_for_cleanup(tempdir)
  182. self.track_for_cleanup(tempdldir)
  183. create_temp_layer(tempdir, 'selftestrecipetool')
  184. self.add_command_to_tearDown('bitbake-layers remove-layer %s' % tempdir)
  185. self.append_config("DL_DIR = \"%s\"" % tempdldir)
  186. runCmd('bitbake-layers add-layer %s' % tempdir)
  187. # Use dbus-wait as a local git repo we can add a commit between two builds in
  188. pn = 'dbus-wait'
  189. srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  190. url = 'git://git.yoctoproject.org/dbus-wait'
  191. result = runCmd('git clone %s noname' % url, cwd=tempdir)
  192. srcdir = os.path.join(tempdir, 'noname')
  193. result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir)
  194. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory')
  195. recipefile = os.path.join(tempdir, "recipes-test", "dbus-wait-test", 'dbus-wait-test_git.bb')
  196. os.makedirs(os.path.dirname(recipefile))
  197. srcuri = 'git://' + srcdir + ';protocol=file;branch=master'
  198. result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri])
  199. self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
  200. with open(recipefile, 'a') as f:
  201. f.write('SRCREV = "${AUTOREV}"\n')
  202. f.write('PV = "1.0"\n')
  203. bitbake("dbus-wait-test -c fetch")
  204. with open(os.path.join(srcdir, "bar.txt"), "w") as f:
  205. f.write("foo")
  206. result = runCmd('git add bar.txt; git commit -asm "add bar"', cwd=srcdir)
  207. bitbake("dbus-wait-test -c unpack")
  208. class SStateCreation(SStateBase):
  209. def test_sstate_creation_distro_specific_pass(self):
  210. self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
  211. def test_sstate_creation_distro_specific_fail(self):
  212. 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)
  213. def test_sstate_creation_distro_nonspecific_pass(self):
  214. self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
  215. def test_sstate_creation_distro_nonspecific_fail(self):
  216. self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False)
  217. class SStateCleanup(SStateBase):
  218. def test_cleansstate_task_distro_specific_nonspecific(self):
  219. targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native']
  220. targets.append('linux-libc-headers')
  221. self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True)
  222. def test_cleansstate_task_distro_nonspecific(self):
  223. self.run_test_cleansstate_task(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
  224. def test_cleansstate_task_distro_specific(self):
  225. targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native']
  226. targets.append('linux-libc-headers')
  227. self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
  228. class SStateDistroTests(SStateBase):
  229. def test_rebuild_distro_specific_sstate_cross_native_targets(self):
  230. self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch, 'binutils-native'], temp_sstate_location=True)
  231. def test_rebuild_distro_specific_sstate_cross_target(self):
  232. self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch], temp_sstate_location=True)
  233. def test_rebuild_distro_specific_sstate_native_target(self):
  234. self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True)
  235. class SStateCacheManagement(SStateBase):
  236. # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list
  237. # global_config elements are expected to not generate any sstate files that would be removed by sstate-cache-management.py (such as changing the value of MACHINE)
  238. def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=[''], ignore_patterns=[]):
  239. self.assertTrue(global_config)
  240. self.assertTrue(target_config)
  241. self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements')
  242. for idx in range(len(target_config)):
  243. self.append_config(global_config[idx])
  244. self.append_recipeinc(target, target_config[idx])
  245. bitbake(target)
  246. self.remove_config(global_config[idx])
  247. self.remove_recipeinc(target, target_config[idx])
  248. self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path])
  249. # For now this only checks if random sstate tasks are handled correctly as a group.
  250. # In the future we should add control over what tasks we check for.
  251. expected_remaining_sstate = []
  252. for idx in range(len(target_config)):
  253. self.append_config(global_config[idx])
  254. self.append_recipeinc(target, target_config[idx])
  255. if target_config[idx] == target_config[-1]:
  256. target_sstate_before_build = self.search_sstate(target + r'.*?\.tar.zst$')
  257. bitbake("-cclean %s" % target)
  258. result = bitbake(target, ignore_status=True)
  259. if target_config[idx] == target_config[-1]:
  260. target_sstate_after_build = self.search_sstate(target + r'.*?\.tar.zst$')
  261. 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)]
  262. self.remove_config(global_config[idx])
  263. self.remove_recipeinc(target, target_config[idx])
  264. self.assertEqual(result.status, 0, msg = "build of %s failed with %s" % (target, result.output))
  265. runCmd("sstate-cache-management.py -y --cache-dir=%s --remove-duplicated" % (self.sstate_path))
  266. 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)]
  267. actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate]
  268. self.assertFalse(actual_not_expected, msg="Files should have been removed but were not: %s" % ', '.join(map(str, actual_not_expected)))
  269. expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate]
  270. self.assertFalse(expected_not_actual, msg="Extra files were removed: %s" ', '.join(map(str, expected_not_actual)))
  271. def test_sstate_cache_management_script_using_pr_1(self):
  272. global_config = []
  273. target_config = []
  274. global_config.append('')
  275. target_config.append('PR = "0"')
  276. self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
  277. def test_sstate_cache_management_script_using_pr_2(self):
  278. global_config = []
  279. target_config = []
  280. global_config.append('')
  281. target_config.append('PR = "0"')
  282. global_config.append('')
  283. target_config.append('PR = "1"')
  284. self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
  285. def test_sstate_cache_management_script_using_pr_3(self):
  286. global_config = []
  287. target_config = []
  288. global_config.append('MACHINE = "qemux86-64"')
  289. target_config.append('PR = "0"')
  290. global_config.append(global_config[0])
  291. target_config.append('PR = "1"')
  292. global_config.append('MACHINE = "qemux86"')
  293. target_config.append('PR = "1"')
  294. self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
  295. def test_sstate_cache_management_script_using_machine(self):
  296. global_config = []
  297. target_config = []
  298. global_config.append('MACHINE = "qemux86-64"')
  299. target_config.append('')
  300. global_config.append('MACHINE = "qemux86"')
  301. target_config.append('')
  302. self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
  303. class SStateHashSameSigs(SStateBase):
  304. def sstate_hashtest(self, sdkmachine):
  305. self.write_config("""
  306. MACHINE = "qemux86"
  307. TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
  308. BUILD_ARCH = "x86_64"
  309. BUILD_OS = "linux"
  310. SDKMACHINE = "x86_64"
  311. PACKAGE_CLASSES = "package_rpm package_ipk package_deb"
  312. BB_SIGNATURE_HANDLER = "OEBasicHash"
  313. """)
  314. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  315. bitbake("core-image-weston -S none")
  316. self.write_config("""
  317. MACHINE = "qemux86"
  318. TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
  319. BUILD_ARCH = "i686"
  320. BUILD_OS = "linux"
  321. SDKMACHINE = "%s"
  322. PACKAGE_CLASSES = "package_rpm package_ipk package_deb"
  323. BB_SIGNATURE_HANDLER = "OEBasicHash"
  324. """ % sdkmachine)
  325. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  326. bitbake("core-image-weston -S none")
  327. def get_files(d):
  328. f = []
  329. for root, dirs, files in os.walk(d):
  330. if "core-image-weston" in root:
  331. # SDKMACHINE changing will change
  332. # do_rootfs/do_testimage/do_build stamps of images which
  333. # is safe to ignore.
  334. continue
  335. f.extend(os.path.join(root, name) for name in files)
  336. return f
  337. files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/")
  338. files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/")
  339. 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]
  340. self.maxDiff = None
  341. self.assertCountEqual(files1, files2)
  342. def test_sstate_32_64_same_hash(self):
  343. """
  344. The sstate checksums for both native and target should not vary whether
  345. they're built on a 32 or 64 bit system. Rather than requiring two different
  346. build machines and running a builds, override the variables calling uname()
  347. manually and check using bitbake -S.
  348. """
  349. self.sstate_hashtest("i686")
  350. def test_sstate_sdk_arch_same_hash(self):
  351. """
  352. Similarly, test an arm SDK has the same hashes
  353. """
  354. self.sstate_hashtest("aarch64")
  355. def test_sstate_nativelsbstring_same_hash(self):
  356. """
  357. The sstate checksums should be independent of whichever NATIVELSBSTRING is
  358. detected. Rather than requiring two different build machines and running
  359. builds, override the variables manually and check using bitbake -S.
  360. """
  361. self.write_config("""
  362. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
  363. NATIVELSBSTRING = \"DistroA\"
  364. BB_SIGNATURE_HANDLER = "OEBasicHash"
  365. """)
  366. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  367. bitbake("core-image-weston -S none")
  368. self.write_config("""
  369. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
  370. NATIVELSBSTRING = \"DistroB\"
  371. BB_SIGNATURE_HANDLER = "OEBasicHash"
  372. """)
  373. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  374. bitbake("core-image-weston -S none")
  375. def get_files(d):
  376. f = []
  377. for root, dirs, files in os.walk(d):
  378. f.extend(os.path.join(root, name) for name in files)
  379. return f
  380. files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/")
  381. files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/")
  382. files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
  383. self.maxDiff = None
  384. self.assertCountEqual(files1, files2)
  385. class SStateHashSameSigs2(SStateBase):
  386. def test_sstate_allarch_samesigs(self):
  387. """
  388. The sstate checksums of allarch packages should be independent of whichever
  389. MACHINE is set. Check this using bitbake -S.
  390. Also, rather than duplicate the test, check nativesdk stamps are the same between
  391. the two MACHINE values.
  392. """
  393. configA = """
  394. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
  395. MACHINE = \"qemux86-64\"
  396. BB_SIGNATURE_HANDLER = "OEBasicHash"
  397. """
  398. #OLDEST_KERNEL is arch specific so set to a different value here for testing
  399. configB = """
  400. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
  401. MACHINE = \"qemuarm\"
  402. OLDEST_KERNEL = \"3.3.0\"
  403. BB_SIGNATURE_HANDLER = "OEBasicHash"
  404. ERROR_QA:append = " somenewoption"
  405. WARN_QA:append = " someotheroption"
  406. """
  407. self.sstate_common_samesigs(configA, configB, allarch=True)
  408. def test_sstate_nativesdk_samesigs_multilib(self):
  409. """
  410. check nativesdk stamps are the same between the two MACHINE values.
  411. """
  412. configA = """
  413. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
  414. MACHINE = \"qemux86-64\"
  415. require conf/multilib.conf
  416. MULTILIBS = \"multilib:lib32\"
  417. DEFAULTTUNE:virtclass-multilib-lib32 = \"x86\"
  418. BB_SIGNATURE_HANDLER = "OEBasicHash"
  419. """
  420. configB = """
  421. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
  422. MACHINE = \"qemuarm\"
  423. require conf/multilib.conf
  424. MULTILIBS = \"\"
  425. BB_SIGNATURE_HANDLER = "OEBasicHash"
  426. """
  427. self.sstate_common_samesigs(configA, configB)
  428. class SStateHashSameSigs3(SStateBase):
  429. def test_sstate_sametune_samesigs(self):
  430. """
  431. The sstate checksums of two identical machines (using the same tune) should be the
  432. same, apart from changes within the machine specific stamps directory. We use the
  433. qemux86copy machine to test this. Also include multilibs in the test.
  434. """
  435. self.write_config("""
  436. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
  437. MACHINE = \"qemux86\"
  438. require conf/multilib.conf
  439. MULTILIBS = "multilib:lib32"
  440. DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
  441. BB_SIGNATURE_HANDLER = "OEBasicHash"
  442. """)
  443. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  444. bitbake("world meta-toolchain -S none")
  445. self.write_config("""
  446. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
  447. MACHINE = \"qemux86copy\"
  448. require conf/multilib.conf
  449. MULTILIBS = "multilib:lib32"
  450. DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
  451. BB_SIGNATURE_HANDLER = "OEBasicHash"
  452. """)
  453. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  454. bitbake("world meta-toolchain -S none")
  455. def get_files(d):
  456. f = []
  457. for root, dirs, files in os.walk(d):
  458. for name in files:
  459. if "meta-environment" in root or "cross-canadian" in root or 'meta-ide-support' in root:
  460. continue
  461. if "qemux86copy-" in root or "qemux86-" in root:
  462. continue
  463. if "do_build" not in name and "do_populate_sdk" not in name:
  464. f.append(os.path.join(root, name))
  465. return f
  466. files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps")
  467. files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps")
  468. files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
  469. self.maxDiff = None
  470. self.assertCountEqual(files1, files2)
  471. def test_sstate_multilib_or_not_native_samesigs(self):
  472. """The sstate checksums of two native recipes (and their dependencies)
  473. where the target is using multilib in one but not the other
  474. should be the same. We use the qemux86copy machine to test
  475. this.
  476. """
  477. self.write_config("""
  478. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\"
  479. MACHINE = \"qemux86\"
  480. require conf/multilib.conf
  481. MULTILIBS = "multilib:lib32"
  482. DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
  483. BB_SIGNATURE_HANDLER = "OEBasicHash"
  484. """)
  485. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  486. bitbake("binutils-native -S none")
  487. self.write_config("""
  488. TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\"
  489. MACHINE = \"qemux86copy\"
  490. BB_SIGNATURE_HANDLER = "OEBasicHash"
  491. """)
  492. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  493. bitbake("binutils-native -S none")
  494. def get_files(d):
  495. f = []
  496. for root, dirs, files in os.walk(d):
  497. for name in files:
  498. f.append(os.path.join(root, name))
  499. return f
  500. files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps")
  501. files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps")
  502. files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
  503. self.maxDiff = None
  504. self.assertCountEqual(files1, files2)
  505. class SStateHashSameSigs4(SStateBase):
  506. def test_sstate_noop_samesigs(self):
  507. """
  508. The sstate checksums of two builds with these variables changed or
  509. classes inherits should be the same.
  510. """
  511. self.write_config("""
  512. TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
  513. BB_NUMBER_THREADS = "${@oe.utils.cpu_count()}"
  514. PARALLEL_MAKE = "-j 1"
  515. DL_DIR = "${TOPDIR}/download1"
  516. TIME = "111111"
  517. DATE = "20161111"
  518. INHERIT:remove = "buildstats-summary buildhistory uninative"
  519. http_proxy = ""
  520. BB_SIGNATURE_HANDLER = "OEBasicHash"
  521. """)
  522. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  523. self.track_for_cleanup(self.topdir + "/download1")
  524. bitbake("world meta-toolchain -S none")
  525. self.write_config("""
  526. TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
  527. BB_NUMBER_THREADS = "${@oe.utils.cpu_count()+1}"
  528. PARALLEL_MAKE = "-j 2"
  529. DL_DIR = "${TOPDIR}/download2"
  530. TIME = "222222"
  531. DATE = "20161212"
  532. # Always remove uninative as we're changing proxies
  533. INHERIT:remove = "uninative"
  534. INHERIT += "buildstats-summary buildhistory"
  535. http_proxy = "http://example.com/"
  536. BB_SIGNATURE_HANDLER = "OEBasicHash"
  537. """)
  538. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  539. self.track_for_cleanup(self.topdir + "/download2")
  540. bitbake("world meta-toolchain -S none")
  541. def get_files(d):
  542. f = {}
  543. for root, dirs, files in os.walk(d):
  544. for name in files:
  545. name, shash = name.rsplit('.', 1)
  546. # Extract just the machine and recipe name
  547. base = os.sep.join(root.rsplit(os.sep, 2)[-2:] + [name])
  548. f[base] = shash
  549. return f
  550. def compare_sigfiles(files, files1, files2, compare=False):
  551. for k in files:
  552. if k in files1 and k in files2:
  553. print("%s differs:" % k)
  554. if compare:
  555. sigdatafile1 = self.topdir + "/tmp-sstatesamehash/stamps/" + k + "." + files1[k]
  556. sigdatafile2 = self.topdir + "/tmp-sstatesamehash2/stamps/" + k + "." + files2[k]
  557. output = bb.siggen.compare_sigfiles(sigdatafile1, sigdatafile2)
  558. if output:
  559. print('\n'.join(output))
  560. elif k in files1 and k not in files2:
  561. print("%s in files1" % k)
  562. elif k not in files1 and k in files2:
  563. print("%s in files2" % k)
  564. else:
  565. assert "shouldn't reach here"
  566. files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps/")
  567. files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps/")
  568. # Remove items that are identical in both sets
  569. for k,v in files1.items() & files2.items():
  570. del files1[k]
  571. del files2[k]
  572. if not files1 and not files2:
  573. # No changes, so we're done
  574. return
  575. files = list(files1.keys() | files2.keys())
  576. # this is an expensive computation, thus just compare the first 'max_sigfiles_to_compare' k files
  577. max_sigfiles_to_compare = 20
  578. first, rest = files[:max_sigfiles_to_compare], files[max_sigfiles_to_compare:]
  579. compare_sigfiles(first, files1, files2, compare=True)
  580. compare_sigfiles(rest, files1, files2, compare=False)
  581. self.fail("sstate hashes not identical.")
  582. def test_sstate_movelayer_samesigs(self):
  583. """
  584. The sstate checksums of two builds with the same oe-core layer in two
  585. different locations should be the same.
  586. """
  587. core_layer = os.path.join(
  588. self.tc.td["COREBASE"], 'meta')
  589. copy_layer_1 = self.topdir + "/meta-copy1/meta"
  590. copy_layer_2 = self.topdir + "/meta-copy2/meta"
  591. oe.path.copytree(core_layer, copy_layer_1)
  592. os.symlink(os.path.dirname(core_layer) + "/scripts", self.topdir + "/meta-copy1/scripts")
  593. self.write_config("""
  594. TMPDIR = "${TOPDIR}/tmp-sstatesamehash"
  595. """)
  596. bblayers_conf = 'BBLAYERS += "%s"\nBBLAYERS:remove = "%s"' % (copy_layer_1, core_layer)
  597. self.write_bblayers_config(bblayers_conf)
  598. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash")
  599. bitbake("bash -S none")
  600. oe.path.copytree(core_layer, copy_layer_2)
  601. os.symlink(os.path.dirname(core_layer) + "/scripts", self.topdir + "/meta-copy2/scripts")
  602. self.write_config("""
  603. TMPDIR = "${TOPDIR}/tmp-sstatesamehash2"
  604. """)
  605. bblayers_conf = 'BBLAYERS += "%s"\nBBLAYERS:remove = "%s"' % (copy_layer_2, core_layer)
  606. self.write_bblayers_config(bblayers_conf)
  607. self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2")
  608. bitbake("bash -S none")
  609. def get_files(d):
  610. f = []
  611. for root, dirs, files in os.walk(d):
  612. for name in files:
  613. f.append(os.path.join(root, name))
  614. return f
  615. files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps")
  616. files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps")
  617. files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
  618. self.maxDiff = None
  619. self.assertCountEqual(files1, files2)
  620. class SStateFindSiginfo(SStateBase):
  621. def test_sstate_compare_sigfiles_and_find_siginfo(self):
  622. """
  623. Test the functionality of the find_siginfo: basic function and callback in compare_sigfiles
  624. """
  625. self.write_config("""
  626. TMPDIR = \"${TOPDIR}/tmp-sstates-findsiginfo\"
  627. MACHINE = \"qemux86-64\"
  628. require conf/multilib.conf
  629. MULTILIBS = "multilib:lib32"
  630. DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
  631. BB_SIGNATURE_HANDLER = "OEBasicHash"
  632. """)
  633. self.track_for_cleanup(self.topdir + "/tmp-sstates-findsiginfo")
  634. pns = ["binutils", "binutils-native", "lib32-binutils"]
  635. target_configs = [
  636. """
  637. TMPVAL1 = "tmpval1"
  638. TMPVAL2 = "tmpval2"
  639. do_tmptask1() {
  640. echo ${TMPVAL1}
  641. }
  642. do_tmptask2() {
  643. echo ${TMPVAL2}
  644. }
  645. addtask do_tmptask1
  646. addtask tmptask2 before do_tmptask1
  647. """,
  648. """
  649. TMPVAL3 = "tmpval3"
  650. TMPVAL4 = "tmpval4"
  651. do_tmptask1() {
  652. echo ${TMPVAL3}
  653. }
  654. do_tmptask2() {
  655. echo ${TMPVAL4}
  656. }
  657. addtask do_tmptask1
  658. addtask tmptask2 before do_tmptask1
  659. """
  660. ]
  661. for target_config in target_configs:
  662. self.write_recipeinc("binutils", target_config)
  663. for pn in pns:
  664. bitbake("%s -c do_tmptask1 -S none" % pn)
  665. self.delete_recipeinc("binutils")
  666. with bb.tinfoil.Tinfoil() as tinfoil:
  667. tinfoil.prepare(config_only=True)
  668. def find_siginfo(pn, taskname, sigs=None):
  669. result = None
  670. command_complete = False
  671. tinfoil.set_event_mask(["bb.event.FindSigInfoResult",
  672. "bb.command.CommandCompleted"])
  673. ret = tinfoil.run_command("findSigInfo", pn, taskname, sigs)
  674. if ret:
  675. while result is None or not command_complete:
  676. event = tinfoil.wait_event(1)
  677. if event:
  678. if isinstance(event, bb.command.CommandCompleted):
  679. command_complete = True
  680. elif isinstance(event, bb.event.FindSigInfoResult):
  681. result = event.result
  682. return result
  683. def recursecb(key, hash1, hash2):
  684. nonlocal recursecb_count
  685. recursecb_count += 1
  686. hashes = [hash1, hash2]
  687. hashfiles = find_siginfo(key, None, hashes)
  688. self.assertCountEqual(hashes, hashfiles)
  689. bb.siggen.compare_sigfiles(hashfiles[hash1]['path'], hashfiles[hash2]['path'], recursecb)
  690. for pn in pns:
  691. recursecb_count = 0
  692. matches = find_siginfo(pn, "do_tmptask1")
  693. self.assertGreaterEqual(len(matches), 2)
  694. latesthashes = sorted(matches.keys(), key=lambda h: matches[h]['time'])[-2:]
  695. bb.siggen.compare_sigfiles(matches[latesthashes[-2]]['path'], matches[latesthashes[-1]]['path'], recursecb)
  696. self.assertEqual(recursecb_count,1)
  697. class SStatePrintdiff(SStateBase):
  698. def run_test_printdiff_changerecipe(self, target, change_recipe, change_bbtask, change_content, expected_sametmp_output, expected_difftmp_output):
  699. import time
  700. self.write_config("""
  701. TMPDIR = "${{TOPDIR}}/tmp-sstateprintdiff-sametmp-{}"
  702. """.format(time.time()))
  703. # Use runall do_build to ensure any indirect sstate is created, e.g. tzcode-native on both x86 and
  704. # aarch64 hosts since only allarch target recipes depend upon it and it may not be built otherwise.
  705. # A bitbake -c cleansstate tzcode-native would cause some of these tests to error for example.
  706. bitbake("--runall build --runall deploy_source_date_epoch {}".format(target))
  707. bitbake("-S none {}".format(target))
  708. bitbake(change_bbtask)
  709. self.write_recipeinc(change_recipe, change_content)
  710. result_sametmp = bitbake("-S printdiff {}".format(target))
  711. self.write_config("""
  712. TMPDIR = "${{TOPDIR}}/tmp-sstateprintdiff-difftmp-{}"
  713. """.format(time.time()))
  714. result_difftmp = bitbake("-S printdiff {}".format(target))
  715. self.delete_recipeinc(change_recipe)
  716. for item in expected_sametmp_output:
  717. self.assertIn(item, result_sametmp.output, msg = "Item {} not found in output:\n{}".format(item, result_sametmp.output))
  718. for item in expected_difftmp_output:
  719. self.assertIn(item, result_difftmp.output, msg = "Item {} not found in output:\n{}".format(item, result_difftmp.output))
  720. def run_test_printdiff_changeconfig(self, target, change_bbtasks, change_content, expected_sametmp_output, expected_difftmp_output):
  721. import time
  722. self.write_config("""
  723. TMPDIR = "${{TOPDIR}}/tmp-sstateprintdiff-sametmp-{}"
  724. """.format(time.time()))
  725. bitbake("--runall build --runall deploy_source_date_epoch {}".format(target))
  726. bitbake("-S none {}".format(target))
  727. bitbake(" ".join(change_bbtasks))
  728. self.append_config(change_content)
  729. result_sametmp = bitbake("-S printdiff {}".format(target))
  730. self.write_config("""
  731. TMPDIR = "${{TOPDIR}}/tmp-sstateprintdiff-difftmp-{}"
  732. """.format(time.time()))
  733. self.append_config(change_content)
  734. result_difftmp = bitbake("-S printdiff {}".format(target))
  735. for item in expected_sametmp_output:
  736. self.assertIn(item, result_sametmp.output, msg = "Item {} not found in output:\n{}".format(item, result_sametmp.output))
  737. for item in expected_difftmp_output:
  738. self.assertIn(item, result_difftmp.output, msg = "Item {} not found in output:\n{}".format(item, result_difftmp.output))
  739. # Check if printdiff walks the full dependency chain from the image target to where the change is in a specific recipe
  740. def test_image_minimal_vs_perlcross(self):
  741. expected_output = ("Task perlcross-native:do_install couldn't be used from the cache because:",
  742. "We need hash",
  743. "most recent matching task was")
  744. expected_sametmp_output = expected_output + (
  745. "Variable do_install value changed",
  746. '+ echo "this changes the task signature"')
  747. expected_difftmp_output = expected_output
  748. self.run_test_printdiff_changerecipe("core-image-minimal", "perlcross", "-c do_install perlcross-native",
  749. """
  750. do_install:append() {
  751. echo "this changes the task signature"
  752. }
  753. """,
  754. expected_sametmp_output, expected_difftmp_output)
  755. # Check if changes to gcc-source (which uses tmp/work-shared) are correctly discovered
  756. def test_gcc_runtime_vs_gcc_source(self):
  757. gcc_source_pn = 'gcc-source-%s' % get_bb_vars(['PV'], 'gcc')['PV']
  758. expected_output = ("Task {}:do_preconfigure couldn't be used from the cache because:".format(gcc_source_pn),
  759. "We need hash",
  760. "most recent matching task was")
  761. expected_sametmp_output = expected_output + (
  762. "Variable do_preconfigure value changed",
  763. '+ print("this changes the task signature")')
  764. expected_difftmp_output = expected_output
  765. self.run_test_printdiff_changerecipe("gcc-runtime", "gcc-source", "-c do_preconfigure {}".format(gcc_source_pn),
  766. """
  767. python do_preconfigure:append() {
  768. print("this changes the task signature")
  769. }
  770. """,
  771. expected_sametmp_output, expected_difftmp_output)
  772. # Check if changing a really base task definiton is reported against multiple core recipes using it
  773. def test_image_minimal_vs_base_do_configure(self):
  774. change_bbtasks = ('zstd-native:do_configure',
  775. 'texinfo-dummy-native:do_configure',
  776. 'ldconfig-native:do_configure',
  777. 'gettext-minimal-native:do_configure',
  778. 'tzcode-native:do_configure',
  779. 'makedevs-native:do_configure',
  780. 'pigz-native:do_configure',
  781. 'update-rc.d-native:do_configure',
  782. 'unzip-native:do_configure',
  783. 'gnu-config-native:do_configure')
  784. expected_output = ["Task {} couldn't be used from the cache because:".format(t) for t in change_bbtasks] + [
  785. "We need hash",
  786. "most recent matching task was"]
  787. expected_sametmp_output = expected_output + [
  788. "Variable base_do_configure value changed",
  789. '+ echo "this changes base_do_configure() definiton "']
  790. expected_difftmp_output = expected_output
  791. self.run_test_printdiff_changeconfig("core-image-minimal",change_bbtasks,
  792. """
  793. INHERIT += "base-do-configure-modified"
  794. """,
  795. expected_sametmp_output, expected_difftmp_output)
  796. class SStateCheckObjectPresence(SStateBase):
  797. def check_bb_output(self, output, targets, exceptions, check_cdn):
  798. def is_exception(object, exceptions):
  799. for e in exceptions:
  800. if re.search(e, object):
  801. return True
  802. return False
  803. # sstate is checked for existence of these, but they never get written out to begin with
  804. exceptions += ["{}.*image_qa".format(t) for t in targets.split()]
  805. exceptions += ["{}.*deploy_source_date_epoch".format(t) for t in targets.split()]
  806. exceptions += ["{}.*image_complete".format(t) for t in targets.split()]
  807. exceptions += ["linux-yocto.*shared_workdir"]
  808. # these get influnced by IMAGE_FSTYPES tweaks in yocto-autobuilder-helper's config.json (on x86-64)
  809. # additionally, they depend on noexec (thus, absent stamps) package, install, etc. image tasks,
  810. # which makes tracing other changes difficult
  811. exceptions += ["{}.*create_.*spdx".format(t) for t in targets.split()]
  812. output_l = output.splitlines()
  813. for l in output_l:
  814. if l.startswith("Sstate summary"):
  815. for idx, item in enumerate(l.split()):
  816. if item == 'Missed':
  817. missing_objects = int(l.split()[idx+1])
  818. break
  819. else:
  820. self.fail("Did not find missing objects amount in sstate summary: {}".format(l))
  821. break
  822. else:
  823. self.fail("Did not find 'Sstate summary' line in bitbake output")
  824. failed_urls = []
  825. failed_urls_extrainfo = []
  826. for l in output_l:
  827. if "SState: Unsuccessful fetch test for" in l and check_cdn:
  828. missing_object = l.split()[6]
  829. elif "SState: Looked for but didn't find file" in l and not check_cdn:
  830. missing_object = l.split()[8]
  831. else:
  832. missing_object = None
  833. if missing_object:
  834. if not is_exception(missing_object, exceptions):
  835. failed_urls.append(missing_object)
  836. else:
  837. missing_objects -= 1
  838. if "urlopen failed for" in l and not is_exception(l, exceptions):
  839. failed_urls_extrainfo.append(l)
  840. self.assertEqual(len(failed_urls), missing_objects, "Amount of reported missing objects does not match failed URLs: {}\nFailed URLs:\n{}\nFetcher diagnostics:\n{}".format(missing_objects, "\n".join(failed_urls), "\n".join(failed_urls_extrainfo)))
  841. self.assertEqual(len(failed_urls), 0, "Missing objects in the cache:\n{}\nFetcher diagnostics:\n{}".format("\n".join(failed_urls), "\n".join(failed_urls_extrainfo)))
  842. @OETestTag("yocto-mirrors")
  843. class SStateMirrors(SStateCheckObjectPresence):
  844. def run_test(self, machine, targets, exceptions, check_cdn = True, ignore_errors = False):
  845. if check_cdn:
  846. self.config_sstate(True)
  847. self.append_config("""
  848. MACHINE = "{}"
  849. BB_HASHSERVE_UPSTREAM = "hashserv.yoctoproject.org:8686"
  850. SSTATE_MIRRORS ?= "file://.* http://cdn.jsdelivr.net/yocto/sstate/all/PATH;downloadfilename=PATH"
  851. """.format(machine))
  852. else:
  853. self.append_config("""
  854. MACHINE = "{}"
  855. """.format(machine))
  856. result = bitbake("-DD -n {}".format(targets))
  857. bitbake("-S none {}".format(targets))
  858. if ignore_errors:
  859. return
  860. self.check_bb_output(result.output, targets, exceptions, check_cdn)
  861. def test_cdn_mirror_qemux86_64(self):
  862. exceptions = []
  863. self.run_test("qemux86-64", "core-image-minimal core-image-full-cmdline core-image-sato-sdk", exceptions, ignore_errors = True)
  864. self.run_test("qemux86-64", "core-image-minimal core-image-full-cmdline core-image-sato-sdk", exceptions)
  865. def test_cdn_mirror_qemuarm64(self):
  866. exceptions = []
  867. self.run_test("qemuarm64", "core-image-minimal core-image-full-cmdline core-image-sato-sdk", exceptions, ignore_errors = True)
  868. self.run_test("qemuarm64", "core-image-minimal core-image-full-cmdline core-image-sato-sdk", exceptions)
  869. def test_local_cache_qemux86_64(self):
  870. exceptions = []
  871. self.run_test("qemux86-64", "core-image-minimal core-image-full-cmdline core-image-sato-sdk", exceptions, check_cdn = False)
  872. def test_local_cache_qemuarm64(self):
  873. exceptions = []
  874. self.run_test("qemuarm64", "core-image-minimal core-image-full-cmdline core-image-sato-sdk", exceptions, check_cdn = False)