diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/devtool.py')
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/devtool.py | 114 |
1 files changed, 97 insertions, 17 deletions
diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py index ddf6c0c9f8..34fc791f3a 100644 --- a/meta/lib/oeqa/selftest/cases/devtool.py +++ b/meta/lib/oeqa/selftest/cases/devtool.py | |||
| @@ -218,6 +218,34 @@ class DevtoolTestCase(OESelftestTestCase): | |||
| 218 | filelist.append(' '.join(splitline)) | 218 | filelist.append(' '.join(splitline)) |
| 219 | return filelist | 219 | return filelist |
| 220 | 220 | ||
| 221 | def _check_diff(self, diffoutput, addlines, removelines): | ||
| 222 | """Check output from 'git diff' matches expectation""" | ||
| 223 | remaining_addlines = addlines[:] | ||
| 224 | remaining_removelines = removelines[:] | ||
| 225 | for line in diffoutput.splitlines(): | ||
| 226 | if line.startswith('+++') or line.startswith('---'): | ||
| 227 | continue | ||
| 228 | elif line.startswith('+'): | ||
| 229 | matched = False | ||
| 230 | for item in addlines: | ||
| 231 | if re.match(item, line[1:].strip()): | ||
| 232 | matched = True | ||
| 233 | remaining_addlines.remove(item) | ||
| 234 | break | ||
| 235 | self.assertTrue(matched, 'Unexpected diff add line: %s' % line) | ||
| 236 | elif line.startswith('-'): | ||
| 237 | matched = False | ||
| 238 | for item in removelines: | ||
| 239 | if re.match(item, line[1:].strip()): | ||
| 240 | matched = True | ||
| 241 | remaining_removelines.remove(item) | ||
| 242 | break | ||
| 243 | self.assertTrue(matched, 'Unexpected diff remove line: %s' % line) | ||
| 244 | if remaining_addlines: | ||
| 245 | self.fail('Expected added lines not found: %s' % remaining_addlines) | ||
| 246 | if remaining_removelines: | ||
| 247 | self.fail('Expected removed lines not found: %s' % remaining_removelines) | ||
| 248 | |||
| 221 | 249 | ||
| 222 | class DevtoolBase(DevtoolTestCase): | 250 | class DevtoolBase(DevtoolTestCase): |
| 223 | 251 | ||
| @@ -718,6 +746,7 @@ class DevtoolModifyTests(DevtoolBase): | |||
| 718 | 746 | ||
| 719 | self.assertTrue(bbclassextended, 'None of these recipes are BBCLASSEXTENDed to native - need to adjust testrecipes list: %s' % ', '.join(testrecipes)) | 747 | self.assertTrue(bbclassextended, 'None of these recipes are BBCLASSEXTENDed to native - need to adjust testrecipes list: %s' % ', '.join(testrecipes)) |
| 720 | self.assertTrue(inheritnative, 'None of these recipes do "inherit native" - need to adjust testrecipes list: %s' % ', '.join(testrecipes)) | 748 | self.assertTrue(inheritnative, 'None of these recipes do "inherit native" - need to adjust testrecipes list: %s' % ', '.join(testrecipes)) |
| 749 | |||
| 721 | def test_devtool_modify_localfiles_only(self): | 750 | def test_devtool_modify_localfiles_only(self): |
| 722 | # Check preconditions | 751 | # Check preconditions |
| 723 | testrecipe = 'base-files' | 752 | testrecipe = 'base-files' |
| @@ -930,23 +959,7 @@ class DevtoolUpdateTests(DevtoolBase): | |||
| 930 | srcurilines[0] = 'SRC_URI = "' + srcurilines[0] | 959 | srcurilines[0] = 'SRC_URI = "' + srcurilines[0] |
| 931 | srcurilines.append('"') | 960 | srcurilines.append('"') |
| 932 | removelines = ['SRCREV = ".*"'] + srcurilines | 961 | removelines = ['SRCREV = ".*"'] + srcurilines |
| 933 | for line in result.output.splitlines(): | 962 | self._check_diff(result.output, addlines, removelines) |
| 934 | if line.startswith('+++') or line.startswith('---'): | ||
| 935 | continue | ||
| 936 | elif line.startswith('+'): | ||
| 937 | matched = False | ||
| 938 | for item in addlines: | ||
| 939 | if re.match(item, line[1:].strip()): | ||
| 940 | matched = True | ||
| 941 | break | ||
| 942 | self.assertTrue(matched, 'Unexpected diff add line: %s' % line) | ||
| 943 | elif line.startswith('-'): | ||
| 944 | matched = False | ||
| 945 | for item in removelines: | ||
| 946 | if re.match(item, line[1:].strip()): | ||
| 947 | matched = True | ||
| 948 | break | ||
| 949 | self.assertTrue(matched, 'Unexpected diff remove line: %s' % line) | ||
| 950 | # Now try with auto mode | 963 | # Now try with auto mode |
| 951 | runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile))) | 964 | runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile))) |
| 952 | result = runCmd('devtool update-recipe %s' % testrecipe) | 965 | result = runCmd('devtool update-recipe %s' % testrecipe) |
| @@ -1316,6 +1329,73 @@ class DevtoolUpdateTests(DevtoolBase): | |||
| 1316 | expected_status = [] | 1329 | expected_status = [] |
| 1317 | self._check_repo_status(os.path.dirname(recipefile), expected_status) | 1330 | self._check_repo_status(os.path.dirname(recipefile), expected_status) |
| 1318 | 1331 | ||
| 1332 | def test_devtool_finish_modify_git_subdir(self): | ||
| 1333 | # Check preconditions | ||
| 1334 | testrecipe = 'dos2unix' | ||
| 1335 | bb_vars = get_bb_vars(['SRC_URI', 'S', 'WORKDIR', 'FILE'], testrecipe) | ||
| 1336 | self.assertIn('git://', bb_vars['SRC_URI'], 'This test expects the %s recipe to be a git recipe' % testrecipe) | ||
| 1337 | workdir_git = '%s/git/' % bb_vars['WORKDIR'] | ||
| 1338 | if not bb_vars['S'].startswith(workdir_git): | ||
| 1339 | self.fail('This test expects the %s recipe to be building from a subdirectory of the git repo' % testrecipe) | ||
| 1340 | subdir = bb_vars['S'].split(workdir_git, 1)[1] | ||
| 1341 | # Clean up anything in the workdir/sysroot/sstate cache | ||
| 1342 | bitbake('%s -c cleansstate' % testrecipe) | ||
| 1343 | # Try modifying a recipe | ||
| 1344 | tempdir = tempfile.mkdtemp(prefix='devtoolqa') | ||
| 1345 | self.track_for_cleanup(tempdir) | ||
| 1346 | self.track_for_cleanup(self.workspacedir) | ||
| 1347 | self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe) | ||
| 1348 | self.add_command_to_tearDown('bitbake-layers remove-layer */workspace') | ||
| 1349 | result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir)) | ||
| 1350 | testsrcfile = os.path.join(tempdir, subdir, 'dos2unix.c') | ||
| 1351 | self.assertExists(testsrcfile, 'Extracted source could not be found') | ||
| 1352 | self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output) | ||
| 1353 | self.assertNotExists(os.path.join(tempdir, subdir, '.git'), 'Subdirectory has been initialised as a git repo') | ||
| 1354 | # Check git repo | ||
| 1355 | self._check_src_repo(tempdir) | ||
| 1356 | # Modify file | ||
| 1357 | runCmd("sed -i '1s:^:/* Add a comment */\\n:' %s" % testsrcfile) | ||
| 1358 | result = runCmd('git commit -a -m "Add a comment"', cwd=tempdir) | ||
| 1359 | # Now try updating original recipe | ||
| 1360 | recipefile = bb_vars['FILE'] | ||
| 1361 | recipedir = os.path.dirname(recipefile) | ||
| 1362 | self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (recipedir, testrecipe)) | ||
| 1363 | result = runCmd('devtool update-recipe %s' % testrecipe) | ||
| 1364 | expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)), | ||
| 1365 | ('??', '.*/%s/%s/$' % (testrecipe, testrecipe))] | ||
| 1366 | self._check_repo_status(os.path.dirname(recipefile), expected_status) | ||
| 1367 | result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile)) | ||
| 1368 | removelines = ['SRC_URI = "git://.*"'] | ||
| 1369 | addlines = [ | ||
| 1370 | 'SRC_URI = "git://.* \\\\', | ||
| 1371 | 'file://0001-Add-a-comment.patch;patchdir=.. \\\\', | ||
| 1372 | '"' | ||
| 1373 | ] | ||
| 1374 | self._check_diff(result.output, addlines, removelines) | ||
| 1375 | # Put things back so we can run devtool finish on a different layer | ||
| 1376 | runCmd('cd %s; rm -f %s/*.patch; git checkout .' % (recipedir, testrecipe)) | ||
| 1377 | # Run devtool finish | ||
| 1378 | res = re.search('recipes-.*', recipedir) | ||
| 1379 | self.assertTrue(res, 'Unable to find recipe subdirectory') | ||
| 1380 | recipesubdir = res[0] | ||
| 1381 | self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, recipesubdir)) | ||
| 1382 | result = runCmd('devtool finish %s meta-selftest' % testrecipe) | ||
| 1383 | # Check bbappend file contents | ||
| 1384 | appendfn = os.path.join(self.testlayer_path, recipesubdir, '%s_%%.bbappend' % testrecipe) | ||
| 1385 | with open(appendfn, 'r') as f: | ||
| 1386 | appendlines = f.readlines() | ||
| 1387 | expected_appendlines = [ | ||
| 1388 | 'FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', | ||
| 1389 | '\n', | ||
| 1390 | 'SRC_URI += "file://0001-Add-a-comment.patch;patchdir=.."\n', | ||
| 1391 | '\n' | ||
| 1392 | ] | ||
| 1393 | self.assertEqual(appendlines, expected_appendlines) | ||
| 1394 | self.assertExists(os.path.join(os.path.dirname(appendfn), testrecipe, '0001-Add-a-comment.patch')) | ||
| 1395 | # Try building | ||
| 1396 | bitbake('%s -c patch' % testrecipe) | ||
| 1397 | |||
| 1398 | |||
| 1319 | class DevtoolExtractTests(DevtoolBase): | 1399 | class DevtoolExtractTests(DevtoolBase): |
| 1320 | 1400 | ||
| 1321 | def test_devtool_extract(self): | 1401 | def test_devtool_extract(self): |
