Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Scripts to run a test, grab the failures and trace them.""" | 6 """Scripts to run a test, grab the failures and trace them.""" |
| 7 | 7 |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import subprocess | 10 import subprocess |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 | 55 |
| 56 Assumes run_test_cases.py is implicitly called. | 56 Assumes run_test_cases.py is implicitly called. |
| 57 """ | 57 """ |
| 58 handle, result_file = tempfile.mkstemp(prefix='run_test_cases') | 58 handle, result_file = tempfile.mkstemp(prefix='run_test_cases') |
| 59 os.close(handle) | 59 os.close(handle) |
| 60 env = os.environ.copy() | 60 env = os.environ.copy() |
| 61 env['RUN_TEST_CASES_RESULT_FILE'] = result_file | 61 env['RUN_TEST_CASES_RESULT_FILE'] = result_file |
| 62 env['GTEST_SHARD_INDEX'] = str(shard_index) | 62 env['GTEST_SHARD_INDEX'] = str(shard_index) |
| 63 env['GTEST_TOTAL_SHARDS'] = str(shard_count) | 63 env['GTEST_TOTAL_SHARDS'] = str(shard_count) |
| 64 cmd = [sys.executable, 'isolate.py', 'run', '-r', result] | 64 cmd = [sys.executable, 'isolate.py', 'run', '-r', result] |
| 65 return_code = subprocess.call(cmd, env=env) | 65 subprocess.call(cmd, env=env) |
| 66 if not os.path.isfile(result_file): | 66 if not os.path.isfile(result_file): |
| 67 print >> sys.stderr, 'Failed to find %s' % result_file | 67 print >> sys.stderr, 'Failed to find %s' % result_file |
| 68 return None | 68 return None |
| 69 if return_code: | |
| 70 print >> sys.stderr, 'Failed to run isolate.py run' | |
| 71 return None | |
| 72 with open(result_file) as f: | 69 with open(result_file) as f: |
| 73 try: | 70 try: |
| 74 data = json.load(f) | 71 data = json.load(f) |
| 75 except ValueError as e: | 72 except ValueError as e: |
| 76 print >> sys.stderr, ('Unable to load json file, %s: %s' % | 73 print >> sys.stderr, ('Unable to load json file, %s: %s' % |
| 77 (result_file, str(e))) | 74 (result_file, str(e))) |
| 78 return None | 75 return None |
| 79 os.remove(result_file) | 76 os.remove(result_file) |
| 80 return [ | 77 return [ |
| 81 test for test, runs in data.iteritems() | 78 test for test, runs in data.iteritems() |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 164 |
| 168 def main(): | 165 def main(): |
| 169 parser = run_test_cases.OptionParserWithTestSharding( | 166 parser = run_test_cases.OptionParserWithTestSharding( |
| 170 usage='%prog <option> [test]') | 167 usage='%prog <option> [test]') |
| 171 options, args = parser.parse_args() | 168 options, args = parser.parse_args() |
| 172 | 169 |
| 173 if len(args) != 1: | 170 if len(args) != 1: |
| 174 parser.error('Use with the name of the test only, e.g. "unit_tests"') | 171 parser.error('Use with the name of the test only, e.g. "unit_tests"') |
| 175 | 172 |
| 176 basename = args[0] | 173 basename = args[0] |
| 177 executable = '../../out/Release/%s' % basename | 174 if sys.platform == 'win32' or sys.platform == 'cygwin': |
|
M-A Ruel
2012/08/27 14:21:51
if sys.platform in ('cygwin', 'win32'):
csharp
2012/08/27 15:52:41
Done.
| |
| 175 executable = '../../build/Release/%s' % basename | |
|
M-A Ruel
2012/08/27 14:21:51
Actually, that's kind of crappy, I'd rather remove
csharp
2012/08/27 15:52:41
Done.
| |
| 176 else: | |
| 177 executable = '../../out/Release/%s' % basename | |
| 178 result = '%s.results' % executable | 178 result = '%s.results' % executable |
| 179 if sys.platform == 'win32': | 179 if sys.platform == 'win32': |
|
M-A Ruel
2012/08/27 15:31:09
cygwin too. But I don't think tracing works.
csharp
2012/08/27 15:52:41
Done.
| |
| 180 executable += '.exe' | 180 executable += '.exe' |
| 181 if not os.path.isfile(executable): | 181 if not os.path.isfile(executable): |
| 182 print >> sys.stderr, ( | 182 print >> sys.stderr, ( |
| 183 '%s doesn\'t exist, please build %s_run' % (executable, basename)) | 183 '%s doesn\'t exist, please build %s_run' % (executable, basename)) |
| 184 return 1 | 184 return 1 |
| 185 if not os.path.isfile(result): | 185 if not os.path.isfile(result): |
| 186 print >> sys.stderr, ( | 186 print >> sys.stderr, ( |
| 187 '%s doesn\'t exist, please build %s_run' % (result, basename)) | 187 '%s doesn\'t exist, please build %s_run' % (result, basename)) |
| 188 return 1 | 188 return 1 |
| 189 | 189 |
| 190 return not fix_all(result, options.index, options.shards) | 190 return not fix_all(result, options.index, options.shards) |
| 191 | 191 |
| 192 | 192 |
| 193 if __name__ == '__main__': | 193 if __name__ == '__main__': |
| 194 sys.exit(main()) | 194 sys.exit(main()) |
| OLD | NEW |