Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Smoke tests for gclient.py. | 6 """Smoke tests for gclient.py. |
| 7 | 7 |
| 8 Shell out 'gclient' and run basic conformance tests. | 8 Shell out 'gclient' and run basic conformance tests. |
| 9 | 9 |
| 10 This test assumes GClientSmokeBase.URL_BASE is valid. | 10 This test assumes GClientSmokeBase.URL_BASE is valid. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 cmd = cmd_base + cmd | 46 cmd = cmd_base + cmd |
| 47 process = subprocess.Popen(cmd, cwd=cwd, env=self.env, | 47 process = subprocess.Popen(cmd, cwd=cwd, env=self.env, |
| 48 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 48 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 49 shell=sys.platform.startswith('win')) | 49 shell=sys.platform.startswith('win')) |
| 50 (stdout, stderr) = process.communicate() | 50 (stdout, stderr) = process.communicate() |
| 51 logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout)) | 51 logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout)) |
| 52 logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr)) | 52 logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr)) |
| 53 return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'), | 53 return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'), |
| 54 process.returncode) | 54 process.returncode) |
| 55 | 55 |
| 56 def untangle(self, stdout): | |
| 57 tasks = {} | |
| 58 remaining = [] | |
| 59 for line in stdout.splitlines(False): | |
| 60 m = re.match(r'^(\d)+>(.*)$', line) | |
| 61 if not m: | |
| 62 remaining.append(line) | |
| 63 else: | |
| 64 self.assertEquals([], remaining) | |
| 65 tasks.setdefault(int(m.group(1)), []).append(m.group(2)) | |
| 66 out = [] | |
| 67 for key in sorted(tasks.iterkeys()): | |
| 68 out.extend(tasks[key]) | |
| 69 out.extend(remaining) | |
| 70 return '\n'.join(out) | |
| 71 | |
| 56 def parseGclient(self, cmd, items, expected_stderr='', untangle=False): | 72 def parseGclient(self, cmd, items, expected_stderr='', untangle=False): |
| 57 """Parse gclient's output to make it easier to test. | 73 """Parse gclient's output to make it easier to test. |
| 58 If untangle is True, tries to sort out the output from parallel checkout.""" | 74 If untangle is True, tries to sort out the output from parallel checkout.""" |
| 59 (stdout, stderr, returncode) = self.gclient(cmd) | 75 (stdout, stderr, returncode) = self.gclient(cmd) |
| 60 if untangle: | 76 if untangle: |
| 61 tasks = {} | 77 stdout = self.untangle(stdout) |
| 62 remaining = [] | |
| 63 for line in stdout.splitlines(False): | |
| 64 m = re.match(r'^(\d)+>(.*)$', line) | |
| 65 if not m: | |
| 66 remaining.append(line) | |
| 67 else: | |
| 68 self.assertEquals([], remaining) | |
| 69 tasks.setdefault(int(m.group(1)), []).append(m.group(2)) | |
| 70 out = [] | |
| 71 for key in sorted(tasks.iterkeys()): | |
| 72 out.extend(tasks[key]) | |
| 73 out.extend(remaining) | |
| 74 stdout = '\n'.join(out) | |
| 75 self.checkString(expected_stderr, stderr) | 78 self.checkString(expected_stderr, stderr) |
| 76 self.assertEquals(0, returncode) | 79 self.assertEquals(0, returncode) |
| 77 return self.checkBlock(stdout, items) | 80 return self.checkBlock(stdout, items) |
| 78 | 81 |
| 79 def splitBlock(self, stdout): | 82 def splitBlock(self, stdout): |
| 80 """Split gclient's output into logical execution blocks. | 83 """Split gclient's output into logical execution blocks. |
| 81 ___ running 'foo' at '/bar' | 84 ___ running 'foo' at '/bar' |
| 82 (...) | 85 (...) |
| 83 ___ running 'baz' at '/bar' | 86 ___ running 'baz' at '/bar' |
| 84 (...) | 87 (...) |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 self.checkString(join('third_party', 'fpp'), out[0][2]) | 606 self.checkString(join('third_party', 'fpp'), out[0][2]) |
| 604 self.checkString(join('third_party', 'prout'), out[0][3]) | 607 self.checkString(join('third_party', 'prout'), out[0][3]) |
| 605 self.checkString('hi', out[1][1]) | 608 self.checkString('hi', out[1][1]) |
| 606 self.assertEquals(4, len(out[0])) | 609 self.assertEquals(4, len(out[0])) |
| 607 self.assertEquals(2, len(out[1])) | 610 self.assertEquals(2, len(out[1])) |
| 608 | 611 |
| 609 # So verify it works with --verbose. | 612 # So verify it works with --verbose. |
| 610 out = self.parseGclient( | 613 out = self.parseGclient( |
| 611 ['status', '--deps', 'mac', '--verbose', '--jobs', '1'], | 614 ['status', '--deps', 'mac', '--verbose', '--jobs', '1'], |
| 612 [['running', join(self.root_dir, 'src')], | 615 [['running', join(self.root_dir, 'src')], |
| 616 ['running', join(self.root_dir, 'src', 'other')], | |
| 613 ['running', join(self.root_dir, 'src', 'third_party', 'fpp')], | 617 ['running', join(self.root_dir, 'src', 'third_party', 'fpp')], |
| 614 ['running', join(self.root_dir, 'src', 'other')], | |
| 615 ['running', join(self.root_dir, 'src', 'third_party', 'prout')]]) | 618 ['running', join(self.root_dir, 'src', 'third_party', 'prout')]]) |
| 616 out = self.svnBlockCleanup(out) | 619 out = self.svnBlockCleanup(out) |
| 617 self.checkString('other', out[0][1]) | 620 self.checkString('other', out[0][1]) |
| 618 self.checkString(join('third_party', 'fpp'), out[0][2]) | 621 self.checkString(join('third_party', 'fpp'), out[0][2]) |
| 619 self.checkString(join('third_party', 'prout'), out[0][3]) | 622 self.checkString(join('third_party', 'prout'), out[0][3]) |
| 620 self.checkString('hi', out[2][1]) | 623 self.checkString('hi', out[1][1]) |
| 621 self.assertEquals(4, len(out[0])) | 624 self.assertEquals(4, len(out[0])) |
| 622 self.assertEquals(1, len(out[1])) | 625 self.assertEquals(2, len(out[1])) |
| 623 self.assertEquals(2, len(out[2])) | 626 self.assertEquals(1, len(out[2])) |
| 624 self.assertEquals(1, len(out[3])) | 627 self.assertEquals(1, len(out[3])) |
| 625 self.assertEquals(4, len(out)) | 628 self.assertEquals(4, len(out)) |
| 626 | 629 |
| 627 # Revert implies --force implies running hooks without looking at pattern | 630 # Revert implies --force implies running hooks without looking at pattern |
| 628 # matching. | 631 # matching. |
| 629 # TODO(maruel): In general, gclient revert output is wrong. It should output | 632 # TODO(maruel): In general, gclient revert output is wrong. It should output |
| 630 # the file list after some ___ running 'svn status' | 633 # the file list after some ___ running 'svn status' |
| 631 results = self.gclient(['revert', '--deps', 'mac', '--jobs', '1']) | 634 results = self.gclient(['revert', '--deps', 'mac', '--jobs', '1']) |
| 632 out = self.splitBlock(results[0]) | 635 out = self.splitBlock(results[0]) |
| 633 self.assertEquals(7, len(out)) | 636 self.assertEquals(7, len(out)) |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 ('trunk/third_party/foo@1', 'src/third_party/foo'), | 1044 ('trunk/third_party/foo@1', 'src/third_party/foo'), |
| 1042 ('trunk/other@2', 'src/other'))) | 1045 ('trunk/other@2', 'src/other'))) |
| 1043 tree['src/file/other/DEPS'] = ( | 1046 tree['src/file/other/DEPS'] = ( |
| 1044 self.FAKE_REPOS.svn_revs[2]['trunk/other/DEPS']) | 1047 self.FAKE_REPOS.svn_revs[2]['trunk/other/DEPS']) |
| 1045 tree['src/git_hooked1'] = 'git_hooked1' | 1048 tree['src/git_hooked1'] = 'git_hooked1' |
| 1046 tree['src/git_hooked2'] = 'git_hooked2' | 1049 tree['src/git_hooked2'] = 'git_hooked2' |
| 1047 tree['src/svn_hooked1'] = 'svn_hooked1' | 1050 tree['src/svn_hooked1'] = 'svn_hooked1' |
| 1048 self.assertTree(tree) | 1051 self.assertTree(tree) |
| 1049 | 1052 |
| 1050 def testMultiSolutionsJobs(self): | 1053 def testMultiSolutionsJobs(self): |
| 1051 print >> sys.stderr, ( | |
| 1052 'Warning: testMultiSolutionsJobs is temporarily disabled') | |
| 1053 return | |
| 1054 # unreachable code | |
| 1055 # pylint: disable=W0101 | |
| 1056 if not self.enabled: | 1054 if not self.enabled: |
| 1057 return | 1055 return |
| 1058 self.gclient(['config', '--spec', | 1056 self.gclient(['config', '--spec', |
| 1059 'solutions=[' | 1057 'solutions=[' |
| 1060 '{"name": "src",' | 1058 '{"name": "src",' |
| 1061 ' "url": "' + self.svn_base + 'trunk/src/"},' | 1059 ' "url": "' + self.svn_base + 'trunk/src/"},' |
| 1062 '{"name": "src-git",' | 1060 '{"name": "src-git",' |
| 1063 '"url": "' + self.git_base + 'repo_1"}]']) | 1061 '"url": "' + self.git_base + 'repo_1"}]']) |
| 1064 self.parseGclient(['sync', '--deps', 'mac', '--jobs', '8'], | 1062 # There is no guarantee that the ordering will be consistent. |
| 1065 ['running', 'running', 'running', | 1063 (stdout, stderr, returncode) = self.gclient( |
| 1066 # This is due to the way svn update is called for a single | 1064 ['sync', '--deps', 'mac', '--jobs', '8']) |
| 1067 # file when File() is used in a DEPS file. | 1065 stdout = self.untangle(stdout) |
| 1068 ('running', self.root_dir + '/src/file/other'), | 1066 self.checkString('', stderr) |
| 1069 'running', 'running', 'running', 'running', 'running', 'running', | 1067 self.assertEquals(0, returncode) |
| 1070 'running', 'running'], | 1068 results = self.splitBlock(stdout) |
| 1071 untangle=True) | 1069 self.assertEquals(12, len(results)) |
|
M-A Ruel
2011/10/11 02:29:36
This verifies that all 12 steps went on and the tr
| |
| 1072 tree = self.mangle_git_tree(('repo_1@2', 'src-git'), | 1070 tree = self.mangle_git_tree(('repo_1@2', 'src-git'), |
| 1073 ('repo_2@1', 'src/repo2'), | 1071 ('repo_2@1', 'src/repo2'), |
| 1074 ('repo_3@2', 'src/repo2/repo_renamed')) | 1072 ('repo_3@2', 'src/repo2/repo_renamed')) |
| 1075 tree.update(self.mangle_svn_tree( | 1073 tree.update(self.mangle_svn_tree( |
| 1076 ('trunk/src@2', 'src'), | 1074 ('trunk/src@2', 'src'), |
| 1077 ('trunk/third_party/foo@1', 'src/third_party/foo'), | 1075 ('trunk/third_party/foo@1', 'src/third_party/foo'), |
| 1078 ('trunk/other@2', 'src/other'))) | 1076 ('trunk/other@2', 'src/other'))) |
| 1079 tree['src/file/other/DEPS'] = ( | 1077 tree['src/file/other/DEPS'] = ( |
| 1080 self.FAKE_REPOS.svn_revs[2]['trunk/other/DEPS']) | 1078 self.FAKE_REPOS.svn_revs[2]['trunk/other/DEPS']) |
| 1081 tree['src/git_hooked1'] = 'git_hooked1' | 1079 tree['src/git_hooked1'] = 'git_hooked1' |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 | 1277 |
| 1280 if '-c' in sys.argv: | 1278 if '-c' in sys.argv: |
| 1281 COVERAGE = True | 1279 COVERAGE = True |
| 1282 sys.argv.remove('-c') | 1280 sys.argv.remove('-c') |
| 1283 if os.path.exists('.coverage'): | 1281 if os.path.exists('.coverage'): |
| 1284 os.remove('.coverage') | 1282 os.remove('.coverage') |
| 1285 os.environ['COVERAGE_FILE'] = os.path.join( | 1283 os.environ['COVERAGE_FILE'] = os.path.join( |
| 1286 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 1284 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
| 1287 '.coverage') | 1285 '.coverage') |
| 1288 unittest.main() | 1286 unittest.main() |
| OLD | NEW |