blob: 17da0fd32c76c98087c702f31984f21ff51881f6 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import os
6import re
7
8import oeqa.utils.ftools as ftools
9from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
10
11from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
13class BitbakeTests(OESelftestTestCase):
14
15 def getline(self, res, line):
16 for l in res.output.split('\n'):
17 if line in l:
18 return l
19
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080020 # Test bitbake can run from the <builddir>/conf directory
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 def test_run_bitbake_from_dir_1(self):
22 os.chdir(os.path.join(self.builddir, 'conf'))
23 self.assertEqual(bitbake('-e').status, 0, msg = "bitbake couldn't run from \"conf\" dir")
24
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080025 # Test bitbake can run from the <builddir>'s parent directory
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026 def test_run_bitbake_from_dir_2(self):
27 my_env = os.environ.copy()
28 my_env['BBPATH'] = my_env['BUILDDIR']
29 os.chdir(os.path.dirname(os.environ['BUILDDIR']))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir's parent directory")
31
32 # Test bitbake can run from some other random system location (we use /tmp/)
33 def test_run_bitbake_from_dir_3(self):
34 my_env = os.environ.copy()
35 my_env['BBPATH'] = my_env['BUILDDIR']
36 os.chdir("/tmp/")
37 self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from /tmp/")
38
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039
Brad Bishopd7bf8c12018-02-25 22:55:05 -050040 def test_event_handler(self):
41 self.write_config("INHERIT += \"test_events\"")
42 result = bitbake('m4-native')
Brad Bishop96ff1982019-08-19 13:50:42 -040043 find_build_started = re.search(r"NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing.*Tasks", result.output)
Brad Bishop19323692019-04-05 15:28:33 -040044 find_build_completed = re.search(r"Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output)
46 self.assertTrue(find_build_completed, msg = "Match failed in:\n%s" % result.output)
47 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)
48
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 def test_local_sstate(self):
50 bitbake('m4-native')
51 bitbake('m4-native -cclean')
52 result = bitbake('m4-native')
53 find_setscene = re.search("m4-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 )
55
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056 def test_bitbake_invalid_recipe(self):
57 result = bitbake('-b asdf', ignore_status=True)
58 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)
59
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060 def test_bitbake_invalid_target(self):
61 result = bitbake('asdf', ignore_status=True)
62 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)
63
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064 def test_warnings_errors(self):
65 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)
67 find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output)
68 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)
70
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 def test_invalid_patch(self):
Brad Bishop316dfdd2018-06-25 12:45:53 -040072 # This patch should fail to apply.
73 self.write_recipeinc('man-db', 'FILESEXTRAPATHS_prepend := "${THISDIR}/files:"\nSRC_URI += "file://0001-Test-patch-here.patch"')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050074 self.write_config("INHERIT_remove = \"report-error\"")
Brad Bishop316dfdd2018-06-25 12:45:53 -040075 result = bitbake('man-db -c patch', ignore_status=True)
76 self.delete_recipeinc('man-db')
77 bitbake('-cclean man-db')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050078 line = self.getline(result, "Function failed: patch_do_patch")
Brad Bishop316dfdd2018-06-25 12:45:53 -040079 self.assertTrue(line and line.startswith("ERROR:"), msg = "Incorrectly formed patch application didn't fail. bitbake output: %s" % result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050080
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081 def test_force_task_1(self):
82 # test 1 from bug 5875
83 test_recipe = 'zlib'
84 test_data = "Microsoft Made No Profit From Anyone's Zunes Yo"
85 bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe)
86 image_dir = bb_vars['D']
87 pkgsplit_dir = bb_vars['PKGDEST']
88 man_dir = bb_vars['mandir']
89
90 bitbake('-c clean %s' % test_recipe)
91 bitbake('-c package -f %s' % test_recipe)
92 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
93
94 man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3')
95 ftools.append_file(man_file, test_data)
96 bitbake('-c package -f %s' % test_recipe)
97
98 man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3')
99 man_split_content = ftools.read_file(man_split_file)
100 self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.')
101
102 ret = bitbake(test_recipe)
103 self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.')
104
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500105 def test_force_task_2(self):
106 # test 2 from bug 5875
107 test_recipe = 'zlib'
108
109 bitbake(test_recipe)
110 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
111
112 result = bitbake('-C compile %s' % test_recipe)
113 look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:']
114 for task in look_for_tasks:
115 self.assertIn(task, result.output, msg="Couldn't find %s task.")
116
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500117 def test_bitbake_g(self):
118 result = bitbake('-g core-image-minimal')
119 for f in ['pn-buildlist', 'recipe-depends.dot', 'task-depends.dot']:
120 self.addCleanup(os.remove, f)
121 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)
122 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.")
123
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500124 def test_image_manifest(self):
125 bitbake('core-image-minimal')
126 bb_vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "IMAGE_LINK_NAME"], "core-image-minimal")
127 deploydir = bb_vars["DEPLOY_DIR_IMAGE"]
128 imagename = bb_vars["IMAGE_LINK_NAME"]
129 manifest = os.path.join(deploydir, imagename + ".manifest")
130 self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest)
131
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500132 def test_invalid_recipe_src_uri(self):
133 data = 'SRC_URI = "file://invalid"'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400134 self.write_recipeinc('man-db', data)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500135 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
136SSTATE_DIR = \"${TOPDIR}/download-selftest\"
137INHERIT_remove = \"report-error\"
138""")
139 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
140
Brad Bishop316dfdd2018-06-25 12:45:53 -0400141 bitbake('-ccleanall man-db')
142 result = bitbake('-c fetch man-db', ignore_status=True)
143 bitbake('-ccleanall man-db')
144 self.delete_recipeinc('man-db')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145 self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output)
146 self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \
147doesn't exist, yet no error message encountered. bitbake output: %s" % result.output)
148 line = self.getline(result, 'Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.')
149 self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \
150doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output)
151
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152 def test_rename_downloaded_file(self):
153 # TODO unique dldir instead of using cleanall
154 # TODO: need to set sstatedir?
155 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
156SSTATE_DIR = \"${TOPDIR}/download-selftest\"
157""")
158 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
159
160 data = 'SRC_URI = "${GNU_MIRROR}/aspell/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"'
161 self.write_recipeinc('aspell', data)
162 result = bitbake('-f -c fetch aspell', ignore_status=True)
163 self.delete_recipeinc('aspell')
164 self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output)
165 dl_dir = get_bb_var("DL_DIR")
166 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)
167 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)
168
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500169 def test_environment(self):
170 self.write_config("TEST_ENV=\"localconf\"")
171 result = runCmd('bitbake -e | grep TEST_ENV=')
172 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='")
173
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500174 def test_dry_run(self):
175 result = runCmd('bitbake -n m4-native')
176 self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output)
177
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500178 def test_just_parse(self):
179 result = runCmd('bitbake -p')
180 self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output)
181
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500182 def test_version(self):
183 result = runCmd('bitbake -s | grep wget')
Brad Bishop19323692019-04-05 15:28:33 -0400184 find = re.search(r"wget *:([0-9a-zA-Z\.\-]+)", result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500185 self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output)
186
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500187 def test_prefile(self):
188 preconf = os.path.join(self.builddir, 'conf/prefile.conf')
189 self.track_for_cleanup(preconf)
190 ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"")
191 result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
192 self.assertTrue('prefile' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration. ")
193 self.write_config("TEST_PREFILE=\"localconf\"")
194 result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
195 self.assertTrue('localconf' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration.")
196
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500197 def test_postfile(self):
198 postconf = os.path.join(self.builddir, 'conf/postfile.conf')
199 self.track_for_cleanup(postconf)
200 ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"")
201 self.write_config("TEST_POSTFILE=\"localconf\"")
202 result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=')
203 self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.")
204
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500205 def test_checkuri(self):
206 result = runCmd('bitbake -c checkuri m4')
207 self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output)
208
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500209 def test_continue(self):
210 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
211SSTATE_DIR = \"${TOPDIR}/download-selftest\"
212INHERIT_remove = \"report-error\"
213""")
214 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400215 self.write_recipeinc('man-db',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" )
216 runCmd('bitbake -c cleanall man-db xcursor-transparent-theme')
217 result = runCmd('bitbake -c unpack -k man-db xcursor-transparent-theme', ignore_status=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500218 errorpos = result.output.find('ERROR: Function failed: do_fail_task')
219 manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output)
220 continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1))
221 self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output)
222
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500223 def test_non_gplv3(self):
224 self.write_config('INCOMPATIBLE_LICENSE = "GPLv3"')
225 result = bitbake('selftest-ed', ignore_status=True)
226 self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
227 lic_dir = get_bb_var('LICENSE_DIRECTORY')
228 self.assertFalse(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv3')))
229 self.assertTrue(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv2')))
230
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500231 def test_setscene_only(self):
232 """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)"""
233 test_recipe = 'ed'
234
235 bitbake(test_recipe)
236 bitbake('-c clean %s' % test_recipe)
237 ret = bitbake('--setscene-only %s' % test_recipe)
238
239 tasks = re.findall(r'task\s+(do_\S+):', ret.output)
240
241 for task in tasks:
242 self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n'
243 'Executed tasks were: %s' % (task, str(tasks)))
244
Brad Bishop96ff1982019-08-19 13:50:42 -0400245 def test_skip_setscene(self):
246 test_recipe = 'ed'
247
248 bitbake(test_recipe)
249 bitbake('-c clean %s' % test_recipe)
250
251 ret = bitbake('--setscene-only %s' % test_recipe)
252 tasks = re.findall(r'task\s+(do_\S+):', ret.output)
253
254 for task in tasks:
255 self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n'
256 'Executed tasks were: %s' % (task, str(tasks)))
257
258 # Run without setscene. Should do nothing
259 ret = bitbake('--skip-setscene %s' % test_recipe)
260 tasks = re.findall(r'task\s+(do_\S+):', ret.output)
261
262 self.assertFalse(tasks, 'Tasks %s ran when they should not have' % (str(tasks)))
263
264 # Clean (leave sstate cache) and run with --skip-setscene. No setscene
265 # tasks should run
266 bitbake('-c clean %s' % test_recipe)
267
268 ret = bitbake('--skip-setscene %s' % test_recipe)
269 tasks = re.findall(r'task\s+(do_\S+):', ret.output)
270
271 for task in tasks:
272 self.assertNotIn('_setscene', task, 'A _setscene task ran: %s.\n'
273 'Executed tasks were: %s' % (task, str(tasks)))
274
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500275 def test_bbappend_order(self):
276 """ Bitbake should bbappend to recipe in a predictable order """
277 test_recipe = 'ed'
278 bb_vars = get_bb_vars(['SUMMARY', 'PV'], test_recipe)
279 test_recipe_summary_before = bb_vars['SUMMARY']
280 test_recipe_pv = bb_vars['PV']
281 recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend'
282 expected_recipe_summary = test_recipe_summary_before
283
284 for i in range(5):
285 recipe_append_dir = test_recipe + '_test_' + str(i)
286 recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file)
287 os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir))
288 feature = 'SUMMARY += "%s"\n' % i
289 ftools.write_file(recipe_append_path, feature)
290 expected_recipe_summary += ' %s' % i
291
292 self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test',
293 test_recipe + '_test_*'))
294
295 test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe)
296 self.assertEqual(expected_recipe_summary, test_recipe_summary_after)