1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-09 17:39:31 +00:00

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>
This commit is contained in:
Markus Lehtonen
2015-09-23 13:45:07 +03:00
committed by Richard Purdie
parent 0a9f59e8d2
commit 2f8440b9ae
+34 -52
View File
@@ -103,6 +103,22 @@ class DevtoolTests(DevtoolBase):
self.assertEqual(result.output.strip(), "refs/heads/devtool", self.assertEqual(result.output.strip(), "refs/heads/devtool",
'Wrong branch in git repo') 'Wrong branch in git repo')
def _check_repo_status(self, repo_dir, expected_status):
"""Check the worktree status of a repository"""
result = runCmd('git status . --porcelain',
cwd=repo_dir)
for line in result.output.splitlines():
for ind, (f_status, fn_re) in enumerate(expected_status):
if re.match(fn_re, line[3:]):
if f_status != line[:2]:
self.fail('Unexpected status in line: %s' % line)
expected_status.pop(ind)
break
else:
self.fail('Unexpected modified file in line: %s' % line)
if expected_status:
self.fail('Missing file changes: %s' % expected_status)
@testcase(1158) @testcase(1158)
def test_create_workspace(self): def test_create_workspace(self):
# Check preconditions # Check preconditions
@@ -457,8 +473,7 @@ class DevtoolTests(DevtoolBase):
recipefile = get_bb_var('FILE', testrecipe) recipefile = get_bb_var('FILE', testrecipe)
src_uri = get_bb_var('SRC_URI', testrecipe) src_uri = get_bb_var('SRC_URI', testrecipe)
self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe) self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self._check_repo_status(os.path.dirname(recipefile), [])
self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
# First, modify a recipe # First, modify a recipe
tempdir = tempfile.mkdtemp(prefix='devtoolqa') tempdir = tempfile.mkdtemp(prefix='devtoolqa')
self.track_for_cleanup(tempdir) self.track_for_cleanup(tempdir)
@@ -477,19 +492,10 @@ class DevtoolTests(DevtoolBase):
result = runCmd('git commit -m "Add a new file"', cwd=tempdir) result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile))) self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
result = runCmd('devtool update-recipe %s' % testrecipe) result = runCmd('devtool update-recipe %s' % testrecipe)
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe) ('??', '.*/0001-Change-the-README.patch$'),
status = result.output.splitlines() ('??', '.*/0002-Add-a-new-file.patch$')]
self.assertEqual(len(status), 3, 'Less/more files modified than expected. Entire status:\n%s' % result.output) self._check_repo_status(os.path.dirname(recipefile), expected_status)
for line in status:
if line.endswith('0001-Change-the-README.patch'):
self.assertEqual(line[:3], '?? ', 'Unexpected status in line: %s' % line)
elif line.endswith('0002-Add-a-new-file.patch'):
self.assertEqual(line[:3], '?? ', 'Unexpected status in line: %s' % line)
elif re.search('%s_[^_]*.bb$' % testrecipe, line):
self.assertEqual(line[:3], ' M ', 'Unexpected status in line: %s' % line)
else:
raise AssertionError('Unexpected modified file in status: %s' % line)
@testcase(1172) @testcase(1172)
def test_devtool_update_recipe_git(self): def test_devtool_update_recipe_git(self):
@@ -503,8 +509,7 @@ class DevtoolTests(DevtoolBase):
if entry.startswith('file://') and entry.endswith('.patch'): if entry.startswith('file://') and entry.endswith('.patch'):
patches.append(entry[7:].split(';')[0]) patches.append(entry[7:].split(';')[0])
self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe) self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe)
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self._check_repo_status(os.path.dirname(recipefile), [])
self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
# First, modify a recipe # First, modify a recipe
tempdir = tempfile.mkdtemp(prefix='devtoolqa') tempdir = tempfile.mkdtemp(prefix='devtoolqa')
self.track_for_cleanup(tempdir) self.track_for_cleanup(tempdir)
@@ -523,19 +528,10 @@ class DevtoolTests(DevtoolBase):
result = runCmd('git commit -m "Add a new file"', cwd=tempdir) result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile))) self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe) result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe)
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile))] + \
self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe) [(' D', '.*/%s$' % patch) for patch in patches]
status = result.output.splitlines() self._check_repo_status(os.path.dirname(recipefile), expected_status)
for line in status:
for patch in patches:
if line.endswith(patch):
self.assertEqual(line[:3], ' D ', 'Unexpected status in line: %s' % line)
break
else:
if re.search('%s_[^_]*.bb$' % testrecipe, line):
self.assertEqual(line[:3], ' M ', 'Unexpected status in line: %s' % line)
else:
raise AssertionError('Unexpected modified file in status: %s' % line)
result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile)) result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git"'] addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git"']
srcurilines = src_uri.split() srcurilines = src_uri.split()
@@ -564,21 +560,11 @@ class DevtoolTests(DevtoolBase):
result = runCmd('devtool update-recipe %s' % testrecipe) result = runCmd('devtool update-recipe %s' % testrecipe)
result = runCmd('git rev-parse --show-toplevel') result = runCmd('git rev-parse --show-toplevel')
topleveldir = result.output.strip() topleveldir = result.output.strip()
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile))
status = result.output.splitlines()
relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe) relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe)
expectedstatus = [('M', os.path.relpath(recipefile, topleveldir)), expected_status = [(' M', os.path.relpath(recipefile, topleveldir)),
('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath), ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath),
('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)] ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)]
for line in status: self._check_repo_status(os.path.dirname(recipefile), expected_status)
statusline = line.split(None, 1)
for fstatus, fn in expectedstatus:
if fn == statusline[1]:
if fstatus != statusline[0]:
self.fail('Unexpected status in line: %s' % line)
break
else:
self.fail('Unexpected modified file in line: %s' % line)
@testcase(1170) @testcase(1170)
def test_devtool_update_recipe_append(self): def test_devtool_update_recipe_append(self):
@@ -587,8 +573,7 @@ class DevtoolTests(DevtoolBase):
recipefile = get_bb_var('FILE', testrecipe) recipefile = get_bb_var('FILE', testrecipe)
src_uri = get_bb_var('SRC_URI', testrecipe) src_uri = get_bb_var('SRC_URI', testrecipe)
self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe) self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self._check_repo_status(os.path.dirname(recipefile), [])
self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
# First, modify a recipe # First, modify a recipe
tempdir = tempfile.mkdtemp(prefix='devtoolqa') tempdir = tempfile.mkdtemp(prefix='devtoolqa')
tempsrcdir = os.path.join(tempdir, 'source') tempsrcdir = os.path.join(tempdir, 'source')
@@ -610,8 +595,7 @@ class DevtoolTests(DevtoolBase):
result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
self.assertNotIn('WARNING:', result.output) self.assertNotIn('WARNING:', result.output)
# Check recipe is still clean # Check recipe is still clean
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self._check_repo_status(os.path.dirname(recipefile), [])
self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
# Check bbappend was created # Check bbappend was created
splitpath = os.path.dirname(recipefile).split(os.sep) splitpath = os.path.dirname(recipefile).split(os.sep)
appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1]) appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
@@ -661,8 +645,7 @@ class DevtoolTests(DevtoolBase):
if entry.startswith('git://'): if entry.startswith('git://'):
git_uri = entry git_uri = entry
break break
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self._check_repo_status(os.path.dirname(recipefile), [])
self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
# First, modify a recipe # First, modify a recipe
tempdir = tempfile.mkdtemp(prefix='devtoolqa') tempdir = tempfile.mkdtemp(prefix='devtoolqa')
tempsrcdir = os.path.join(tempdir, 'source') tempsrcdir = os.path.join(tempdir, 'source')
@@ -693,8 +676,7 @@ class DevtoolTests(DevtoolBase):
result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir)) result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
self.assertNotIn('WARNING:', result.output) self.assertNotIn('WARNING:', result.output)
# Check recipe is still clean # Check recipe is still clean
result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self._check_repo_status(os.path.dirname(recipefile), [])
self.assertEqual(result.output.strip(), "", '%s recipe is not clean' % testrecipe)
# Check bbappend was created # Check bbappend was created
splitpath = os.path.dirname(recipefile).split(os.sep) splitpath = os.path.dirname(recipefile).split(os.sep)
appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1]) appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])