summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/bbtests.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/bbtests.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/bbtests.py129
1 files changed, 103 insertions, 26 deletions
diff --git a/meta/lib/oeqa/selftest/cases/bbtests.py b/meta/lib/oeqa/selftest/cases/bbtests.py
index 79390acc0d..98e9f81661 100644
--- a/meta/lib/oeqa/selftest/cases/bbtests.py
+++ b/meta/lib/oeqa/selftest/cases/bbtests.py
@@ -1,4 +1,6 @@
1# 1#
2# Copyright OpenEmbedded Contributors
3#
2# SPDX-License-Identifier: MIT 4# SPDX-License-Identifier: MIT
3# 5#
4 6
@@ -39,7 +41,7 @@ class BitbakeTests(OESelftestTestCase):
39 41
40 def test_event_handler(self): 42 def test_event_handler(self):
41 self.write_config("INHERIT += \"test_events\"") 43 self.write_config("INHERIT += \"test_events\"")
42 result = bitbake('m4-native') 44 result = bitbake('selftest-hello-native')
43 find_build_started = re.search(r"NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing.*Tasks", result.output) 45 find_build_started = re.search(r"NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing.*Tasks", result.output)
44 find_build_completed = re.search(r"Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output) 46 find_build_completed = re.search(r"Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output)
45 self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output) 47 self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output)
@@ -47,11 +49,11 @@ class BitbakeTests(OESelftestTestCase):
47 self.assertNotIn('Test for bb.event.InvalidEvent', result.output) 49 self.assertNotIn('Test for bb.event.InvalidEvent', result.output)
48 50
49 def test_local_sstate(self): 51 def test_local_sstate(self):
50 bitbake('m4-native') 52 bitbake('selftest-hello-native')
51 bitbake('m4-native -cclean') 53 bitbake('selftest-hello-native -cclean')
52 result = bitbake('m4-native') 54 result = bitbake('selftest-hello-native')
53 find_setscene = re.search("m4-native.*do_.*_setscene", result.output) 55 find_setscene = re.search("selftest-hello-native.*do_.*_setscene", result.output)
54 self.assertTrue(find_setscene, msg = "No \"m4-native.*do_.*_setscene\" message found during bitbake m4-native. bitbake output: %s" % result.output ) 56 self.assertTrue(find_setscene, msg = "No \"selftest-hello-native.*do_.*_setscene\" message found during bitbake selftest-hello-native. bitbake output: %s" % result.output )
55 57
56 def test_bitbake_invalid_recipe(self): 58 def test_bitbake_invalid_recipe(self):
57 result = bitbake('-b asdf', ignore_status=True) 59 result = bitbake('-b asdf', ignore_status=True)
@@ -63,15 +65,15 @@ class BitbakeTests(OESelftestTestCase):
63 65
64 def test_warnings_errors(self): 66 def test_warnings_errors(self):
65 result = bitbake('-b asdf', ignore_status=True) 67 result = bitbake('-b asdf', ignore_status=True)
66 find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages* shown", result.output) 68 find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages*", result.output)
67 find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output) 69 find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages*", result.output)
68 self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output) 70 self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output)
69 self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output) 71 self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output)
70 72
71 def test_invalid_patch(self): 73 def test_invalid_patch(self):
72 # This patch should fail to apply. 74 # This patch should fail to apply.
73 self.write_recipeinc('man-db', 'FILESEXTRAPATHS_prepend := "${THISDIR}/files:"\nSRC_URI += "file://0001-Test-patch-here.patch"') 75 self.write_recipeinc('man-db', 'FILESEXTRAPATHS:prepend := "${THISDIR}/files:"\nSRC_URI += "file://0001-Test-patch-here.patch"')
74 self.write_config("INHERIT_remove = \"report-error\"") 76 self.write_config("INHERIT:remove = \"report-error\"")
75 result = bitbake('man-db -c patch', ignore_status=True) 77 result = bitbake('man-db -c patch', ignore_status=True)
76 self.delete_recipeinc('man-db') 78 self.delete_recipeinc('man-db')
77 bitbake('-cclean man-db') 79 bitbake('-cclean man-db')
@@ -83,8 +85,10 @@ class BitbakeTests(OESelftestTestCase):
83 85
84 def test_force_task_1(self): 86 def test_force_task_1(self):
85 # test 1 from bug 5875 87 # test 1 from bug 5875
88 import uuid
86 test_recipe = 'zlib' 89 test_recipe = 'zlib'
87 test_data = "Microsoft Made No Profit From Anyone's Zunes Yo" 90 # Need to use uuid otherwise hash equivlance would change the workflow
91 test_data = "Microsoft Made No Profit From Anyone's Zunes Yo %s" % uuid.uuid1()
88 bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe) 92 bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe)
89 image_dir = bb_vars['D'] 93 image_dir = bb_vars['D']
90 pkgsplit_dir = bb_vars['PKGDEST'] 94 pkgsplit_dir = bb_vars['PKGDEST']
@@ -139,19 +143,14 @@ class BitbakeTests(OESelftestTestCase):
139 self.write_recipeinc('man-db', data) 143 self.write_recipeinc('man-db', data)
140 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" 144 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
141SSTATE_DIR = \"${TOPDIR}/download-selftest\" 145SSTATE_DIR = \"${TOPDIR}/download-selftest\"
142INHERIT_remove = \"report-error\" 146INHERIT:remove = \"report-error\"
143""") 147""")
144 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) 148 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
145 149
146 bitbake('-ccleanall man-db')
147 result = bitbake('-c fetch man-db', ignore_status=True) 150 result = bitbake('-c fetch man-db', ignore_status=True)
148 bitbake('-ccleanall man-db')
149 self.delete_recipeinc('man-db') 151 self.delete_recipeinc('man-db')
150 self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output) 152 self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output)
151 self.assertIn('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:', result.output) 153 self.assertIn('Unable to get checksum for man-db SRC_URI entry invalid: file could not be found', result.output)
152 line = self.getline(result, 'Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.')
153 self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \
154doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output)
155 154
156 def test_rename_downloaded_file(self): 155 def test_rename_downloaded_file(self):
157 # TODO unique dldir instead of using cleanall 156 # TODO unique dldir instead of using cleanall
@@ -161,7 +160,7 @@ SSTATE_DIR = \"${TOPDIR}/download-selftest\"
161""") 160""")
162 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) 161 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
163 162
164 data = 'SRC_URI = "${GNU_MIRROR}/aspell/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"' 163 data = 'SRC_URI = "https://downloads.yoctoproject.org/mirror/sources/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"'
165 self.write_recipeinc('aspell', data) 164 self.write_recipeinc('aspell', data)
166 result = bitbake('-f -c fetch aspell', ignore_status=True) 165 result = bitbake('-f -c fetch aspell', ignore_status=True)
167 self.delete_recipeinc('aspell') 166 self.delete_recipeinc('aspell')
@@ -176,7 +175,7 @@ SSTATE_DIR = \"${TOPDIR}/download-selftest\"
176 self.assertIn('localconf', result.output) 175 self.assertIn('localconf', result.output)
177 176
178 def test_dry_run(self): 177 def test_dry_run(self):
179 result = runCmd('bitbake -n m4-native') 178 result = runCmd('bitbake -n selftest-hello-native')
180 self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output) 179 self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output)
181 180
182 def test_just_parse(self): 181 def test_just_parse(self):
@@ -189,6 +188,10 @@ SSTATE_DIR = \"${TOPDIR}/download-selftest\"
189 self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output) 188 self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output)
190 189
191 def test_prefile(self): 190 def test_prefile(self):
191 # Test when the prefile does not exist
192 result = runCmd('bitbake -r conf/prefile.conf', ignore_status=True)
193 self.assertEqual(1, result.status, "bitbake didn't error and should have when a specified prefile didn't exist: %s" % result.output)
194 # Test when the prefile exists
192 preconf = os.path.join(self.builddir, 'conf/prefile.conf') 195 preconf = os.path.join(self.builddir, 'conf/prefile.conf')
193 self.track_for_cleanup(preconf) 196 self.track_for_cleanup(preconf)
194 ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"") 197 ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"")
@@ -199,6 +202,10 @@ SSTATE_DIR = \"${TOPDIR}/download-selftest\"
199 self.assertIn('localconf', result.output) 202 self.assertIn('localconf', result.output)
200 203
201 def test_postfile(self): 204 def test_postfile(self):
205 # Test when the postfile does not exist
206 result = runCmd('bitbake -R conf/postfile.conf', ignore_status=True)
207 self.assertEqual(1, result.status, "bitbake didn't error and should have when a specified postfile didn't exist: %s" % result.output)
208 # Test when the postfile exists
202 postconf = os.path.join(self.builddir, 'conf/postfile.conf') 209 postconf = os.path.join(self.builddir, 'conf/postfile.conf')
203 self.track_for_cleanup(postconf) 210 self.track_for_cleanup(postconf)
204 ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"") 211 ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"")
@@ -213,7 +220,7 @@ SSTATE_DIR = \"${TOPDIR}/download-selftest\"
213 def test_continue(self): 220 def test_continue(self):
214 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" 221 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
215SSTATE_DIR = \"${TOPDIR}/download-selftest\" 222SSTATE_DIR = \"${TOPDIR}/download-selftest\"
216INHERIT_remove = \"report-error\" 223INHERIT:remove = \"report-error\"
217""") 224""")
218 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) 225 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
219 self.write_recipeinc('man-db',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" ) 226 self.write_recipeinc('man-db',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" )
@@ -225,16 +232,21 @@ INHERIT_remove = \"report-error\"
225 self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output) 232 self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output)
226 233
227 def test_non_gplv3(self): 234 def test_non_gplv3(self):
228 self.write_config('INCOMPATIBLE_LICENSE = "GPLv3"') 235 self.write_config('''INCOMPATIBLE_LICENSE = "GPL-3.0-or-later"
236require conf/distro/include/no-gplv3.inc
237''')
229 result = bitbake('selftest-ed', ignore_status=True) 238 result = bitbake('selftest-ed', ignore_status=True)
230 self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output)) 239 self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
231 lic_dir = get_bb_var('LICENSE_DIRECTORY') 240 lic_dir = get_bb_var('LICENSE_DIRECTORY')
232 self.assertFalse(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv3'))) 241 arch = get_bb_var('SSTATE_PKGARCH')
233 self.assertTrue(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv2'))) 242 filename = os.path.join(lic_dir, arch, 'selftest-ed', 'generic_GPL-3.0-or-later')
243 self.assertFalse(os.path.isfile(filename), msg="License file %s exists and shouldn't" % filename)
244 filename = os.path.join(lic_dir, arch, 'selftest-ed', 'generic_GPL-2.0-or-later')
245 self.assertTrue(os.path.isfile(filename), msg="License file %s doesn't exist" % filename)
234 246
235 def test_setscene_only(self): 247 def test_setscene_only(self):
236 """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)""" 248 """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)"""
237 test_recipe = 'ed' 249 test_recipe = 'selftest-hello-native'
238 250
239 bitbake(test_recipe) 251 bitbake(test_recipe)
240 bitbake('-c clean %s' % test_recipe) 252 bitbake('-c clean %s' % test_recipe)
@@ -247,7 +259,7 @@ INHERIT_remove = \"report-error\"
247 'Executed tasks were: %s' % (task, str(tasks))) 259 'Executed tasks were: %s' % (task, str(tasks)))
248 260
249 def test_skip_setscene(self): 261 def test_skip_setscene(self):
250 test_recipe = 'ed' 262 test_recipe = 'selftest-hello-native'
251 263
252 bitbake(test_recipe) 264 bitbake(test_recipe)
253 bitbake('-c clean %s' % test_recipe) 265 bitbake('-c clean %s' % test_recipe)
@@ -298,3 +310,68 @@ INHERIT_remove = \"report-error\"
298 310
299 test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe) 311 test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe)
300 self.assertEqual(expected_recipe_summary, test_recipe_summary_after) 312 self.assertEqual(expected_recipe_summary, test_recipe_summary_after)
313
314 def test_git_patchtool(self):
315 """ PATCHTOOL=git should work with non-git sources like tarballs
316 test recipe for the test must NOT containt git:// repository in SRC_URI
317 """
318 test_recipe = "man-db"
319 self.write_recipeinc(test_recipe, 'PATCHTOOL=\"git\"')
320 src = get_bb_var("SRC_URI",test_recipe)
321 gitscm = re.search("git://", src)
322 self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe))
323 result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
324 fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output)
325 self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"")
326 self.delete_recipeinc(test_recipe)
327 bitbake('-cclean {}'.format(test_recipe))
328
329 def test_git_patchtool2(self):
330 """ Test if PATCHTOOL=git works with git repo and doesn't reinitialize it
331 """
332 test_recipe = "gitrepotest"
333 src = get_bb_var("SRC_URI",test_recipe)
334 gitscm = re.search("git://", src)
335 self.assertTrue(gitscm, "test_git_patchtool pre-condition failed: {} test recipe doesn't contains git repo!".format(test_recipe))
336 result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
337 srcdir = get_bb_var('S', test_recipe)
338 result = runCmd("git log", cwd = srcdir)
339 self.assertFalse("bitbake_patching_started" in result.output, msg = "Repository has been reinitialized. {}".format(srcdir))
340 self.delete_recipeinc(test_recipe)
341 bitbake('-cclean {}'.format(test_recipe))
342
343
344 def test_git_unpack_nonetwork(self):
345 """
346 Test that a recipe with a floating tag that needs to be resolved upstream doesn't
347 access the network in a patch task run in a separate builld invocation
348 """
349
350 # Enable the recipe to float using a distro override
351 self.write_config("DISTROOVERRIDES .= \":gitunpack-enable-recipe\"")
352
353 bitbake('gitunpackoffline -c fetch')
354 bitbake('gitunpackoffline -c patch')
355
356 def test_git_unpack_nonetwork_fail(self):
357 """
358 Test that a recipe with a floating tag which doesn't call get_srcrev() in the fetcher
359 raises an error when the fetcher is called.
360 """
361
362 # Enable the recipe to float using a distro override
363 self.write_config("DISTROOVERRIDES .= \":gitunpack-enable-recipe\"")
364
365 result = bitbake('gitunpackoffline-fail -c fetch', ignore_status=True)
366 self.assertTrue(re.search("Recipe uses a floating tag/branch .* for repo .* without a fixed SRCREV yet doesn't call bb.fetch2.get_srcrev()", result.output), msg = "Recipe without PV set to SRCPV should have failed: %s" % result.output)
367
368 def test_unexpanded_variable_in_path(self):
369 """
370 Test that bitbake fails if directory contains unexpanded bitbake variable in the name
371 """
372 recipe_name = "gitunpackoffline"
373 self.write_config('PV:pn-gitunpackoffline:append = "+${UNDEFVAL}"')
374 result = bitbake('{}'.format(recipe_name), ignore_status=True)
375 self.assertGreater(result.status, 0, "Build should have failed if ${ is in the path")
376 self.assertTrue(re.search("ERROR: Directory name /.* contains unexpanded bitbake variable. This may cause build failures and WORKDIR polution",
377 result.output), msg = "mkdirhier with unexpanded variable should have failed: %s" % result.output)