blob: 26728a4b41240fffbf5ed663ee9d2a6138499e25 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import os
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002import re
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003
4import oeqa.utils.ftools as ftools
5from oeqa.selftest.base import oeSelfTest
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var
7from oeqa.utils.decorators import testcase
8
9class BitbakeTests(oeSelfTest):
10
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011 def getline(self, res, line):
12 for l in res.output.split('\n'):
13 if line in l:
14 return l
15
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016 @testcase(789)
17 def test_run_bitbake_from_dir_1(self):
18 os.chdir(os.path.join(self.builddir, 'conf'))
19 self.assertEqual(bitbake('-e').status, 0, msg = "bitbake couldn't run from \"conf\" dir")
20
21 @testcase(790)
22 def test_run_bitbake_from_dir_2(self):
23 my_env = os.environ.copy()
24 my_env['BBPATH'] = my_env['BUILDDIR']
25 os.chdir(os.path.dirname(os.environ['BUILDDIR']))
26 self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir")
27
28 @testcase(806)
29 def test_event_handler(self):
30 self.write_config("INHERIT += \"test_events\"")
31 result = bitbake('m4-native')
32 find_build_started = re.search("NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Preparing RunQueue", result.output)
33 find_build_completed = re.search("Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output)
34 self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output)
35 self.assertTrue(find_build_completed, msg = "Match failed in:\n%s" % result.output)
36 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)
37
38 @testcase(103)
39 def test_local_sstate(self):
40 bitbake('m4-native -ccleansstate')
41 bitbake('m4-native')
42 bitbake('m4-native -cclean')
43 result = bitbake('m4-native')
44 find_setscene = re.search("m4-native.*do_.*_setscene", result.output)
45 self.assertTrue(find_setscene, msg = "No \"m4-native.*do_.*_setscene\" message found during bitbake m4-native. bitbake output: %s" % result.output )
46
47 @testcase(105)
48 def test_bitbake_invalid_recipe(self):
49 result = bitbake('-b asdf', ignore_status=True)
50 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)
51
52 @testcase(107)
53 def test_bitbake_invalid_target(self):
54 result = bitbake('asdf', ignore_status=True)
55 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)
56
57 @testcase(106)
58 def test_warnings_errors(self):
59 result = bitbake('-b asdf', ignore_status=True)
60 find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages* shown", result.output)
61 find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output)
62 self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output)
63 self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output)
64
65 @testcase(108)
66 def test_invalid_patch(self):
67 self.write_recipeinc('man', 'SRC_URI += "file://man-1.5h1-make.patch"')
68 result = bitbake('man -c patch', ignore_status=True)
69 self.delete_recipeinc('man')
70 bitbake('-cclean man')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071 line = self.getline(result, "Function failed: patch_do_patch")
72 self.assertTrue(line and line.startswith("ERROR:"), msg = "Though no man-1.5h1-make.patch file exists, bitbake didn't output any err. message. bitbake output: %s" % result.output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
Patrick Williamsf1e5d692016-03-30 15:21:19 -050074 @testcase(1354)
75 def test_force_task_1(self):
76 # test 1 from bug 5875
77 test_recipe = 'zlib'
78 test_data = "Microsoft Made No Profit From Anyone's Zunes Yo"
79 image_dir = get_bb_var('D', test_recipe)
80 pkgsplit_dir = get_bb_var('PKGDEST', test_recipe)
81 man_dir = get_bb_var('mandir', test_recipe)
82
83 bitbake('-c cleansstate %s' % test_recipe)
84 bitbake(test_recipe)
85 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
86
87 man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3')
88 ftools.append_file(man_file, test_data)
89 bitbake('-c package -f %s' % test_recipe)
90
91 man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3')
92 man_split_content = ftools.read_file(man_split_file)
93 self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.')
94
95 ret = bitbake(test_recipe)
96 self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.')
97
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 @testcase(163)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050099 def test_force_task_2(self):
100 # test 2 from bug 5875
101 test_recipe = 'zlib'
102
103 bitbake('-c cleansstate %s' % test_recipe)
104 bitbake(test_recipe)
105 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
106
107 result = bitbake('-C compile %s' % test_recipe)
108 look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 for task in look_for_tasks:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500110 self.assertIn(task, result.output, msg="Couldn't find %s task.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
112 @testcase(167)
113 def test_bitbake_g(self):
114 result = bitbake('-g core-image-full-cmdline')
115 for f in ['pn-buildlist', 'pn-depends.dot', 'package-depends.dot', 'task-depends.dot']:
116 self.addCleanup(os.remove, f)
117 self.assertTrue('NOTE: PN build list saved to \'pn-buildlist\'' in result.output, msg = "No dependency \"pn-buildlist\" file was generated for the given task target. bitbake output: %s" % result.output)
118 self.assertTrue('openssh' in ftools.read_file(os.path.join(self.builddir, 'pn-buildlist')), msg = "No \"openssh\" dependency found in pn-buildlist file.")
119
120 @testcase(899)
121 def test_image_manifest(self):
122 bitbake('core-image-minimal')
123 deploydir = get_bb_var("DEPLOY_DIR_IMAGE", target="core-image-minimal")
124 imagename = get_bb_var("IMAGE_LINK_NAME", target="core-image-minimal")
125 manifest = os.path.join(deploydir, imagename + ".manifest")
126 self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest)
127
128 @testcase(168)
129 def test_invalid_recipe_src_uri(self):
130 data = 'SRC_URI = "file://invalid"'
131 self.write_recipeinc('man', data)
132 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
133SSTATE_DIR = \"${TOPDIR}/download-selftest\"
134""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500135 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
136
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 bitbake('-ccleanall man')
138 result = bitbake('-c fetch man', ignore_status=True)
139 bitbake('-ccleanall man')
140 self.delete_recipeinc('man')
141 self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output)
142 self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \
143doesn't exist, yet no error message encountered. bitbake output: %s" % result.output)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500144 line = self.getline(result, 'Function failed: Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.')
145 self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output)
147
148 @testcase(171)
149 def test_rename_downloaded_file(self):
150 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
151SSTATE_DIR = \"${TOPDIR}/download-selftest\"
152""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500153 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
154
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 data = 'SRC_URI_append = ";downloadfilename=test-aspell.tar.gz"'
156 self.write_recipeinc('aspell', data)
157 bitbake('-ccleanall aspell')
158 result = bitbake('-c fetch aspell', ignore_status=True)
159 self.delete_recipeinc('aspell')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output)
161 self.assertTrue(os.path.isfile(os.path.join(get_bb_var("DL_DIR"), 'test-aspell.tar.gz')), msg = "File rename failed. No corresponding test-aspell.tar.gz file found under %s" % str(get_bb_var("DL_DIR")))
162 self.assertTrue(os.path.isfile(os.path.join(get_bb_var("DL_DIR"), 'test-aspell.tar.gz.done')), "File rename failed. No corresponding test-aspell.tar.gz.done file found under %s" % str(get_bb_var("DL_DIR")))
163
164 @testcase(1028)
165 def test_environment(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500166 self.write_config("TEST_ENV=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167 result = runCmd('bitbake -e | grep TEST_ENV=')
168 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='")
169
170 @testcase(1029)
171 def test_dry_run(self):
172 result = runCmd('bitbake -n m4-native')
173 self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output)
174
175 @testcase(1030)
176 def test_just_parse(self):
177 result = runCmd('bitbake -p')
178 self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output)
179
180 @testcase(1031)
181 def test_version(self):
182 result = runCmd('bitbake -s | grep wget')
183 find = re.search("wget *:([0-9a-zA-Z\.\-]+)", result.output)
184 self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output)
185
186 @testcase(1032)
187 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. ")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500193 self.write_config("TEST_PREFILE=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194 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
197 @testcase(1033)
198 def test_postfile(self):
199 postconf = os.path.join(self.builddir, 'conf/postfile.conf')
200 self.track_for_cleanup(postconf)
201 ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500202 self.write_config("TEST_POSTFILE=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500203 result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=')
204 self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.")
205
206 @testcase(1034)
207 def test_checkuri(self):
208 result = runCmd('bitbake -c checkuri m4')
209 self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output)
210
211 @testcase(1035)
212 def test_continue(self):
213 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
214SSTATE_DIR = \"${TOPDIR}/download-selftest\"
215""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500216 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 self.write_recipeinc('man',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" )
218 runCmd('bitbake -c cleanall man xcursor-transparent-theme')
219 result = runCmd('bitbake man xcursor-transparent-theme -k', ignore_status=True)
220 errorpos = result.output.find('ERROR: Function failed: do_fail_task')
221 manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output)
222 continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1))
223 self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output)
224
225 @testcase(1119)
226 def test_non_gplv3(self):
227 data = 'INCOMPATIBLE_LICENSE = "GPLv3"'
228 conf = os.path.join(self.builddir, 'conf/local.conf')
229 ftools.append_file(conf ,data)
230 self.addCleanup(ftools.remove_from_file, conf ,data)
231 result = bitbake('readline', ignore_status=True)
232 self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
233 self.assertFalse(os.path.isfile(os.path.join(self.builddir, 'tmp/deploy/licenses/readline/generic_GPLv3')))
234 self.assertTrue(os.path.isfile(os.path.join(self.builddir, 'tmp/deploy/licenses/readline/generic_GPLv2')))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500235
236 @testcase(1422)
237 def test_setscene_only(self):
238 """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)"""
239 test_recipe = 'ed'
240
241 bitbake(test_recipe)
242 bitbake('-c clean %s' % test_recipe)
243 ret = bitbake('--setscene-only %s' % test_recipe)
244
245 tasks = re.findall(r'task\s+(do_\S+):', ret.output)
246
247 for task in tasks:
248 self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n'
249 'Executed tasks were: %s' % (task, str(tasks)))
250
251 @testcase(1425)
252 def test_bbappend_order(self):
253 """ Bitbake should bbappend to recipe in a predictable order """
254 test_recipe = 'ed'
255 test_recipe_summary_before = get_bb_var('SUMMARY', test_recipe)
256 test_recipe_pv = get_bb_var('PV', test_recipe)
257 recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend'
258 expected_recipe_summary = test_recipe_summary_before
259
260 for i in range(5):
261 recipe_append_dir = test_recipe + '_test_' + str(i)
262 recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file)
263 os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir))
264 feature = 'SUMMARY += "%s"\n' % i
265 ftools.write_file(recipe_append_path, feature)
266 expected_recipe_summary += ' %s' % i
267
268 self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test',
269 test_recipe + '_test_*'))
270
271 test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe)
272 self.assertEqual(expected_recipe_summary, test_recipe_summary_after)