blob: 4ce935fc1dc3fc512aaa5e90a2a969f28a4447f7 [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')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032 find_build_started = re.search("NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing RunQueue Tasks", result.output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 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):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 bitbake('m4-native')
41 bitbake('m4-native -cclean')
42 result = bitbake('m4-native')
43 find_setscene = re.search("m4-native.*do_.*_setscene", result.output)
44 self.assertTrue(find_setscene, msg = "No \"m4-native.*do_.*_setscene\" message found during bitbake m4-native. bitbake output: %s" % result.output )
45
46 @testcase(105)
47 def test_bitbake_invalid_recipe(self):
48 result = bitbake('-b asdf', ignore_status=True)
49 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)
50
51 @testcase(107)
52 def test_bitbake_invalid_target(self):
53 result = bitbake('asdf', ignore_status=True)
54 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)
55
56 @testcase(106)
57 def test_warnings_errors(self):
58 result = bitbake('-b asdf', ignore_status=True)
59 find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages* shown", result.output)
60 find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output)
61 self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output)
62 self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output)
63
64 @testcase(108)
65 def test_invalid_patch(self):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060066 # This patch already exists in SRC_URI so adding it again will cause the
67 # patch to fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 self.write_recipeinc('man', 'SRC_URI += "file://man-1.5h1-make.patch"')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069 self.write_config("INHERIT_remove = \"report-error\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 result = bitbake('man -c patch', ignore_status=True)
71 self.delete_recipeinc('man')
72 bitbake('-cclean man')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050073 line = self.getline(result, "Function failed: patch_do_patch")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 self.assertTrue(line and line.startswith("ERROR:"), msg = "Repeated patch application didn't fail. bitbake output: %s" % result.output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075
Patrick Williamsf1e5d692016-03-30 15:21:19 -050076 @testcase(1354)
77 def test_force_task_1(self):
78 # test 1 from bug 5875
79 test_recipe = 'zlib'
80 test_data = "Microsoft Made No Profit From Anyone's Zunes Yo"
81 image_dir = get_bb_var('D', test_recipe)
82 pkgsplit_dir = get_bb_var('PKGDEST', test_recipe)
83 man_dir = get_bb_var('mandir', test_recipe)
84
Brad Bishop37a0e4d2017-12-04 01:01:44 -050085 bitbake('-c clean %s' % test_recipe)
86 bitbake('-c package -f %s' % test_recipe)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050087 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
88
89 man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3')
90 ftools.append_file(man_file, test_data)
91 bitbake('-c package -f %s' % test_recipe)
92
93 man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3')
94 man_split_content = ftools.read_file(man_split_file)
95 self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.')
96
97 ret = bitbake(test_recipe)
98 self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.')
99
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 @testcase(163)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500101 def test_force_task_2(self):
102 # test 2 from bug 5875
103 test_recipe = 'zlib'
104
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500105 bitbake(test_recipe)
106 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
107
108 result = bitbake('-C compile %s' % test_recipe)
109 look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 for task in look_for_tasks:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500111 self.assertIn(task, result.output, msg="Couldn't find %s task.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112
113 @testcase(167)
114 def test_bitbake_g(self):
115 result = bitbake('-g core-image-full-cmdline')
116 for f in ['pn-buildlist', 'pn-depends.dot', 'package-depends.dot', 'task-depends.dot']:
117 self.addCleanup(os.remove, f)
118 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)
119 self.assertTrue('openssh' in ftools.read_file(os.path.join(self.builddir, 'pn-buildlist')), msg = "No \"openssh\" dependency found in pn-buildlist file.")
120
121 @testcase(899)
122 def test_image_manifest(self):
123 bitbake('core-image-minimal')
124 deploydir = get_bb_var("DEPLOY_DIR_IMAGE", target="core-image-minimal")
125 imagename = get_bb_var("IMAGE_LINK_NAME", target="core-image-minimal")
126 manifest = os.path.join(deploydir, imagename + ".manifest")
127 self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest)
128
129 @testcase(168)
130 def test_invalid_recipe_src_uri(self):
131 data = 'SRC_URI = "file://invalid"'
132 self.write_recipeinc('man', data)
133 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
134SSTATE_DIR = \"${TOPDIR}/download-selftest\"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600135INHERIT_remove = \"report-error\"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500137 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
138
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 bitbake('-ccleanall man')
140 result = bitbake('-c fetch man', ignore_status=True)
141 bitbake('-ccleanall man')
142 self.delete_recipeinc('man')
143 self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output)
144 self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \
145doesn't exist, yet no error message encountered. bitbake output: %s" % result.output)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600146 line = self.getline(result, 'Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500147 self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output)
149
150 @testcase(171)
151 def test_rename_downloaded_file(self):
152 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
153SSTATE_DIR = \"${TOPDIR}/download-selftest\"
154""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500155 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
156
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 data = 'SRC_URI_append = ";downloadfilename=test-aspell.tar.gz"'
158 self.write_recipeinc('aspell', data)
159 bitbake('-ccleanall aspell')
160 result = bitbake('-c fetch aspell', ignore_status=True)
161 self.delete_recipeinc('aspell')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output)
163 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")))
164 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")))
165
166 @testcase(1028)
167 def test_environment(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500168 self.write_config("TEST_ENV=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169 result = runCmd('bitbake -e | grep TEST_ENV=')
170 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='")
171
172 @testcase(1029)
173 def test_dry_run(self):
174 result = runCmd('bitbake -n m4-native')
175 self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output)
176
177 @testcase(1030)
178 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
182 @testcase(1031)
183 def test_version(self):
184 result = runCmd('bitbake -s | grep wget')
185 find = re.search("wget *:([0-9a-zA-Z\.\-]+)", result.output)
186 self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output)
187
188 @testcase(1032)
189 def test_prefile(self):
190 preconf = os.path.join(self.builddir, 'conf/prefile.conf')
191 self.track_for_cleanup(preconf)
192 ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"")
193 result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
194 self.assertTrue('prefile' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration. ")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500195 self.write_config("TEST_PREFILE=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196 result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
197 self.assertTrue('localconf' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration.")
198
199 @testcase(1033)
200 def test_postfile(self):
201 postconf = os.path.join(self.builddir, 'conf/postfile.conf')
202 self.track_for_cleanup(postconf)
203 ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500204 self.write_config("TEST_POSTFILE=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205 result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=')
206 self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.")
207
208 @testcase(1034)
209 def test_checkuri(self):
210 result = runCmd('bitbake -c checkuri m4')
211 self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output)
212
213 @testcase(1035)
214 def test_continue(self):
215 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
216SSTATE_DIR = \"${TOPDIR}/download-selftest\"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600217INHERIT_remove = \"report-error\"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500219 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 self.write_recipeinc('man',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" )
221 runCmd('bitbake -c cleanall man xcursor-transparent-theme')
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500222 result = runCmd('bitbake -c unpack -k man xcursor-transparent-theme', ignore_status=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223 errorpos = result.output.find('ERROR: Function failed: do_fail_task')
224 manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output)
225 continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1))
226 self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output)
227
228 @testcase(1119)
229 def test_non_gplv3(self):
230 data = 'INCOMPATIBLE_LICENSE = "GPLv3"'
231 conf = os.path.join(self.builddir, 'conf/local.conf')
232 ftools.append_file(conf ,data)
233 self.addCleanup(ftools.remove_from_file, conf ,data)
234 result = bitbake('readline', ignore_status=True)
235 self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
236 self.assertFalse(os.path.isfile(os.path.join(self.builddir, 'tmp/deploy/licenses/readline/generic_GPLv3')))
237 self.assertTrue(os.path.isfile(os.path.join(self.builddir, 'tmp/deploy/licenses/readline/generic_GPLv2')))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500238
239 @testcase(1422)
240 def test_setscene_only(self):
241 """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)"""
242 test_recipe = 'ed'
243
244 bitbake(test_recipe)
245 bitbake('-c clean %s' % test_recipe)
246 ret = bitbake('--setscene-only %s' % test_recipe)
247
248 tasks = re.findall(r'task\s+(do_\S+):', ret.output)
249
250 for task in tasks:
251 self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n'
252 'Executed tasks were: %s' % (task, str(tasks)))
253
254 @testcase(1425)
255 def test_bbappend_order(self):
256 """ Bitbake should bbappend to recipe in a predictable order """
257 test_recipe = 'ed'
258 test_recipe_summary_before = get_bb_var('SUMMARY', test_recipe)
259 test_recipe_pv = get_bb_var('PV', test_recipe)
260 recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend'
261 expected_recipe_summary = test_recipe_summary_before
262
263 for i in range(5):
264 recipe_append_dir = test_recipe + '_test_' + str(i)
265 recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file)
266 os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir))
267 feature = 'SUMMARY += "%s"\n' % i
268 ftools.write_file(recipe_append_path, feature)
269 expected_recipe_summary += ' %s' % i
270
271 self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test',
272 test_recipe + '_test_*'))
273
274 test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe)
275 self.assertEqual(expected_recipe_summary, test_recipe_summary_after)