bbtests.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import os
  2. import re
  3. import oeqa.utils.ftools as ftools
  4. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
  5. from oeqa.selftest.case import OESelftestTestCase
  6. class BitbakeTests(OESelftestTestCase):
  7. def getline(self, res, line):
  8. for l in res.output.split('\n'):
  9. if line in l:
  10. return l
  11. # Test bitbake can run from the <builddir>/conf directory
  12. def test_run_bitbake_from_dir_1(self):
  13. os.chdir(os.path.join(self.builddir, 'conf'))
  14. self.assertEqual(bitbake('-e').status, 0, msg = "bitbake couldn't run from \"conf\" dir")
  15. # Test bitbake can run from the <builddir>'s parent directory
  16. def test_run_bitbake_from_dir_2(self):
  17. my_env = os.environ.copy()
  18. my_env['BBPATH'] = my_env['BUILDDIR']
  19. os.chdir(os.path.dirname(os.environ['BUILDDIR']))
  20. self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir's parent directory")
  21. # Test bitbake can run from some other random system location (we use /tmp/)
  22. def test_run_bitbake_from_dir_3(self):
  23. my_env = os.environ.copy()
  24. my_env['BBPATH'] = my_env['BUILDDIR']
  25. os.chdir("/tmp/")
  26. self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from /tmp/")
  27. def test_event_handler(self):
  28. self.write_config("INHERIT += \"test_events\"")
  29. result = bitbake('m4-native')
  30. find_build_started = re.search(r"NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing RunQueue Tasks", result.output)
  31. find_build_completed = re.search(r"Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output)
  32. self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output)
  33. self.assertTrue(find_build_completed, msg = "Match failed in:\n%s" % result.output)
  34. self.assertFalse('Test for bb.event.InvalidEvent' in result.output, msg = "\"Test for bb.event.InvalidEvent\" message found during bitbake process. bitbake output: %s" % result.output)
  35. def test_local_sstate(self):
  36. bitbake('m4-native')
  37. bitbake('m4-native -cclean')
  38. result = bitbake('m4-native')
  39. find_setscene = re.search("m4-native.*do_.*_setscene", result.output)
  40. self.assertTrue(find_setscene, msg = "No \"m4-native.*do_.*_setscene\" message found during bitbake m4-native. bitbake output: %s" % result.output )
  41. def test_bitbake_invalid_recipe(self):
  42. result = bitbake('-b asdf', ignore_status=True)
  43. self.assertTrue("ERROR: Unable to find any recipe file matching 'asdf'" in result.output, msg = "Though asdf recipe doesn't exist, bitbake didn't output any err. message. bitbake output: %s" % result.output)
  44. def test_bitbake_invalid_target(self):
  45. result = bitbake('asdf', ignore_status=True)
  46. self.assertTrue("ERROR: Nothing PROVIDES 'asdf'" in result.output, msg = "Though no 'asdf' target exists, bitbake didn't output any err. message. bitbake output: %s" % result.output)
  47. def test_warnings_errors(self):
  48. result = bitbake('-b asdf', ignore_status=True)
  49. find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages* shown", result.output)
  50. find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output)
  51. self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output)
  52. self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output)
  53. def test_invalid_patch(self):
  54. # This patch should fail to apply.
  55. self.write_recipeinc('man-db', 'FILESEXTRAPATHS_prepend := "${THISDIR}/files:"\nSRC_URI += "file://0001-Test-patch-here.patch"')
  56. self.write_config("INHERIT_remove = \"report-error\"")
  57. result = bitbake('man-db -c patch', ignore_status=True)
  58. self.delete_recipeinc('man-db')
  59. bitbake('-cclean man-db')
  60. line = self.getline(result, "Function failed: patch_do_patch")
  61. self.assertTrue(line and line.startswith("ERROR:"), msg = "Incorrectly formed patch application didn't fail. bitbake output: %s" % result.output)
  62. def test_force_task_1(self):
  63. # test 1 from bug 5875
  64. test_recipe = 'zlib'
  65. test_data = "Microsoft Made No Profit From Anyone's Zunes Yo"
  66. bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe)
  67. image_dir = bb_vars['D']
  68. pkgsplit_dir = bb_vars['PKGDEST']
  69. man_dir = bb_vars['mandir']
  70. bitbake('-c clean %s' % test_recipe)
  71. bitbake('-c package -f %s' % test_recipe)
  72. self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
  73. man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3')
  74. ftools.append_file(man_file, test_data)
  75. bitbake('-c package -f %s' % test_recipe)
  76. man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3')
  77. man_split_content = ftools.read_file(man_split_file)
  78. self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.')
  79. ret = bitbake(test_recipe)
  80. self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.')
  81. def test_force_task_2(self):
  82. # test 2 from bug 5875
  83. test_recipe = 'zlib'
  84. bitbake(test_recipe)
  85. self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
  86. result = bitbake('-C compile %s' % test_recipe)
  87. look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:']
  88. for task in look_for_tasks:
  89. self.assertIn(task, result.output, msg="Couldn't find %s task.")
  90. def test_bitbake_g(self):
  91. result = bitbake('-g core-image-minimal')
  92. for f in ['pn-buildlist', 'recipe-depends.dot', 'task-depends.dot']:
  93. self.addCleanup(os.remove, f)
  94. self.assertTrue('Task dependencies saved to \'task-depends.dot\'' in result.output, msg = "No task dependency \"task-depends.dot\" file was generated for the given task target. bitbake output: %s" % result.output)
  95. self.assertTrue('busybox' in ftools.read_file(os.path.join(self.builddir, 'task-depends.dot')), msg = "No \"busybox\" dependency found in task-depends.dot file.")
  96. def test_image_manifest(self):
  97. bitbake('core-image-minimal')
  98. bb_vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "IMAGE_LINK_NAME"], "core-image-minimal")
  99. deploydir = bb_vars["DEPLOY_DIR_IMAGE"]
  100. imagename = bb_vars["IMAGE_LINK_NAME"]
  101. manifest = os.path.join(deploydir, imagename + ".manifest")
  102. self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest)
  103. def test_invalid_recipe_src_uri(self):
  104. data = 'SRC_URI = "file://invalid"'
  105. self.write_recipeinc('man-db', data)
  106. self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
  107. SSTATE_DIR = \"${TOPDIR}/download-selftest\"
  108. INHERIT_remove = \"report-error\"
  109. """)
  110. self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
  111. bitbake('-ccleanall man-db')
  112. result = bitbake('-c fetch man-db', ignore_status=True)
  113. bitbake('-ccleanall man-db')
  114. self.delete_recipeinc('man-db')
  115. self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output)
  116. self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \
  117. doesn't exist, yet no error message encountered. bitbake output: %s" % result.output)
  118. line = self.getline(result, 'Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.')
  119. self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \
  120. doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output)
  121. def test_rename_downloaded_file(self):
  122. # TODO unique dldir instead of using cleanall
  123. # TODO: need to set sstatedir?
  124. self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
  125. SSTATE_DIR = \"${TOPDIR}/download-selftest\"
  126. """)
  127. self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
  128. data = 'SRC_URI = "${GNU_MIRROR}/aspell/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"'
  129. self.write_recipeinc('aspell', data)
  130. result = bitbake('-f -c fetch aspell', ignore_status=True)
  131. self.delete_recipeinc('aspell')
  132. self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output)
  133. dl_dir = get_bb_var("DL_DIR")
  134. self.assertTrue(os.path.isfile(os.path.join(dl_dir, 'test-aspell.tar.gz')), msg = "File rename failed. No corresponding test-aspell.tar.gz file found under %s" % dl_dir)
  135. self.assertTrue(os.path.isfile(os.path.join(dl_dir, 'test-aspell.tar.gz.done')), "File rename failed. No corresponding test-aspell.tar.gz.done file found under %s" % dl_dir)
  136. def test_environment(self):
  137. self.write_config("TEST_ENV=\"localconf\"")
  138. result = runCmd('bitbake -e | grep TEST_ENV=')
  139. self.assertTrue('localconf' in result.output, msg = "bitbake didn't report any value for TEST_ENV variable. To test, run 'bitbake -e | grep TEST_ENV='")
  140. def test_dry_run(self):
  141. result = runCmd('bitbake -n m4-native')
  142. self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output)
  143. def test_just_parse(self):
  144. result = runCmd('bitbake -p')
  145. self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output)
  146. def test_version(self):
  147. result = runCmd('bitbake -s | grep wget')
  148. find = re.search(r"wget *:([0-9a-zA-Z\.\-]+)", result.output)
  149. self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output)
  150. def test_prefile(self):
  151. preconf = os.path.join(self.builddir, 'conf/prefile.conf')
  152. self.track_for_cleanup(preconf)
  153. ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"")
  154. result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
  155. self.assertTrue('prefile' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration. ")
  156. self.write_config("TEST_PREFILE=\"localconf\"")
  157. result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
  158. self.assertTrue('localconf' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration.")
  159. def test_postfile(self):
  160. postconf = os.path.join(self.builddir, 'conf/postfile.conf')
  161. self.track_for_cleanup(postconf)
  162. ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"")
  163. self.write_config("TEST_POSTFILE=\"localconf\"")
  164. result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=')
  165. self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.")
  166. def test_checkuri(self):
  167. result = runCmd('bitbake -c checkuri m4')
  168. self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output)
  169. def test_continue(self):
  170. self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
  171. SSTATE_DIR = \"${TOPDIR}/download-selftest\"
  172. INHERIT_remove = \"report-error\"
  173. """)
  174. self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
  175. self.write_recipeinc('man-db',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" )
  176. runCmd('bitbake -c cleanall man-db xcursor-transparent-theme')
  177. result = runCmd('bitbake -c unpack -k man-db xcursor-transparent-theme', ignore_status=True)
  178. errorpos = result.output.find('ERROR: Function failed: do_fail_task')
  179. manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output)
  180. continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1))
  181. self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output)
  182. def test_non_gplv3(self):
  183. self.write_config('INCOMPATIBLE_LICENSE = "GPLv3"')
  184. result = bitbake('selftest-ed', ignore_status=True)
  185. self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
  186. lic_dir = get_bb_var('LICENSE_DIRECTORY')
  187. self.assertFalse(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv3')))
  188. self.assertTrue(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv2')))
  189. def test_setscene_only(self):
  190. """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)"""
  191. test_recipe = 'ed'
  192. bitbake(test_recipe)
  193. bitbake('-c clean %s' % test_recipe)
  194. ret = bitbake('--setscene-only %s' % test_recipe)
  195. tasks = re.findall(r'task\s+(do_\S+):', ret.output)
  196. for task in tasks:
  197. self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n'
  198. 'Executed tasks were: %s' % (task, str(tasks)))
  199. def test_bbappend_order(self):
  200. """ Bitbake should bbappend to recipe in a predictable order """
  201. test_recipe = 'ed'
  202. bb_vars = get_bb_vars(['SUMMARY', 'PV'], test_recipe)
  203. test_recipe_summary_before = bb_vars['SUMMARY']
  204. test_recipe_pv = bb_vars['PV']
  205. recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend'
  206. expected_recipe_summary = test_recipe_summary_before
  207. for i in range(5):
  208. recipe_append_dir = test_recipe + '_test_' + str(i)
  209. recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file)
  210. os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir))
  211. feature = 'SUMMARY += "%s"\n' % i
  212. ftools.write_file(recipe_append_path, feature)
  213. expected_recipe_summary += ' %s' % i
  214. self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test',
  215. test_recipe + '_test_*'))
  216. test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe)
  217. self.assertEqual(expected_recipe_summary, test_recipe_summary_after)