summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2015-07-16 12:36:28 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-27 23:29:13 +0100
commit7eb55b442b6ee7dd70d8a308887c2a0917aa9366 (patch)
treef3742f966ad0d41ecd6b06447396341ec0671c18
parent6e7ee4e9bf9cced4e780617ee9b70d95d965b1bc (diff)
downloadpoky-7eb55b442b6ee7dd70d8a308887c2a0917aa9366.tar.gz
oeqa/recipetool: add tests for appendsrcfile(s)
(From OE-Core rev: a6d63b8b4a8a436897bfd29f5de647152149e832) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/recipetool.py152
1 files changed, 152 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/recipetool.py b/meta/lib/oeqa/selftest/recipetool.py
index 854ebfa7b6..bebc1d6fad 100644
--- a/meta/lib/oeqa/selftest/recipetool.py
+++ b/meta/lib/oeqa/selftest/recipetool.py
@@ -399,3 +399,155 @@ class RecipetoolTests(RecipetoolBase):
399 checkvars['DEPENDS'] = 'libpng pango libx11 libxext jpeg' 399 checkvars['DEPENDS'] = 'libpng pango libx11 libxext jpeg'
400 inherits = ['autotools', 'pkgconfig'] 400 inherits = ['autotools', 'pkgconfig']
401 self._test_recipe_contents(recipefile, checkvars, inherits) 401 self._test_recipe_contents(recipefile, checkvars, inherits)
402
403
404class RecipetoolAppendsrcBase(RecipetoolBase):
405 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
406 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, templayerdir, testrecipe, newfile, destfile)
407 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
408
409 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
410
411 if destdir:
412 options += ' -D %s' % destdir
413
414 if expectedfiles is None:
415 expectedfiles = [os.path.basename(f) for f in newfiles]
416
417 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, templayerdir, testrecipe, ' '.join(newfiles))
418 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
419
420 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
421 cmd = 'recipetool appendsrcfile %s %s %s %s' % (templayerdir, testrecipe, newfile, destfile or '')
422 result = runCmd(cmd, ignore_status=True)
423 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
424 self.assertNotIn('Traceback', result.output)
425 for errorstr in checkerror:
426 self.assertIn(errorstr, result.output)
427
428 @staticmethod
429 def _get_first_file_uri(recipe):
430 '''Return the first file:// in SRC_URI for the specified recipe.'''
431 src_uri = get_bb_var('SRC_URI', recipe).split()
432 for uri in src_uri:
433 p = urlparse.urlparse(uri)
434 if p.scheme == 'file':
435 return p.netloc + p.path
436
437 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''):
438 if newfile is None:
439 newfile = self.testfile
440
441 if srcdir:
442 if destdir:
443 expected_subdir = os.path.join(srcdir, destdir)
444 else:
445 expected_subdir = srcdir
446 else:
447 options += " -W"
448 expected_subdir = destdir
449
450 if filename:
451 if destdir:
452 destpath = os.path.join(destdir, filename)
453 else:
454 destpath = filename
455 else:
456 filename = os.path.basename(newfile)
457 if destdir:
458 destpath = destdir + os.sep
459 else:
460 destpath = '.' + os.sep
461
462 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
463 '\n']
464 if has_src_uri:
465 uri = 'file://%s' % filename
466 if expected_subdir:
467 uri += ';subdir=%s' % expected_subdir
468 expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri,
469 '\n']
470
471 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
472
473 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
474 if expectedfiles is None:
475 expectedfiles = [os.path.basename(n) for n in newfiles]
476
477 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
478
479 src_uri = get_bb_var('SRC_URI', testrecipe).split()
480 for f in expectedfiles:
481 if destdir:
482 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
483 else:
484 self.assertIn('file://%s' % f, src_uri)
485
486 recipefile = get_bb_var('FILE', testrecipe)
487 bbappendfile = self._check_bbappend(testrecipe, recipefile, templayerdir)
488 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
489 filesextrapaths = get_bb_var('FILESEXTRAPATHS', testrecipe).split(':')
490 self.assertIn(filesdir, filesextrapaths)
491
492
493class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
494 def test_recipetool_appendsrcfile_basic(self):
495 self._test_appendsrcfile('base-files', 'a-file')
496
497 def test_recipetool_appendsrcfile_basic_wildcard(self):
498 testrecipe = 'base-files'
499 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
500 recipefile = get_bb_var('FILE', testrecipe)
501 bbappendfile = self._check_bbappend(testrecipe, recipefile, templayerdir)
502 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
503
504 def test_recipetool_appendsrcfile_subdir_basic(self):
505 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
506
507 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
508 self._test_appendsrcfile('base-files', destdir='tmp')
509
510 def test_recipetool_appendsrcfile_srcdir_basic(self):
511 testrecipe = 'bash'
512 srcdir = get_bb_var('S', testrecipe)
513 workdir = get_bb_var('WORKDIR', testrecipe)
514 subdir = os.path.relpath(srcdir, workdir)
515 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
516
517 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
518 testrecipe = 'base-files'
519 filepath = self._get_first_file_uri(testrecipe)
520 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
521 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
522
523 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self):
524 testrecipe = 'base-files'
525 subdir = 'tmp'
526 filepath = self._get_first_file_uri(testrecipe)
527 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
528
529 output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False)
530 self.assertTrue(any('with different parameters' in l for l in output))
531
532 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
533 testrecipe = 'bash'
534 filepath = 'Makefile.in'
535 srcdir = get_bb_var('S', testrecipe)
536 workdir = get_bb_var('WORKDIR', testrecipe)
537 subdir = os.path.relpath(srcdir, workdir)
538
539 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
540 bitbake('%s:do_unpack' % testrecipe)
541 self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read())
542
543 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
544 newfiles = [self.testfile]
545 for i in range(1, 5):
546 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
547 with open(testfile, 'w') as f:
548 f.write('Test file %d\n' % i)
549 newfiles.append(testfile)
550 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
551
552 def test_recipetool_appendsrcfiles_basic_subdir(self):
553 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')