blob: 94ca79c031db237c7bbd65fe8588c7261ca16240 [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
11 @testcase(789)
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
16 @testcase(790)
17 def test_run_bitbake_from_dir_2(self):
18 my_env = os.environ.copy()
19 my_env['BBPATH'] = my_env['BUILDDIR']
20 os.chdir(os.path.dirname(os.environ['BUILDDIR']))
21 self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir")
22
23 @testcase(806)
24 def test_event_handler(self):
25 self.write_config("INHERIT += \"test_events\"")
26 result = bitbake('m4-native')
27 find_build_started = re.search("NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Preparing RunQueue", result.output)
28 find_build_completed = re.search("Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output)
29 self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output)
30 self.assertTrue(find_build_completed, msg = "Match failed in:\n%s" % result.output)
31 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)
32
33 @testcase(103)
34 def test_local_sstate(self):
35 bitbake('m4-native -ccleansstate')
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
42 @testcase(105)
43 def test_bitbake_invalid_recipe(self):
44 result = bitbake('-b asdf', ignore_status=True)
45 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)
46
47 @testcase(107)
48 def test_bitbake_invalid_target(self):
49 result = bitbake('asdf', ignore_status=True)
50 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)
51
52 @testcase(106)
53 def test_warnings_errors(self):
54 result = bitbake('-b asdf', ignore_status=True)
55 find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages* shown", result.output)
56 find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output)
57 self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output)
58 self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output)
59
60 @testcase(108)
61 def test_invalid_patch(self):
62 self.write_recipeinc('man', 'SRC_URI += "file://man-1.5h1-make.patch"')
63 result = bitbake('man -c patch', ignore_status=True)
64 self.delete_recipeinc('man')
65 bitbake('-cclean man')
66 self.assertTrue("ERROR: Function failed: patch_do_patch" in result.output, msg = "Though no man-1.5h1-make.patch file exists, bitbake didn't output any err. message. bitbake output: %s" % result.output)
67
Patrick Williamsf1e5d692016-03-30 15:21:19 -050068 @testcase(1354)
69 def test_force_task_1(self):
70 # test 1 from bug 5875
71 test_recipe = 'zlib'
72 test_data = "Microsoft Made No Profit From Anyone's Zunes Yo"
73 image_dir = get_bb_var('D', test_recipe)
74 pkgsplit_dir = get_bb_var('PKGDEST', test_recipe)
75 man_dir = get_bb_var('mandir', test_recipe)
76
77 bitbake('-c cleansstate %s' % test_recipe)
78 bitbake(test_recipe)
79 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
80
81 man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3')
82 ftools.append_file(man_file, test_data)
83 bitbake('-c package -f %s' % test_recipe)
84
85 man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3')
86 man_split_content = ftools.read_file(man_split_file)
87 self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.')
88
89 ret = bitbake(test_recipe)
90 self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.')
91
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092 @testcase(163)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050093 def test_force_task_2(self):
94 # test 2 from bug 5875
95 test_recipe = 'zlib'
96
97 bitbake('-c cleansstate %s' % test_recipe)
98 bitbake(test_recipe)
99 self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe)
100
101 result = bitbake('-C compile %s' % test_recipe)
102 look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 for task in look_for_tasks:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500104 self.assertIn(task, result.output, msg="Couldn't find %s task.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105
106 @testcase(167)
107 def test_bitbake_g(self):
108 result = bitbake('-g core-image-full-cmdline')
109 for f in ['pn-buildlist', 'pn-depends.dot', 'package-depends.dot', 'task-depends.dot']:
110 self.addCleanup(os.remove, f)
111 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)
112 self.assertTrue('openssh' in ftools.read_file(os.path.join(self.builddir, 'pn-buildlist')), msg = "No \"openssh\" dependency found in pn-buildlist file.")
113
114 @testcase(899)
115 def test_image_manifest(self):
116 bitbake('core-image-minimal')
117 deploydir = get_bb_var("DEPLOY_DIR_IMAGE", target="core-image-minimal")
118 imagename = get_bb_var("IMAGE_LINK_NAME", target="core-image-minimal")
119 manifest = os.path.join(deploydir, imagename + ".manifest")
120 self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest)
121
122 @testcase(168)
123 def test_invalid_recipe_src_uri(self):
124 data = 'SRC_URI = "file://invalid"'
125 self.write_recipeinc('man', data)
126 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
127SSTATE_DIR = \"${TOPDIR}/download-selftest\"
128""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500129 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
130
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 bitbake('-ccleanall man')
132 result = bitbake('-c fetch man', ignore_status=True)
133 bitbake('-ccleanall man')
134 self.delete_recipeinc('man')
135 self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output)
136 self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \
137doesn't exist, yet no error message encountered. bitbake output: %s" % result.output)
138 self.assertTrue('ERROR: Function failed: Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.' in result.output, msg = "\"invalid\" file \
139doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output)
140
141 @testcase(171)
142 def test_rename_downloaded_file(self):
143 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
144SSTATE_DIR = \"${TOPDIR}/download-selftest\"
145""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500146 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
147
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 data = 'SRC_URI_append = ";downloadfilename=test-aspell.tar.gz"'
149 self.write_recipeinc('aspell', data)
150 bitbake('-ccleanall aspell')
151 result = bitbake('-c fetch aspell', ignore_status=True)
152 self.delete_recipeinc('aspell')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153 self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output)
154 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")))
155 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")))
156
157 @testcase(1028)
158 def test_environment(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500159 self.write_config("TEST_ENV=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 result = runCmd('bitbake -e | grep TEST_ENV=')
161 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='")
162
163 @testcase(1029)
164 def test_dry_run(self):
165 result = runCmd('bitbake -n m4-native')
166 self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output)
167
168 @testcase(1030)
169 def test_just_parse(self):
170 result = runCmd('bitbake -p')
171 self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output)
172
173 @testcase(1031)
174 def test_version(self):
175 result = runCmd('bitbake -s | grep wget')
176 find = re.search("wget *:([0-9a-zA-Z\.\-]+)", result.output)
177 self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output)
178
179 @testcase(1032)
180 def test_prefile(self):
181 preconf = os.path.join(self.builddir, 'conf/prefile.conf')
182 self.track_for_cleanup(preconf)
183 ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"")
184 result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
185 self.assertTrue('prefile' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration. ")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500186 self.write_config("TEST_PREFILE=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=')
188 self.assertTrue('localconf' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration.")
189
190 @testcase(1033)
191 def test_postfile(self):
192 postconf = os.path.join(self.builddir, 'conf/postfile.conf')
193 self.track_for_cleanup(postconf)
194 ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500195 self.write_config("TEST_POSTFILE=\"localconf\"")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196 result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=')
197 self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.")
198
199 @testcase(1034)
200 def test_checkuri(self):
201 result = runCmd('bitbake -c checkuri m4')
202 self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output)
203
204 @testcase(1035)
205 def test_continue(self):
206 self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\"
207SSTATE_DIR = \"${TOPDIR}/download-selftest\"
208""")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500209 self.track_for_cleanup(os.path.join(self.builddir, "download-selftest"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210 self.write_recipeinc('man',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" )
211 runCmd('bitbake -c cleanall man xcursor-transparent-theme')
212 result = runCmd('bitbake man xcursor-transparent-theme -k', ignore_status=True)
213 errorpos = result.output.find('ERROR: Function failed: do_fail_task')
214 manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output)
215 continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1))
216 self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output)
217
218 @testcase(1119)
219 def test_non_gplv3(self):
220 data = 'INCOMPATIBLE_LICENSE = "GPLv3"'
221 conf = os.path.join(self.builddir, 'conf/local.conf')
222 ftools.append_file(conf ,data)
223 self.addCleanup(ftools.remove_from_file, conf ,data)
224 result = bitbake('readline', ignore_status=True)
225 self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
226 self.assertFalse(os.path.isfile(os.path.join(self.builddir, 'tmp/deploy/licenses/readline/generic_GPLv3')))
227 self.assertTrue(os.path.isfile(os.path.join(self.builddir, 'tmp/deploy/licenses/readline/generic_GPLv2')))