diff options
author | Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | 2017-05-12 14:40:21 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-06 19:02:43 +0100 |
commit | 157c3be2ca93f076033f725ec1ee912df91f7488 (patch) | |
tree | 8ef896ff7adf78d63b34059cd5b017a4f0a3419a /meta/lib/oeqa/selftest/cases/bbtests.py | |
parent | 10c512b60d1167122b5fe778b93838dca3def717 (diff) | |
download | poky-157c3be2ca93f076033f725ec1ee912df91f7488.tar.gz |
oeqa/selftest/cases: Migrate test cases into the new oe-qa framework
New framework has different classes/decorators so adapt current test cases to
support these. Changes include changes on base classes and decorators.
Also include paths in selftest/__init__.py isn't needed because the
loader is the standard unittest one.
(From OE-Core rev: ddbbefdd124604d10bd47dd0266b55a764fcc0ab)
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/bbtests.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/bbtests.py | 279 |
1 files changed, 279 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/bbtests.py b/meta/lib/oeqa/selftest/cases/bbtests.py new file mode 100644 index 0000000000..4c82049032 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/bbtests.py | |||
@@ -0,0 +1,279 @@ | |||
1 | import os | ||
2 | import re | ||
3 | |||
4 | import oeqa.utils.ftools as ftools | ||
5 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
6 | |||
7 | from oeqa.selftest.case import OESelftestTestCase | ||
8 | from oeqa.core.decorator.oeid import OETestID | ||
9 | |||
10 | class BitbakeTests(OESelftestTestCase): | ||
11 | |||
12 | def getline(self, res, line): | ||
13 | for l in res.output.split('\n'): | ||
14 | if line in l: | ||
15 | return l | ||
16 | |||
17 | @OETestID(789) | ||
18 | def test_run_bitbake_from_dir_1(self): | ||
19 | os.chdir(os.path.join(self.builddir, 'conf')) | ||
20 | self.assertEqual(bitbake('-e').status, 0, msg = "bitbake couldn't run from \"conf\" dir") | ||
21 | |||
22 | @OETestID(790) | ||
23 | def test_run_bitbake_from_dir_2(self): | ||
24 | my_env = os.environ.copy() | ||
25 | my_env['BBPATH'] = my_env['BUILDDIR'] | ||
26 | os.chdir(os.path.dirname(os.environ['BUILDDIR'])) | ||
27 | self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir") | ||
28 | |||
29 | @OETestID(806) | ||
30 | def test_event_handler(self): | ||
31 | self.write_config("INHERIT += \"test_events\"") | ||
32 | result = bitbake('m4-native') | ||
33 | find_build_started = re.search("NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing RunQueue Tasks", result.output) | ||
34 | find_build_completed = re.search("Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output) | ||
35 | self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output) | ||
36 | self.assertTrue(find_build_completed, msg = "Match failed in:\n%s" % result.output) | ||
37 | 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) | ||
38 | |||
39 | @OETestID(103) | ||
40 | def test_local_sstate(self): | ||
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 | @OETestID(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 | @OETestID(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 | @OETestID(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 | @OETestID(108) | ||
66 | def test_invalid_patch(self): | ||
67 | # This patch already exists in SRC_URI so adding it again will cause the | ||
68 | # patch to fail. | ||
69 | self.write_recipeinc('man', 'SRC_URI += "file://man-1.5h1-make.patch"') | ||
70 | self.write_config("INHERIT_remove = \"report-error\"") | ||
71 | result = bitbake('man -c patch', ignore_status=True) | ||
72 | self.delete_recipeinc('man') | ||
73 | bitbake('-cclean man') | ||
74 | line = self.getline(result, "Function failed: patch_do_patch") | ||
75 | self.assertTrue(line and line.startswith("ERROR:"), msg = "Repeated patch application didn't fail. bitbake output: %s" % result.output) | ||
76 | |||
77 | @OETestID(1354) | ||
78 | def test_force_task_1(self): | ||
79 | # test 1 from bug 5875 | ||
80 | test_recipe = 'zlib' | ||
81 | test_data = "Microsoft Made No Profit From Anyone's Zunes Yo" | ||
82 | bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe) | ||
83 | image_dir = bb_vars['D'] | ||
84 | pkgsplit_dir = bb_vars['PKGDEST'] | ||
85 | man_dir = bb_vars['mandir'] | ||
86 | |||
87 | bitbake('-c clean %s' % test_recipe) | ||
88 | bitbake('-c package -f %s' % test_recipe) | ||
89 | self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe) | ||
90 | |||
91 | man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3') | ||
92 | ftools.append_file(man_file, test_data) | ||
93 | bitbake('-c package -f %s' % test_recipe) | ||
94 | |||
95 | man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3') | ||
96 | man_split_content = ftools.read_file(man_split_file) | ||
97 | self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.') | ||
98 | |||
99 | ret = bitbake(test_recipe) | ||
100 | self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.') | ||
101 | |||
102 | @OETestID(163) | ||
103 | def test_force_task_2(self): | ||
104 | # test 2 from bug 5875 | ||
105 | test_recipe = 'zlib' | ||
106 | |||
107 | bitbake(test_recipe) | ||
108 | self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe) | ||
109 | |||
110 | result = bitbake('-C compile %s' % test_recipe) | ||
111 | look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:'] | ||
112 | for task in look_for_tasks: | ||
113 | self.assertIn(task, result.output, msg="Couldn't find %s task.") | ||
114 | |||
115 | @OETestID(167) | ||
116 | def test_bitbake_g(self): | ||
117 | result = bitbake('-g core-image-minimal') | ||
118 | for f in ['pn-buildlist', 'recipe-depends.dot', 'task-depends.dot']: | ||
119 | self.addCleanup(os.remove, f) | ||
120 | 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) | ||
121 | 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.") | ||
122 | |||
123 | @OETestID(899) | ||
124 | 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 | |||
132 | @OETestID(168) | ||
133 | def test_invalid_recipe_src_uri(self): | ||
134 | data = 'SRC_URI = "file://invalid"' | ||
135 | self.write_recipeinc('man', data) | ||
136 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" | ||
137 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" | ||
138 | INHERIT_remove = \"report-error\" | ||
139 | """) | ||
140 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) | ||
141 | |||
142 | bitbake('-ccleanall man') | ||
143 | result = bitbake('-c fetch man', ignore_status=True) | ||
144 | bitbake('-ccleanall man') | ||
145 | self.delete_recipeinc('man') | ||
146 | self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output) | ||
147 | self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \ | ||
148 | doesn't exist, yet no error message encountered. bitbake output: %s" % result.output) | ||
149 | line = self.getline(result, 'Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.') | ||
150 | self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \ | ||
151 | doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output) | ||
152 | |||
153 | @OETestID(171) | ||
154 | def test_rename_downloaded_file(self): | ||
155 | # TODO unique dldir instead of using cleanall | ||
156 | # TODO: need to set sstatedir? | ||
157 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" | ||
158 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" | ||
159 | """) | ||
160 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) | ||
161 | |||
162 | data = 'SRC_URI = "${GNU_MIRROR}/aspell/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"' | ||
163 | self.write_recipeinc('aspell', data) | ||
164 | result = bitbake('-f -c fetch aspell', ignore_status=True) | ||
165 | self.delete_recipeinc('aspell') | ||
166 | self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output) | ||
167 | dl_dir = get_bb_var("DL_DIR") | ||
168 | 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) | ||
169 | 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) | ||
170 | |||
171 | @OETestID(1028) | ||
172 | def test_environment(self): | ||
173 | self.write_config("TEST_ENV=\"localconf\"") | ||
174 | result = runCmd('bitbake -e | grep TEST_ENV=') | ||
175 | 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='") | ||
176 | |||
177 | @OETestID(1029) | ||
178 | def test_dry_run(self): | ||
179 | result = runCmd('bitbake -n m4-native') | ||
180 | self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output) | ||
181 | |||
182 | @OETestID(1030) | ||
183 | def test_just_parse(self): | ||
184 | result = runCmd('bitbake -p') | ||
185 | self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output) | ||
186 | |||
187 | @OETestID(1031) | ||
188 | def test_version(self): | ||
189 | result = runCmd('bitbake -s | grep wget') | ||
190 | find = re.search("wget *:([0-9a-zA-Z\.\-]+)", result.output) | ||
191 | self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output) | ||
192 | |||
193 | @OETestID(1032) | ||
194 | def test_prefile(self): | ||
195 | preconf = os.path.join(self.builddir, 'conf/prefile.conf') | ||
196 | self.track_for_cleanup(preconf) | ||
197 | ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"") | ||
198 | result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=') | ||
199 | self.assertTrue('prefile' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration. ") | ||
200 | self.write_config("TEST_PREFILE=\"localconf\"") | ||
201 | result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=') | ||
202 | self.assertTrue('localconf' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration.") | ||
203 | |||
204 | @OETestID(1033) | ||
205 | def test_postfile(self): | ||
206 | postconf = os.path.join(self.builddir, 'conf/postfile.conf') | ||
207 | self.track_for_cleanup(postconf) | ||
208 | ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"") | ||
209 | self.write_config("TEST_POSTFILE=\"localconf\"") | ||
210 | result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=') | ||
211 | self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.") | ||
212 | |||
213 | @OETestID(1034) | ||
214 | def test_checkuri(self): | ||
215 | result = runCmd('bitbake -c checkuri m4') | ||
216 | self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output) | ||
217 | |||
218 | @OETestID(1035) | ||
219 | def test_continue(self): | ||
220 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" | ||
221 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" | ||
222 | INHERIT_remove = \"report-error\" | ||
223 | """) | ||
224 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) | ||
225 | self.write_recipeinc('man',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" ) | ||
226 | runCmd('bitbake -c cleanall man xcursor-transparent-theme') | ||
227 | result = runCmd('bitbake -c unpack -k man xcursor-transparent-theme', ignore_status=True) | ||
228 | errorpos = result.output.find('ERROR: Function failed: do_fail_task') | ||
229 | manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output) | ||
230 | continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1)) | ||
231 | self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output) | ||
232 | |||
233 | @OETestID(1119) | ||
234 | def test_non_gplv3(self): | ||
235 | self.write_config('INCOMPATIBLE_LICENSE = "GPLv3"') | ||
236 | result = bitbake('selftest-ed', ignore_status=True) | ||
237 | self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output)) | ||
238 | lic_dir = get_bb_var('LICENSE_DIRECTORY') | ||
239 | self.assertFalse(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv3'))) | ||
240 | self.assertTrue(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv2'))) | ||
241 | |||
242 | @OETestID(1422) | ||
243 | def test_setscene_only(self): | ||
244 | """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)""" | ||
245 | test_recipe = 'ed' | ||
246 | |||
247 | bitbake(test_recipe) | ||
248 | bitbake('-c clean %s' % test_recipe) | ||
249 | ret = bitbake('--setscene-only %s' % test_recipe) | ||
250 | |||
251 | tasks = re.findall(r'task\s+(do_\S+):', ret.output) | ||
252 | |||
253 | for task in tasks: | ||
254 | self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n' | ||
255 | 'Executed tasks were: %s' % (task, str(tasks))) | ||
256 | |||
257 | @OETestID(1425) | ||
258 | def test_bbappend_order(self): | ||
259 | """ Bitbake should bbappend to recipe in a predictable order """ | ||
260 | test_recipe = 'ed' | ||
261 | bb_vars = get_bb_vars(['SUMMARY', 'PV'], test_recipe) | ||
262 | test_recipe_summary_before = bb_vars['SUMMARY'] | ||
263 | test_recipe_pv = bb_vars['PV'] | ||
264 | recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend' | ||
265 | expected_recipe_summary = test_recipe_summary_before | ||
266 | |||
267 | for i in range(5): | ||
268 | recipe_append_dir = test_recipe + '_test_' + str(i) | ||
269 | recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file) | ||
270 | os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir)) | ||
271 | feature = 'SUMMARY += "%s"\n' % i | ||
272 | ftools.write_file(recipe_append_path, feature) | ||
273 | expected_recipe_summary += ' %s' % i | ||
274 | |||
275 | self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test', | ||
276 | test_recipe + '_test_*')) | ||
277 | |||
278 | test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe) | ||
279 | self.assertEqual(expected_recipe_summary, test_recipe_summary_after) | ||