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/recipetool.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/recipetool.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/recipetool.py | 694 |
1 files changed, 694 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py new file mode 100644 index 0000000000..46f0a7206b --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/recipetool.py | |||
@@ -0,0 +1,694 @@ | |||
1 | import os | ||
2 | import shutil | ||
3 | import tempfile | ||
4 | import urllib.parse | ||
5 | |||
6 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | ||
7 | from oeqa.utils.commands import get_bb_vars, create_temp_layer | ||
8 | from oeqa.core.decorator.oeid import OETestID | ||
9 | from oeqa.selftest.cases import devtool | ||
10 | |||
11 | templayerdir = None | ||
12 | |||
13 | def setUpModule(): | ||
14 | global templayerdir | ||
15 | templayerdir = tempfile.mkdtemp(prefix='recipetoolqa') | ||
16 | create_temp_layer(templayerdir, 'selftestrecipetool') | ||
17 | runCmd('bitbake-layers add-layer %s' % templayerdir) | ||
18 | |||
19 | |||
20 | def tearDownModule(): | ||
21 | runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True) | ||
22 | runCmd('rm -rf %s' % templayerdir) | ||
23 | |||
24 | |||
25 | class RecipetoolBase(devtool.DevtoolBase): | ||
26 | |||
27 | def setUpLocal(self): | ||
28 | super(RecipetoolBase, self).setUpLocal() | ||
29 | self.templayerdir = templayerdir | ||
30 | self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa') | ||
31 | self.track_for_cleanup(self.tempdir) | ||
32 | self.testfile = os.path.join(self.tempdir, 'testfile') | ||
33 | with open(self.testfile, 'w') as f: | ||
34 | f.write('Test file\n') | ||
35 | |||
36 | def tearDownLocal(self): | ||
37 | runCmd('rm -rf %s/recipes-*' % self.templayerdir) | ||
38 | super(RecipetoolBase, self).tearDownLocal() | ||
39 | |||
40 | def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None): | ||
41 | result = runCmd(cmd) | ||
42 | self.assertNotIn('Traceback', result.output) | ||
43 | |||
44 | # Check the bbappend was created and applies properly | ||
45 | recipefile = get_bb_var('FILE', testrecipe) | ||
46 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) | ||
47 | |||
48 | # Check the bbappend contents | ||
49 | if expectedlines is not None: | ||
50 | with open(bbappendfile, 'r') as f: | ||
51 | self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile) | ||
52 | |||
53 | # Check file was copied | ||
54 | filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe) | ||
55 | for expectedfile in expectedfiles: | ||
56 | self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile) | ||
57 | |||
58 | # Check no other files created | ||
59 | createdfiles = [] | ||
60 | for root, _, files in os.walk(filesdir): | ||
61 | for f in files: | ||
62 | createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir)) | ||
63 | self.assertTrue(sorted(createdfiles), sorted(expectedfiles)) | ||
64 | |||
65 | return bbappendfile, result.output | ||
66 | |||
67 | |||
68 | class RecipetoolTests(RecipetoolBase): | ||
69 | |||
70 | @classmethod | ||
71 | def setUpClass(cls): | ||
72 | super(RecipetoolTests, cls).setUpClass() | ||
73 | # Ensure we have the right data in shlibs/pkgdata | ||
74 | cls.logger.info('Running bitbake to generate pkgdata') | ||
75 | bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile') | ||
76 | bb_vars = get_bb_vars(['COREBASE', 'BBPATH']) | ||
77 | cls.corebase = bb_vars['COREBASE'] | ||
78 | cls.bbpath = bb_vars['BBPATH'] | ||
79 | |||
80 | def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles): | ||
81 | cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options) | ||
82 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) | ||
83 | |||
84 | def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror): | ||
85 | cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile) | ||
86 | result = runCmd(cmd, ignore_status=True) | ||
87 | self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd) | ||
88 | self.assertNotIn('Traceback', result.output) | ||
89 | for errorstr in checkerror: | ||
90 | self.assertIn(errorstr, result.output) | ||
91 | |||
92 | @OETestID(1177) | ||
93 | def test_recipetool_appendfile_basic(self): | ||
94 | # Basic test | ||
95 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
96 | '\n'] | ||
97 | _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd']) | ||
98 | self.assertNotIn('WARNING: ', output) | ||
99 | |||
100 | @OETestID(1183) | ||
101 | def test_recipetool_appendfile_invalid(self): | ||
102 | # Test some commands that should error | ||
103 | self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers']) | ||
104 | self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool']) | ||
105 | self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool']) | ||
106 | |||
107 | @OETestID(1176) | ||
108 | def test_recipetool_appendfile_alternatives(self): | ||
109 | # Now try with a file we know should be an alternative | ||
110 | # (this is very much a fake example, but one we know is reliably an alternative) | ||
111 | self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox']) | ||
112 | # Need a test file - should be executable | ||
113 | testfile2 = os.path.join(self.corebase, 'oe-init-build-env') | ||
114 | testfile2name = os.path.basename(testfile2) | ||
115 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
116 | '\n', | ||
117 | 'SRC_URI += "file://%s"\n' % testfile2name, | ||
118 | '\n', | ||
119 | 'do_install_append() {\n', | ||
120 | ' install -d ${D}${base_bindir}\n', | ||
121 | ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name, | ||
122 | '}\n'] | ||
123 | self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name]) | ||
124 | # Now try bbappending the same file again, contents should not change | ||
125 | bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name]) | ||
126 | # But file should have | ||
127 | copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name) | ||
128 | result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True) | ||
129 | self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output) | ||
130 | |||
131 | @OETestID(1178) | ||
132 | def test_recipetool_appendfile_binary(self): | ||
133 | # Try appending a binary file | ||
134 | # /bin/ls can be a symlink to /usr/bin/ls | ||
135 | ls = os.path.realpath("/bin/ls") | ||
136 | result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls)) | ||
137 | self.assertIn('WARNING: ', result.output) | ||
138 | self.assertIn('is a binary', result.output) | ||
139 | |||
140 | @OETestID(1173) | ||
141 | def test_recipetool_appendfile_add(self): | ||
142 | # Try arbitrary file add to a recipe | ||
143 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
144 | '\n', | ||
145 | 'SRC_URI += "file://testfile"\n', | ||
146 | '\n', | ||
147 | 'do_install_append() {\n', | ||
148 | ' install -d ${D}${datadir}\n', | ||
149 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', | ||
150 | '}\n'] | ||
151 | self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile']) | ||
152 | # Try adding another file, this time where the source file is executable | ||
153 | # (so we're testing that, plus modifying an existing bbappend) | ||
154 | testfile2 = os.path.join(self.corebase, 'oe-init-build-env') | ||
155 | testfile2name = os.path.basename(testfile2) | ||
156 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
157 | '\n', | ||
158 | 'SRC_URI += "file://testfile \\\n', | ||
159 | ' file://%s \\\n' % testfile2name, | ||
160 | ' "\n', | ||
161 | '\n', | ||
162 | 'do_install_append() {\n', | ||
163 | ' install -d ${D}${datadir}\n', | ||
164 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', | ||
165 | ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name, | ||
166 | '}\n'] | ||
167 | self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name]) | ||
168 | |||
169 | @OETestID(1174) | ||
170 | def test_recipetool_appendfile_add_bindir(self): | ||
171 | # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable | ||
172 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
173 | '\n', | ||
174 | 'SRC_URI += "file://testfile"\n', | ||
175 | '\n', | ||
176 | 'do_install_append() {\n', | ||
177 | ' install -d ${D}${bindir}\n', | ||
178 | ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n', | ||
179 | '}\n'] | ||
180 | _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile']) | ||
181 | self.assertNotIn('WARNING: ', output) | ||
182 | |||
183 | @OETestID(1175) | ||
184 | def test_recipetool_appendfile_add_machine(self): | ||
185 | # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable | ||
186 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
187 | '\n', | ||
188 | 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n', | ||
189 | '\n', | ||
190 | 'SRC_URI_append_mymachine = " file://testfile"\n', | ||
191 | '\n', | ||
192 | 'do_install_append_mymachine() {\n', | ||
193 | ' install -d ${D}${datadir}\n', | ||
194 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', | ||
195 | '}\n'] | ||
196 | _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile']) | ||
197 | self.assertNotIn('WARNING: ', output) | ||
198 | |||
199 | @OETestID(1184) | ||
200 | def test_recipetool_appendfile_orig(self): | ||
201 | # A file that's in SRC_URI and in do_install with the same name | ||
202 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
203 | '\n'] | ||
204 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig']) | ||
205 | self.assertNotIn('WARNING: ', output) | ||
206 | |||
207 | @OETestID(1191) | ||
208 | def test_recipetool_appendfile_todir(self): | ||
209 | # A file that's in SRC_URI and in do_install with destination directory rather than file | ||
210 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
211 | '\n'] | ||
212 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir']) | ||
213 | self.assertNotIn('WARNING: ', output) | ||
214 | |||
215 | @OETestID(1187) | ||
216 | def test_recipetool_appendfile_renamed(self): | ||
217 | # A file that's in SRC_URI with a different name to the destination file | ||
218 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
219 | '\n'] | ||
220 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1']) | ||
221 | self.assertNotIn('WARNING: ', output) | ||
222 | |||
223 | @OETestID(1190) | ||
224 | def test_recipetool_appendfile_subdir(self): | ||
225 | # A file that's in SRC_URI in a subdir | ||
226 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
227 | '\n', | ||
228 | 'SRC_URI += "file://testfile"\n', | ||
229 | '\n', | ||
230 | 'do_install_append() {\n', | ||
231 | ' install -d ${D}${datadir}\n', | ||
232 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n', | ||
233 | '}\n'] | ||
234 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile']) | ||
235 | self.assertNotIn('WARNING: ', output) | ||
236 | |||
237 | @OETestID(1189) | ||
238 | def test_recipetool_appendfile_src_glob(self): | ||
239 | # A file that's in SRC_URI as a glob | ||
240 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
241 | '\n', | ||
242 | 'SRC_URI += "file://testfile"\n', | ||
243 | '\n', | ||
244 | 'do_install_append() {\n', | ||
245 | ' install -d ${D}${datadir}\n', | ||
246 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-src-globfile\n', | ||
247 | '}\n'] | ||
248 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-src-globfile', self.testfile, '', expectedlines, ['testfile']) | ||
249 | self.assertNotIn('WARNING: ', output) | ||
250 | |||
251 | @OETestID(1181) | ||
252 | def test_recipetool_appendfile_inst_glob(self): | ||
253 | # A file that's in do_install as a glob | ||
254 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
255 | '\n'] | ||
256 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile']) | ||
257 | self.assertNotIn('WARNING: ', output) | ||
258 | |||
259 | @OETestID(1182) | ||
260 | def test_recipetool_appendfile_inst_todir_glob(self): | ||
261 | # A file that's in do_install as a glob with destination as a directory | ||
262 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
263 | '\n'] | ||
264 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile']) | ||
265 | self.assertNotIn('WARNING: ', output) | ||
266 | |||
267 | @OETestID(1185) | ||
268 | def test_recipetool_appendfile_patch(self): | ||
269 | # A file that's added by a patch in SRC_URI | ||
270 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
271 | '\n', | ||
272 | 'SRC_URI += "file://testfile"\n', | ||
273 | '\n', | ||
274 | 'do_install_append() {\n', | ||
275 | ' install -d ${D}${sysconfdir}\n', | ||
276 | ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n', | ||
277 | '}\n'] | ||
278 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile']) | ||
279 | for line in output.splitlines(): | ||
280 | if 'WARNING: ' in line: | ||
281 | self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line) | ||
282 | break | ||
283 | else: | ||
284 | self.fail('Patch warning not found in output:\n%s' % output) | ||
285 | |||
286 | @OETestID(1188) | ||
287 | def test_recipetool_appendfile_script(self): | ||
288 | # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install) | ||
289 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
290 | '\n', | ||
291 | 'SRC_URI += "file://testfile"\n', | ||
292 | '\n', | ||
293 | 'do_install_append() {\n', | ||
294 | ' install -d ${D}${datadir}\n', | ||
295 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n', | ||
296 | '}\n'] | ||
297 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile']) | ||
298 | self.assertNotIn('WARNING: ', output) | ||
299 | |||
300 | @OETestID(1180) | ||
301 | def test_recipetool_appendfile_inst_func(self): | ||
302 | # A file that's installed from a function called by do_install | ||
303 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
304 | '\n'] | ||
305 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func']) | ||
306 | self.assertNotIn('WARNING: ', output) | ||
307 | |||
308 | @OETestID(1186) | ||
309 | def test_recipetool_appendfile_postinstall(self): | ||
310 | # A file that's created by a postinstall script (and explicitly mentioned in it) | ||
311 | # First try without specifying recipe | ||
312 | self._try_recipetool_appendfile_fail('/usr/share/selftest-replaceme-postinst', self.testfile, ['File /usr/share/selftest-replaceme-postinst may be written out in a pre/postinstall script of the following recipes:', 'selftest-recipetool-appendfile']) | ||
313 | # Now specify recipe | ||
314 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
315 | '\n', | ||
316 | 'SRC_URI += "file://testfile"\n', | ||
317 | '\n', | ||
318 | 'do_install_append() {\n', | ||
319 | ' install -d ${D}${datadir}\n', | ||
320 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n', | ||
321 | '}\n'] | ||
322 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile']) | ||
323 | |||
324 | @OETestID(1179) | ||
325 | def test_recipetool_appendfile_extlayer(self): | ||
326 | # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure | ||
327 | exttemplayerdir = os.path.join(self.tempdir, 'extlayer') | ||
328 | self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*') | ||
329 | result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile)) | ||
330 | self.assertNotIn('Traceback', result.output) | ||
331 | createdfiles = [] | ||
332 | for root, _, files in os.walk(exttemplayerdir): | ||
333 | for f in files: | ||
334 | createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir)) | ||
335 | createdfiles.remove('conf/layer.conf') | ||
336 | expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend', | ||
337 | 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig'] | ||
338 | self.assertEqual(sorted(createdfiles), sorted(expectedfiles)) | ||
339 | |||
340 | @OETestID(1192) | ||
341 | def test_recipetool_appendfile_wildcard(self): | ||
342 | |||
343 | def try_appendfile_wc(options): | ||
344 | result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options)) | ||
345 | self.assertNotIn('Traceback', result.output) | ||
346 | bbappendfile = None | ||
347 | for root, _, files in os.walk(self.templayerdir): | ||
348 | for f in files: | ||
349 | if f.endswith('.bbappend'): | ||
350 | bbappendfile = f | ||
351 | break | ||
352 | if not bbappendfile: | ||
353 | self.fail('No bbappend file created') | ||
354 | runCmd('rm -rf %s/recipes-*' % self.templayerdir) | ||
355 | return bbappendfile | ||
356 | |||
357 | # Check without wildcard option | ||
358 | recipefn = os.path.basename(get_bb_var('FILE', 'base-files')) | ||
359 | filename = try_appendfile_wc('') | ||
360 | self.assertEqual(filename, recipefn.replace('.bb', '.bbappend')) | ||
361 | # Now check with wildcard option | ||
362 | filename = try_appendfile_wc('-w') | ||
363 | self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend') | ||
364 | |||
365 | @OETestID(1193) | ||
366 | def test_recipetool_create(self): | ||
367 | # Try adding a recipe | ||
368 | tempsrc = os.path.join(self.tempdir, 'srctree') | ||
369 | os.makedirs(tempsrc) | ||
370 | recipefile = os.path.join(self.tempdir, 'logrotate_3.8.7.bb') | ||
371 | srcuri = 'https://github.com/logrotate/logrotate/archive/r3-8-7.tar.gz' | ||
372 | result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc)) | ||
373 | self.assertTrue(os.path.isfile(recipefile)) | ||
374 | checkvars = {} | ||
375 | checkvars['LICENSE'] = 'GPLv2' | ||
376 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=18810669f13b87348459e611d31ab760' | ||
377 | checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/archive/r3-8-7.tar.gz' | ||
378 | checkvars['SRC_URI[md5sum]'] = '6b1aa0e0d07eda3c9a2526520850397a' | ||
379 | checkvars['SRC_URI[sha256sum]'] = 'dece4bfeb9d8374a0ecafa34be139b5a697db5c926dcc69a9b8715431a22e733' | ||
380 | self._test_recipe_contents(recipefile, checkvars, []) | ||
381 | |||
382 | @OETestID(1194) | ||
383 | def test_recipetool_create_git(self): | ||
384 | if 'x11' not in get_bb_var('DISTRO_FEATURES'): | ||
385 | self.skipTest('Test requires x11 as distro feature') | ||
386 | # Ensure we have the right data in shlibs/pkgdata | ||
387 | bitbake('libpng pango libx11 libxext jpeg libcheck') | ||
388 | # Try adding a recipe | ||
389 | tempsrc = os.path.join(self.tempdir, 'srctree') | ||
390 | os.makedirs(tempsrc) | ||
391 | recipefile = os.path.join(self.tempdir, 'libmatchbox.bb') | ||
392 | srcuri = 'git://git.yoctoproject.org/libmatchbox' | ||
393 | result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc]) | ||
394 | self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output) | ||
395 | checkvars = {} | ||
396 | checkvars['LICENSE'] = 'LGPLv2.1' | ||
397 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34' | ||
398 | checkvars['S'] = '${WORKDIR}/git' | ||
399 | checkvars['PV'] = '1.11+git${SRCPV}' | ||
400 | checkvars['SRC_URI'] = srcuri | ||
401 | checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango']) | ||
402 | inherits = ['autotools', 'pkgconfig'] | ||
403 | self._test_recipe_contents(recipefile, checkvars, inherits) | ||
404 | |||
405 | @OETestID(1392) | ||
406 | def test_recipetool_create_simple(self): | ||
407 | # Try adding a recipe | ||
408 | temprecipe = os.path.join(self.tempdir, 'recipe') | ||
409 | os.makedirs(temprecipe) | ||
410 | pv = '1.7.3.0' | ||
411 | srcuri = 'http://www.dest-unreach.org/socat/download/socat-%s.tar.bz2' % pv | ||
412 | result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe)) | ||
413 | dirlist = os.listdir(temprecipe) | ||
414 | if len(dirlist) > 1: | ||
415 | self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist))) | ||
416 | if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])): | ||
417 | self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist))) | ||
418 | self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named') | ||
419 | checkvars = {} | ||
420 | checkvars['LICENSE'] = set(['Unknown', 'GPLv2']) | ||
421 | checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263']) | ||
422 | # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot | ||
423 | checkvars['S'] = None | ||
424 | checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}') | ||
425 | inherits = ['autotools'] | ||
426 | self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits) | ||
427 | |||
428 | @OETestID(1418) | ||
429 | def test_recipetool_create_cmake(self): | ||
430 | # Try adding a recipe | ||
431 | temprecipe = os.path.join(self.tempdir, 'recipe') | ||
432 | os.makedirs(temprecipe) | ||
433 | recipefile = os.path.join(temprecipe, 'navit_0.5.0.bb') | ||
434 | srcuri = 'http://downloads.sourceforge.net/project/navit/v0.5.0/navit-0.5.0.tar.gz' | ||
435 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) | ||
436 | self.assertTrue(os.path.isfile(recipefile)) | ||
437 | checkvars = {} | ||
438 | checkvars['LICENSE'] = set(['Unknown', 'GPLv2', 'LGPLv2']) | ||
439 | checkvars['SRC_URI'] = 'http://downloads.sourceforge.net/project/navit/v${PV}/navit-${PV}.tar.gz' | ||
440 | checkvars['SRC_URI[md5sum]'] = '242f398e979a6b8c0f3c802b63435b68' | ||
441 | checkvars['SRC_URI[sha256sum]'] = '13353481d7fc01a4f64e385dda460b51496366bba0fd2cc85a89a0747910e94d' | ||
442 | checkvars['DEPENDS'] = set(['freetype', 'zlib', 'openssl', 'glib-2.0', 'virtual/libgl', 'virtual/egl', 'gtk+', 'libpng', 'libsdl', 'freeglut', 'dbus-glib']) | ||
443 | inherits = ['cmake', 'python-dir', 'gettext', 'pkgconfig'] | ||
444 | self._test_recipe_contents(recipefile, checkvars, inherits) | ||
445 | |||
446 | def test_recipetool_create_github(self): | ||
447 | # Basic test to see if github URL mangling works | ||
448 | temprecipe = os.path.join(self.tempdir, 'recipe') | ||
449 | os.makedirs(temprecipe) | ||
450 | recipefile = os.path.join(temprecipe, 'meson_git.bb') | ||
451 | srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0' | ||
452 | result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri]) | ||
453 | self.assertTrue(os.path.isfile(recipefile)) | ||
454 | checkvars = {} | ||
455 | checkvars['LICENSE'] = set(['Apache-2.0']) | ||
456 | checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https' | ||
457 | inherits = ['setuptools'] | ||
458 | self._test_recipe_contents(recipefile, checkvars, inherits) | ||
459 | |||
460 | def test_recipetool_create_github_tarball(self): | ||
461 | # Basic test to ensure github URL mangling doesn't apply to release tarballs | ||
462 | temprecipe = os.path.join(self.tempdir, 'recipe') | ||
463 | os.makedirs(temprecipe) | ||
464 | pv = '0.32.0' | ||
465 | recipefile = os.path.join(temprecipe, 'meson_%s.bb' % pv) | ||
466 | srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv) | ||
467 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) | ||
468 | self.assertTrue(os.path.isfile(recipefile)) | ||
469 | checkvars = {} | ||
470 | checkvars['LICENSE'] = set(['Apache-2.0']) | ||
471 | checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz' | ||
472 | inherits = ['setuptools'] | ||
473 | self._test_recipe_contents(recipefile, checkvars, inherits) | ||
474 | |||
475 | def test_recipetool_create_git_http(self): | ||
476 | # Basic test to check http git URL mangling works | ||
477 | temprecipe = os.path.join(self.tempdir, 'recipe') | ||
478 | os.makedirs(temprecipe) | ||
479 | recipefile = os.path.join(temprecipe, 'matchbox-terminal_git.bb') | ||
480 | srcuri = 'http://git.yoctoproject.org/git/matchbox-terminal' | ||
481 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) | ||
482 | self.assertTrue(os.path.isfile(recipefile)) | ||
483 | checkvars = {} | ||
484 | checkvars['LICENSE'] = set(['GPLv2']) | ||
485 | checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/matchbox-terminal;protocol=http' | ||
486 | inherits = ['pkgconfig', 'autotools'] | ||
487 | self._test_recipe_contents(recipefile, checkvars, inherits) | ||
488 | |||
489 | def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths): | ||
490 | dstdir = basedstdir | ||
491 | self.assertTrue(os.path.exists(dstdir)) | ||
492 | for p in paths: | ||
493 | dstdir = os.path.join(dstdir, p) | ||
494 | if not os.path.exists(dstdir): | ||
495 | os.makedirs(dstdir) | ||
496 | self.track_for_cleanup(dstdir) | ||
497 | dstfile = os.path.join(dstdir, os.path.basename(srcfile)) | ||
498 | if srcfile != dstfile: | ||
499 | shutil.copy(srcfile, dstfile) | ||
500 | self.track_for_cleanup(dstfile) | ||
501 | |||
502 | def test_recipetool_load_plugin(self): | ||
503 | """Test that recipetool loads only the first found plugin in BBPATH.""" | ||
504 | |||
505 | recipetool = runCmd("which recipetool") | ||
506 | fromname = runCmd("recipetool --quiet pluginfile") | ||
507 | srcfile = fromname.output | ||
508 | searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)] | ||
509 | plugincontent = [] | ||
510 | with open(srcfile) as fh: | ||
511 | plugincontent = fh.readlines() | ||
512 | try: | ||
513 | self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found') | ||
514 | for path in searchpath: | ||
515 | self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool') | ||
516 | result = runCmd("recipetool --quiet count") | ||
517 | self.assertEqual(result.output, '1') | ||
518 | result = runCmd("recipetool --quiet multiloaded") | ||
519 | self.assertEqual(result.output, "no") | ||
520 | for path in searchpath: | ||
521 | result = runCmd("recipetool --quiet bbdir") | ||
522 | self.assertEqual(result.output, path) | ||
523 | os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py')) | ||
524 | finally: | ||
525 | with open(srcfile, 'w') as fh: | ||
526 | fh.writelines(plugincontent) | ||
527 | |||
528 | |||
529 | class RecipetoolAppendsrcBase(RecipetoolBase): | ||
530 | def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles): | ||
531 | cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile) | ||
532 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) | ||
533 | |||
534 | def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''): | ||
535 | |||
536 | if destdir: | ||
537 | options += ' -D %s' % destdir | ||
538 | |||
539 | if expectedfiles is None: | ||
540 | expectedfiles = [os.path.basename(f) for f in newfiles] | ||
541 | |||
542 | cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles)) | ||
543 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) | ||
544 | |||
545 | def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror): | ||
546 | cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '') | ||
547 | result = runCmd(cmd, ignore_status=True) | ||
548 | self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd) | ||
549 | self.assertNotIn('Traceback', result.output) | ||
550 | for errorstr in checkerror: | ||
551 | self.assertIn(errorstr, result.output) | ||
552 | |||
553 | @staticmethod | ||
554 | def _get_first_file_uri(recipe): | ||
555 | '''Return the first file:// in SRC_URI for the specified recipe.''' | ||
556 | src_uri = get_bb_var('SRC_URI', recipe).split() | ||
557 | for uri in src_uri: | ||
558 | p = urllib.parse.urlparse(uri) | ||
559 | if p.scheme == 'file': | ||
560 | return p.netloc + p.path | ||
561 | |||
562 | def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''): | ||
563 | if newfile is None: | ||
564 | newfile = self.testfile | ||
565 | |||
566 | if srcdir: | ||
567 | if destdir: | ||
568 | expected_subdir = os.path.join(srcdir, destdir) | ||
569 | else: | ||
570 | expected_subdir = srcdir | ||
571 | else: | ||
572 | options += " -W" | ||
573 | expected_subdir = destdir | ||
574 | |||
575 | if filename: | ||
576 | if destdir: | ||
577 | destpath = os.path.join(destdir, filename) | ||
578 | else: | ||
579 | destpath = filename | ||
580 | else: | ||
581 | filename = os.path.basename(newfile) | ||
582 | if destdir: | ||
583 | destpath = destdir + os.sep | ||
584 | else: | ||
585 | destpath = '.' + os.sep | ||
586 | |||
587 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
588 | '\n'] | ||
589 | if has_src_uri: | ||
590 | uri = 'file://%s' % filename | ||
591 | if expected_subdir: | ||
592 | uri += ';subdir=%s' % expected_subdir | ||
593 | expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri, | ||
594 | '\n'] | ||
595 | |||
596 | return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename]) | ||
597 | |||
598 | def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''): | ||
599 | if expectedfiles is None: | ||
600 | expectedfiles = [os.path.basename(n) for n in newfiles] | ||
601 | |||
602 | self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options) | ||
603 | |||
604 | bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe) | ||
605 | src_uri = bb_vars['SRC_URI'].split() | ||
606 | for f in expectedfiles: | ||
607 | if destdir: | ||
608 | self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri) | ||
609 | else: | ||
610 | self.assertIn('file://%s' % f, src_uri) | ||
611 | |||
612 | recipefile = bb_vars['FILE'] | ||
613 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) | ||
614 | filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe) | ||
615 | filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':') | ||
616 | self.assertIn(filesdir, filesextrapaths) | ||
617 | |||
618 | |||
619 | |||
620 | |||
621 | class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase): | ||
622 | |||
623 | @OETestID(1273) | ||
624 | def test_recipetool_appendsrcfile_basic(self): | ||
625 | self._test_appendsrcfile('base-files', 'a-file') | ||
626 | |||
627 | @OETestID(1274) | ||
628 | def test_recipetool_appendsrcfile_basic_wildcard(self): | ||
629 | testrecipe = 'base-files' | ||
630 | self._test_appendsrcfile(testrecipe, 'a-file', options='-w') | ||
631 | recipefile = get_bb_var('FILE', testrecipe) | ||
632 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) | ||
633 | self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe) | ||
634 | |||
635 | @OETestID(1281) | ||
636 | def test_recipetool_appendsrcfile_subdir_basic(self): | ||
637 | self._test_appendsrcfile('base-files', 'a-file', 'tmp') | ||
638 | |||
639 | @OETestID(1282) | ||
640 | def test_recipetool_appendsrcfile_subdir_basic_dirdest(self): | ||
641 | self._test_appendsrcfile('base-files', destdir='tmp') | ||
642 | |||
643 | @OETestID(1280) | ||
644 | def test_recipetool_appendsrcfile_srcdir_basic(self): | ||
645 | testrecipe = 'bash' | ||
646 | bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) | ||
647 | srcdir = bb_vars['S'] | ||
648 | workdir = bb_vars['WORKDIR'] | ||
649 | subdir = os.path.relpath(srcdir, workdir) | ||
650 | self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir) | ||
651 | |||
652 | @OETestID(1275) | ||
653 | def test_recipetool_appendsrcfile_existing_in_src_uri(self): | ||
654 | testrecipe = 'base-files' | ||
655 | filepath = self._get_first_file_uri(testrecipe) | ||
656 | self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) | ||
657 | self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False) | ||
658 | |||
659 | @OETestID(1276) | ||
660 | def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self): | ||
661 | testrecipe = 'base-files' | ||
662 | subdir = 'tmp' | ||
663 | filepath = self._get_first_file_uri(testrecipe) | ||
664 | self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) | ||
665 | |||
666 | output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False) | ||
667 | self.assertTrue(any('with different parameters' in l for l in output)) | ||
668 | |||
669 | @OETestID(1277) | ||
670 | def test_recipetool_appendsrcfile_replace_file_srcdir(self): | ||
671 | testrecipe = 'bash' | ||
672 | filepath = 'Makefile.in' | ||
673 | bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) | ||
674 | srcdir = bb_vars['S'] | ||
675 | workdir = bb_vars['WORKDIR'] | ||
676 | subdir = os.path.relpath(srcdir, workdir) | ||
677 | |||
678 | self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir) | ||
679 | bitbake('%s:do_unpack' % testrecipe) | ||
680 | self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read()) | ||
681 | |||
682 | @OETestID(1278) | ||
683 | def test_recipetool_appendsrcfiles_basic(self, destdir=None): | ||
684 | newfiles = [self.testfile] | ||
685 | for i in range(1, 5): | ||
686 | testfile = os.path.join(self.tempdir, 'testfile%d' % i) | ||
687 | with open(testfile, 'w') as f: | ||
688 | f.write('Test file %d\n' % i) | ||
689 | newfiles.append(testfile) | ||
690 | self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W') | ||
691 | |||
692 | @OETestID(1279) | ||
693 | def test_recipetool_appendsrcfiles_basic_subdir(self): | ||
694 | self.test_recipetool_appendsrcfiles_basic(destdir='testdir') | ||