summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2015-09-23 13:45:07 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-10-01 07:43:31 +0100
commit2f8440b9aeedefc8d2bb789a7ad42e8a1ed55716 (patch)
tree8ebeecc50e3c235d96fa22091d369f39a47075d3 /meta/lib
parent0a9f59e8d2b742322ed90986cdeff7587e40a7d1 (diff)
downloadpoky-2f8440b9aeedefc8d2bb789a7ad42e8a1ed55716.tar.gz
oe-selftest: devtool: add method for checking repo status
New method for checking the status of the working tree of a repository. (From OE-Core rev: 4e5eea06a77eca7311209b0b650e79e816713ab9) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/selftest/devtool.py86
1 files changed, 34 insertions, 52 deletions
diff --git a/meta/lib/oeqa/selftest/devtool.py b/meta/lib/oeqa/selftest/devtool.py
index 0df96e794c..92cd0e230d 100644
--- a/meta/lib/oeqa/selftest/devtool.py
+++ b/meta/lib/oeqa/selftest/devtool.py
@@ -103,6 +103,22 @@ class DevtoolTests(DevtoolBase):
103 self.assertEqual(result.output.strip(), "refs/heads/devtool", 103 self.assertEqual(result.output.strip(), "refs/heads/devtool",
104 'Wrong branch in git repo') 104 'Wrong branch in git repo')
105 105
106 def _check_repo_status(self, repo_dir, expected_status):
107 """Check the worktree status of a repository"""
108 result = runCmd('git status . --porcelain',
109 cwd=repo_dir)
110 for line in result.output.splitlines():
111 for ind, (f_status, fn_re) in enumerate(expected_status):
112 if re.match(fn_re, line[3:]):
113 if f_status != line[:2]:
114 self.fail('Unexpected status in line: %s' % line)
115 expected_status.pop(ind)
116 break
117 else:
118 self.fail('Unexpected modified file in line: %s' % line)
119 if expected_status:
120 self.fail('Missing file changes: %s' % expected_status)
121
106 @testcase(1158) 122 @testcase(1158)
107 def test_create_workspace(self): 123 def test_create_workspace(self):
108 # Check preconditions 124 # Check preconditions
@@ -457,8 +473,7 @@ class DevtoolTests(DevtoolBase):
457 recipefile = get_bb_var('FILE', testrecipe) 473 recipefile = get_bb_var('FILE', testrecipe)
458 src_uri = get_bb_var('SRC_URI', testrecipe) 474 src_uri = get_bb_var('SRC_URI', testrecipe)
459 self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe) 475 self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
460 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 476 self._check_repo_status(os.path.dirname(recipefile), [])
461 self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
462 # First, modify a recipe 477 # First, modify a recipe
463 tempdir = tempfile.mkdtemp(prefix='devtoolqa') 478 tempdir = tempfile.mkdtemp(prefix='devtoolqa')
464 self.track_for_cleanup(tempdir) 479 self.track_for_cleanup(tempdir)
@@ -477,19 +492,10 @@ class DevtoolTests(DevtoolBase):
477 result = runCmd('git commit -m "Add a new file"', cwd=tempdir) 492 result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
478 self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile))) 493 self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
479 result = runCmd('devtool update-recipe %s' % testrecipe) 494 result = runCmd('devtool update-recipe %s' % testrecipe)
480 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 495 expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
481 self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe) 496 ('??', '.*/0001-Change-the-README.patch$'),
482 status = result.output.splitlines() 497 ('??', '.*/0002-Add-a-new-file.patch$')]
483 self.assertEqual(len(status), 3, 'Less/more files modified than expected. Entire status:\n%s' % result.output) 498 self._check_repo_status(os.path.dirname(recipefile), expected_status)
484 for line in status:
485 if line.endswith('0001-Change-the-README.patch'):
486 self.assertEqual(line[:3], '?? ', 'Unexpected status in line: %s' % line)
487 elif line.endswith('0002-Add-a-new-file.patch'):
488 self.assertEqual(line[:3], '?? ', 'Unexpected status in line: %s' % line)
489 elif re.search('%s_[^_]*.bb$' % testrecipe, line):
490 self.assertEqual(line[:3], ' M ', 'Unexpected status in line: %s' % line)
491 else:
492 raise AssertionError('Unexpected modified file in status: %s' % line)
493 499
494 @testcase(1172) 500 @testcase(1172)
495 def test_devtool_update_recipe_git(self): 501 def test_devtool_update_recipe_git(self):
@@ -503,8 +509,7 @@ class DevtoolTests(DevtoolBase):
503 if entry.startswith('file://') and entry.endswith('.patch'): 509 if entry.startswith('file://') and entry.endswith('.patch'):
504 patches.append(entry[7:].split(';')[0]) 510 patches.append(entry[7:].split(';')[0])
505 self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe) 511 self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe)
506 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 512 self._check_repo_status(os.path.dirname(recipefile), [])
507 self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
508 # First, modify a recipe 513 # First, modify a recipe
509 tempdir = tempfile.mkdtemp(prefix='devtoolqa') 514 tempdir = tempfile.mkdtemp(prefix='devtoolqa')
510 self.track_for_cleanup(tempdir) 515 self.track_for_cleanup(tempdir)
@@ -523,19 +528,10 @@ class DevtoolTests(DevtoolBase):
523 result = runCmd('git commit -m "Add a new file"', cwd=tempdir) 528 result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
524 self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile))) 529 self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
525 result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe) 530 result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe)
526 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 531 expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile))] + \
527 self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe) 532 [(' D', '.*/%s$' % patch) for patch in patches]
528 status = result.output.splitlines() 533 self._check_repo_status(os.path.dirname(recipefile), expected_status)
529 for line in status: 534
530 for patch in patches:
531 if line.endswith(patch):
532 self.assertEqual(line[:3], ' D ', 'Unexpected status in line: %s' % line)
533 break
534 else:
535 if re.search('%s_[^_]*.bb$' % testrecipe, line):
536 self.assertEqual(line[:3], ' M ', 'Unexpected status in line: %s' % line)
537 else:
538 raise AssertionError('Unexpected modified file in status: %s' % line)
539 result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile)) 535 result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
540 addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git"'] 536 addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git"']
541 srcurilines = src_uri.split() 537 srcurilines = src_uri.split()
@@ -564,21 +560,11 @@ class DevtoolTests(DevtoolBase):
564 result = runCmd('devtool update-recipe %s' % testrecipe) 560 result = runCmd('devtool update-recipe %s' % testrecipe)
565 result = runCmd('git rev-parse --show-toplevel') 561 result = runCmd('git rev-parse --show-toplevel')
566 topleveldir = result.output.strip() 562 topleveldir = result.output.strip()
567 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile))
568 status = result.output.splitlines()
569 relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe) 563 relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe)
570 expectedstatus = [('M', os.path.relpath(recipefile, topleveldir)), 564 expected_status = [(' M', os.path.relpath(recipefile, topleveldir)),
571 ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath), 565 ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath),
572 ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)] 566 ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)]
573 for line in status: 567 self._check_repo_status(os.path.dirname(recipefile), expected_status)
574 statusline = line.split(None, 1)
575 for fstatus, fn in expectedstatus:
576 if fn == statusline[1]:
577 if fstatus != statusline[0]:
578 self.fail('Unexpected status in line: %s' % line)
579 break
580 else:
581 self.fail('Unexpected modified file in line: %s' % line)
582 568
583 @testcase(1170) 569 @testcase(1170)
584 def test_devtool_update_recipe_append(self): 570 def test_devtool_update_recipe_append(self):
@@ -587,8 +573,7 @@ class DevtoolTests(DevtoolBase):
587 recipefile = get_bb_var('FILE', testrecipe) 573 recipefile = get_bb_var('FILE', testrecipe)
588 src_uri = get_bb_var('SRC_URI', testrecipe) 574 src_uri = get_bb_var('SRC_URI', testrecipe)
589 self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe) 575 self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
590 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 576 self._check_repo_status(os.path.dirname(recipefile), [])
591 self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
592 # First, modify a recipe 577 # First, modify a recipe
593 tempdir = tempfile.mkdtemp(prefix='devtoolqa') 578 tempdir = tempfile.mkdtemp(prefix='devtoolqa')
594 tempsrcdir = os.path.join(tempdir, 'source') 579 tempsrcdir = os.path.join(tempdir, 'source')
@@ -610,8 +595,7 @@ class DevtoolTests(DevtoolBase):
610 result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) 595 result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
611 self.assertNotIn('WARNING:', result.output) 596 self.assertNotIn('WARNING:', result.output)
612 # Check recipe is still clean 597 # Check recipe is still clean
613 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 598 self._check_repo_status(os.path.dirname(recipefile), [])
614 self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
615 # Check bbappend was created 599 # Check bbappend was created
616 splitpath = os.path.dirname(recipefile).split(os.sep) 600 splitpath = os.path.dirname(recipefile).split(os.sep)
617 appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1]) 601 appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
@@ -661,8 +645,7 @@ class DevtoolTests(DevtoolBase):
661 if entry.startswith('git://'): 645 if entry.startswith('git://'):
662 git_uri = entry 646 git_uri = entry
663 break 647 break
664 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 648 self._check_repo_status(os.path.dirname(recipefile), [])
665 self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
666 # First, modify a recipe 649 # First, modify a recipe
667 tempdir = tempfile.mkdtemp(prefix='devtoolqa') 650 tempdir = tempfile.mkdtemp(prefix='devtoolqa')
668 tempsrcdir = os.path.join(tempdir, 'source') 651 tempsrcdir = os.path.join(tempdir, 'source')
@@ -693,8 +676,7 @@ class DevtoolTests(DevtoolBase):
693 result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir)) 676 result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
694 self.assertNotIn('WARNING:', result.output) 677 self.assertNotIn('WARNING:', result.output)
695 # Check recipe is still clean 678 # Check recipe is still clean
696 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 679 self._check_repo_status(os.path.dirname(recipefile), [])
697 self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
698 # Check bbappend was created 680 # Check bbappend was created
699 splitpath = os.path.dirname(recipefile).split(os.sep) 681 splitpath = os.path.dirname(recipefile).split(os.sep)
700 appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1]) 682 appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])