diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/devtool.py')
| -rw-r--r-- | meta/lib/oeqa/selftest/devtool.py | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/devtool.py b/meta/lib/oeqa/selftest/devtool.py index ad10af5826..4e22e1dfe4 100644 --- a/meta/lib/oeqa/selftest/devtool.py +++ b/meta/lib/oeqa/selftest/devtool.py | |||
| @@ -524,6 +524,177 @@ class DevtoolTests(DevtoolBase): | |||
| 524 | break | 524 | break |
| 525 | self.assertTrue(matched, 'Unexpected diff remove line: %s' % line) | 525 | self.assertTrue(matched, 'Unexpected diff remove line: %s' % line) |
| 526 | 526 | ||
| 527 | def test_devtool_update_recipe_append(self): | ||
| 528 | # Check preconditions | ||
| 529 | workspacedir = os.path.join(self.builddir, 'workspace') | ||
| 530 | self.assertTrue(not os.path.exists(workspacedir), 'This test cannot be run with a workspace directory under the build directory') | ||
| 531 | testrecipe = 'mdadm' | ||
| 532 | recipefile = get_bb_var('FILE', testrecipe) | ||
| 533 | src_uri = get_bb_var('SRC_URI', testrecipe) | ||
| 534 | self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe) | ||
| 535 | result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) | ||
| 536 | self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe) | ||
| 537 | # First, modify a recipe | ||
| 538 | tempdir = tempfile.mkdtemp(prefix='devtoolqa') | ||
| 539 | tempsrcdir = os.path.join(tempdir, 'source') | ||
| 540 | templayerdir = os.path.join(tempdir, 'layer') | ||
| 541 | self.track_for_cleanup(tempdir) | ||
| 542 | self.track_for_cleanup(workspacedir) | ||
| 543 | self.add_command_to_tearDown('bitbake-layers remove-layer */workspace') | ||
| 544 | # (don't bother with cleaning the recipe on teardown, we won't be building it) | ||
| 545 | result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir)) | ||
| 546 | # Check git repo | ||
| 547 | self.assertTrue(os.path.isdir(os.path.join(tempsrcdir, '.git')), 'git repository for external source tree not found') | ||
| 548 | result = runCmd('git status --porcelain', cwd=tempsrcdir) | ||
| 549 | self.assertEqual(result.output.strip(), "", 'Created git repo is not clean') | ||
| 550 | result = runCmd('git symbolic-ref HEAD', cwd=tempsrcdir) | ||
| 551 | self.assertEqual(result.output.strip(), "refs/heads/devtool", 'Wrong branch in git repo') | ||
| 552 | # Add a commit | ||
| 553 | result = runCmd("sed 's!\\(#define VERSION\\W*\"[^\"]*\\)\"!\\1-custom\"!' -i ReadMe.c", cwd=tempsrcdir) | ||
| 554 | result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir) | ||
| 555 | self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe)) | ||
| 556 | # Create a temporary layer and add it to bblayers.conf | ||
| 557 | self._create_temp_layer(templayerdir, True, 'selftestupdaterecipe') | ||
| 558 | # Create the bbappend | ||
| 559 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 560 | self.assertNotIn('WARNING:', result.output) | ||
| 561 | # Check recipe is still clean | ||
| 562 | result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) | ||
| 563 | self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe) | ||
| 564 | # Check bbappend was created | ||
| 565 | splitpath = os.path.dirname(recipefile).split(os.sep) | ||
| 566 | appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1]) | ||
| 567 | bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir) | ||
| 568 | patchfile = os.path.join(appenddir, testrecipe, '0001-Add-our-custom-version.patch') | ||
| 569 | self.assertTrue(os.path.exists(patchfile), 'Patch file not created') | ||
| 570 | |||
| 571 | # Check bbappend contents | ||
| 572 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
| 573 | '\n', | ||
| 574 | 'SRC_URI += "file://0001-Add-our-custom-version.patch"\n', | ||
| 575 | '\n'] | ||
| 576 | with open(bbappendfile, 'r') as f: | ||
| 577 | self.assertEqual(expectedlines, f.readlines()) | ||
| 578 | |||
| 579 | # Check we can run it again and bbappend isn't modified | ||
| 580 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 581 | with open(bbappendfile, 'r') as f: | ||
| 582 | self.assertEqual(expectedlines, f.readlines()) | ||
| 583 | # Drop new commit and check patch gets deleted | ||
| 584 | result = runCmd('git reset HEAD^', cwd=tempsrcdir) | ||
| 585 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 586 | self.assertFalse(os.path.exists(patchfile), 'Patch file not deleted') | ||
| 587 | expectedlines2 = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', | ||
| 588 | '\n'] | ||
| 589 | with open(bbappendfile, 'r') as f: | ||
| 590 | self.assertEqual(expectedlines2, f.readlines()) | ||
| 591 | # Put commit back and check we can run it if layer isn't in bblayers.conf | ||
| 592 | os.remove(bbappendfile) | ||
| 593 | result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir) | ||
| 594 | result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir) | ||
| 595 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 596 | self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output) | ||
| 597 | self.assertTrue(os.path.exists(patchfile), 'Patch file not created (with disabled layer)') | ||
| 598 | with open(bbappendfile, 'r') as f: | ||
| 599 | self.assertEqual(expectedlines, f.readlines()) | ||
| 600 | # Deleting isn't expected to work under these circumstances | ||
| 601 | |||
| 602 | def test_devtool_update_recipe_append_git(self): | ||
| 603 | # Check preconditions | ||
| 604 | workspacedir = os.path.join(self.builddir, 'workspace') | ||
| 605 | self.assertTrue(not os.path.exists(workspacedir), 'This test cannot be run with a workspace directory under the build directory') | ||
| 606 | testrecipe = 'mtd-utils' | ||
| 607 | recipefile = get_bb_var('FILE', testrecipe) | ||
| 608 | src_uri = get_bb_var('SRC_URI', testrecipe) | ||
| 609 | self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe) | ||
| 610 | for entry in src_uri.split(): | ||
| 611 | if entry.startswith('git://'): | ||
| 612 | git_uri = entry | ||
| 613 | break | ||
| 614 | result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) | ||
| 615 | self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe) | ||
| 616 | # First, modify a recipe | ||
| 617 | tempdir = tempfile.mkdtemp(prefix='devtoolqa') | ||
| 618 | tempsrcdir = os.path.join(tempdir, 'source') | ||
| 619 | templayerdir = os.path.join(tempdir, 'layer') | ||
| 620 | self.track_for_cleanup(tempdir) | ||
| 621 | self.track_for_cleanup(workspacedir) | ||
| 622 | self.add_command_to_tearDown('bitbake-layers remove-layer */workspace') | ||
| 623 | # (don't bother with cleaning the recipe on teardown, we won't be building it) | ||
| 624 | result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir)) | ||
| 625 | # Check git repo | ||
| 626 | self.assertTrue(os.path.isdir(os.path.join(tempsrcdir, '.git')), 'git repository for external source tree not found') | ||
| 627 | result = runCmd('git status --porcelain', cwd=tempsrcdir) | ||
| 628 | self.assertEqual(result.output.strip(), "", 'Created git repo is not clean') | ||
| 629 | result = runCmd('git symbolic-ref HEAD', cwd=tempsrcdir) | ||
| 630 | self.assertEqual(result.output.strip(), "refs/heads/devtool", 'Wrong branch in git repo') | ||
| 631 | # Add a commit | ||
| 632 | result = runCmd('echo "# Additional line" >> Makefile', cwd=tempsrcdir) | ||
| 633 | result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir) | ||
| 634 | self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe)) | ||
| 635 | # Create a temporary layer | ||
| 636 | os.makedirs(os.path.join(templayerdir, 'conf')) | ||
| 637 | with open(os.path.join(templayerdir, 'conf', 'layer.conf'), 'w') as f: | ||
| 638 | f.write('BBPATH .= ":${LAYERDIR}"\n') | ||
| 639 | f.write('BBFILES += "${LAYERDIR}/recipes-*/*/*.bbappend"\n') | ||
| 640 | f.write('BBFILE_COLLECTIONS += "oeselftesttemplayer"\n') | ||
| 641 | f.write('BBFILE_PATTERN_oeselftesttemplayer = "^${LAYERDIR}/"\n') | ||
| 642 | f.write('BBFILE_PRIORITY_oeselftesttemplayer = "999"\n') | ||
| 643 | f.write('BBFILE_PATTERN_IGNORE_EMPTY_oeselftesttemplayer = "1"\n') | ||
| 644 | self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir) | ||
| 645 | result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir) | ||
| 646 | # Create the bbappend | ||
| 647 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 648 | self.assertNotIn('WARNING:', result.output) | ||
| 649 | # Check recipe is still clean | ||
| 650 | result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) | ||
| 651 | self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe) | ||
| 652 | # Check bbappend was created | ||
| 653 | splitpath = os.path.dirname(recipefile).split(os.sep) | ||
| 654 | appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1]) | ||
| 655 | bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir) | ||
| 656 | self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') | ||
| 657 | |||
| 658 | # Check bbappend contents | ||
| 659 | result = runCmd('git rev-parse HEAD', cwd=tempsrcdir) | ||
| 660 | expectedlines = ['SRCREV = "%s"\n' % result.output, | ||
| 661 | '\n', | ||
| 662 | 'SRC_URI = "%s"\n' % git_uri, | ||
| 663 | '\n'] | ||
| 664 | with open(bbappendfile, 'r') as f: | ||
| 665 | self.assertEqual(expectedlines, f.readlines()) | ||
| 666 | |||
| 667 | # Check we can run it again and bbappend isn't modified | ||
| 668 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 669 | with open(bbappendfile, 'r') as f: | ||
| 670 | self.assertEqual(expectedlines, f.readlines()) | ||
| 671 | # Drop new commit and check SRCREV changes | ||
| 672 | result = runCmd('git reset HEAD^', cwd=tempsrcdir) | ||
| 673 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 674 | self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') | ||
| 675 | result = runCmd('git rev-parse HEAD', cwd=tempsrcdir) | ||
| 676 | expectedlines = ['SRCREV = "%s"\n' % result.output, | ||
| 677 | '\n', | ||
| 678 | 'SRC_URI = "%s"\n' % git_uri, | ||
| 679 | '\n'] | ||
| 680 | with open(bbappendfile, 'r') as f: | ||
| 681 | self.assertEqual(expectedlines, f.readlines()) | ||
| 682 | # Put commit back and check we can run it if layer isn't in bblayers.conf | ||
| 683 | os.remove(bbappendfile) | ||
| 684 | result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir) | ||
| 685 | result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir) | ||
| 686 | result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) | ||
| 687 | self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output) | ||
| 688 | self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') | ||
| 689 | result = runCmd('git rev-parse HEAD', cwd=tempsrcdir) | ||
| 690 | expectedlines = ['SRCREV = "%s"\n' % result.output, | ||
| 691 | '\n', | ||
| 692 | 'SRC_URI = "%s"\n' % git_uri, | ||
| 693 | '\n'] | ||
| 694 | with open(bbappendfile, 'r') as f: | ||
| 695 | self.assertEqual(expectedlines, f.readlines()) | ||
| 696 | # Deleting isn't expected to work under these circumstances | ||
| 697 | |||
| 527 | def test_devtool_extract(self): | 698 | def test_devtool_extract(self): |
| 528 | # Check preconditions | 699 | # Check preconditions |
| 529 | workspacedir = os.path.join(self.builddir, 'workspace') | 700 | workspacedir = os.path.join(self.builddir, 'workspace') |
