| 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 """Runs through isolate_test_cases.py all the tests cases in a google-test | 6 """Runs through isolate_test_cases.py all the tests cases in a google-test |
| 7 executable, grabs the failures and traces them to generate a new .isolate. | 7 executable, grabs the failures and traces them to generate a new .isolate. |
| 8 | 8 |
| 9 This scripts requires a .isolated file. This file is generated from a .isolate | 9 This scripts requires a .isolated file. This file is generated from a .isolate |
| 10 file. You can use 'GYP_DEFINES=test_isolation_mode=check ninja foo_test_run' to | 10 file. You can use 'GYP_DEFINES=test_isolation_mode=check ninja foo_test_run' to |
| 11 generate it. | 11 generate it. |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import json | 14 import json |
| 15 import logging | 15 import logging |
| 16 import os | 16 import os |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| 19 import tempfile | 19 import tempfile |
| 20 | 20 |
| 21 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 22 if not ROOT_DIR in sys.path: |
| 23 sys.path.insert(0, ROOT_DIR) |
| 24 |
| 21 import isolate | 25 import isolate |
| 22 import isolate_test_cases | 26 import isolate_test_cases |
| 27 import run_isolated |
| 23 import run_test_cases | 28 import run_test_cases |
| 24 | 29 |
| 25 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 26 | 30 |
| 27 | 31 |
| 28 def with_tempfile(function): | 32 def with_tempfile(function): |
| 29 """Creates a temporary file and calls the inner function.""" | 33 """Creates a temporary file and calls the inner function.""" |
| 30 def hook(*args, **kwargs): | 34 def hook(*args, **kwargs): |
| 31 handle, tempfilepath = tempfile.mkstemp(prefix='fix_test_cases') | 35 handle, tempfilepath = tempfile.mkstemp(prefix='fix_test_cases') |
| 32 os.close(handle) | 36 os.close(handle) |
| 33 try: | 37 try: |
| 34 return function(tempfilepath, *args, **kwargs) | 38 return function(tempfilepath, *args, **kwargs) |
| 35 finally: | 39 finally: |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 assert bool(retcode) == (failures is None or bool(failures)) | 119 assert bool(retcode) == (failures is None or bool(failures)) |
| 116 return success, failures | 120 return success, failures |
| 117 | 121 |
| 118 | 122 |
| 119 @with_tempfile | 123 @with_tempfile |
| 120 def trace_some(tempfilepath, isolated, test_cases, verbosity): | 124 def trace_some(tempfilepath, isolated, test_cases, verbosity): |
| 121 """Traces the test cases.""" | 125 """Traces the test cases.""" |
| 122 with open(tempfilepath, 'w') as f: | 126 with open(tempfilepath, 'w') as f: |
| 123 f.write('\n'.join(test_cases)) | 127 f.write('\n'.join(test_cases)) |
| 124 cmd = [ | 128 cmd = [ |
| 125 sys.executable, os.path.join(ROOT_DIR, 'isolate_test_cases.py'), | 129 sys.executable, os.path.join( |
| 130 ROOT_DIR, 'googletest', 'isolate_test_cases.py'), |
| 126 '--isolated', isolated, | 131 '--isolated', isolated, |
| 127 '--test-case-file', tempfilepath, | 132 '--test-case-file', tempfilepath, |
| 128 # Do not use --run-all here, we assume the test cases will pass inside the | 133 # Do not use --run-all here, we assume the test cases will pass inside the |
| 129 # checkout. | 134 # checkout. |
| 130 ] | 135 ] |
| 131 add_verbosity(cmd, verbosity) | 136 add_verbosity(cmd, verbosity) |
| 132 logging.debug(cmd) | 137 logging.debug(cmd) |
| 133 return subprocess.call(cmd) | 138 return subprocess.call(cmd) |
| 134 | 139 |
| 135 | 140 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 208 |
| 204 # Trace the test cases and update the .isolate file. | 209 # Trace the test cases and update the .isolate file. |
| 205 print('\nTracing the %d failing tests.' % len(failures)) | 210 print('\nTracing the %d failing tests.' % len(failures)) |
| 206 if trace_some(isolated, failures, verbosity): | 211 if trace_some(isolated, failures, verbosity): |
| 207 logging.info('The tracing itself failed.') | 212 logging.info('The tracing itself failed.') |
| 208 return False | 213 return False |
| 209 previous_failures.update(failures) | 214 previous_failures.update(failures) |
| 210 | 215 |
| 211 | 216 |
| 212 def main(): | 217 def main(): |
| 213 run_test_cases.run_isolated.disable_buffering() | 218 run_isolated.disable_buffering() |
| 214 parser = run_test_cases.OptionParserTestCases( | 219 parser = run_test_cases.OptionParserTestCases( |
| 215 usage='%prog <options> -s <something.isolated>') | 220 usage='%prog <options> -s <something.isolated>') |
| 216 parser.add_option( | 221 parser.add_option( |
| 217 '-s', '--isolated', | 222 '-s', '--isolated', |
| 218 help='The isolated file') | 223 help='The isolated file') |
| 219 options, args = parser.parse_args() | 224 options, args = parser.parse_args() |
| 220 | 225 |
| 221 if args: | 226 if args: |
| 222 parser.error('Unsupported arg: %s' % args) | 227 parser.error('Unsupported arg: %s' % args) |
| 223 isolate.parse_isolated_option(parser, options, os.getcwd(), True) | 228 isolate.parse_isolated_option(parser, options, os.getcwd(), True) |
| 224 | 229 |
| 225 _, command, test_cases = isolate_test_cases.safely_load_isolated( | 230 _, command, test_cases = isolate_test_cases.safely_load_isolated( |
| 226 parser, options) | 231 parser, options) |
| 227 if not command: | 232 if not command: |
| 228 parser.error('A command must be defined') | 233 parser.error('A command must be defined') |
| 229 if not test_cases: | 234 if not test_cases: |
| 230 parser.error('No test case to run') | 235 parser.error('No test case to run') |
| 231 return not fix_all(options.isolated, test_cases, options.verbose) | 236 return not fix_all(options.isolated, test_cases, options.verbose) |
| 232 | 237 |
| 233 | 238 |
| 234 if __name__ == '__main__': | 239 if __name__ == '__main__': |
| 235 sys.exit(main()) | 240 sys.exit(main()) |
| OLD | NEW |