| 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 """Traces each test cases of a google-test executable individually. | 6 """Traces each test cases of a google-test executable individually. |
| 7 | 7 |
| 8 Gives detailed information about each test case. The logs can be read afterward | 8 Gives detailed information about each test case. The logs can be read afterward |
| 9 with ./trace_inputs.py read -l /path/to/executable.logs | 9 with ./trace_inputs.py read -l /path/to/executable.logs |
| 10 """ | 10 """ |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return 0 | 167 return 0 |
| 168 | 168 |
| 169 | 169 |
| 170 def main(): | 170 def main(): |
| 171 """CLI frontend to validate arguments.""" | 171 """CLI frontend to validate arguments.""" |
| 172 default_variables = [('OS', isolate.get_flavor())] | 172 default_variables = [('OS', isolate.get_flavor())] |
| 173 if sys.platform in ('win32', 'cygwin'): | 173 if sys.platform in ('win32', 'cygwin'): |
| 174 default_variables.append(('EXECUTABLE_SUFFIX', '.exe')) | 174 default_variables.append(('EXECUTABLE_SUFFIX', '.exe')) |
| 175 else: | 175 else: |
| 176 default_variables.append(('EXECUTABLE_SUFFIX', '')) | 176 default_variables.append(('EXECUTABLE_SUFFIX', '')) |
| 177 parser = run_test_cases.OptionParserWithTestShardingAndFiltering( | 177 parser = run_test_cases.OptionParserTestCases( |
| 178 usage='%prog <options> [gtest]', | 178 usage='%prog <options> [gtest]', |
| 179 description=sys.modules['__main__'].__doc__) | 179 description=sys.modules['__main__'].__doc__) |
| 180 parser.format_description = lambda *_: parser.description | 180 parser.format_description = lambda *_: parser.description |
| 181 parser.add_option( | 181 parser.add_option( |
| 182 '-c', '--cwd', | 182 '-c', '--cwd', |
| 183 default='', | 183 default='', |
| 184 help='Signal to start the process from this relative directory. When ' | 184 help='Signal to start the process from this relative directory. When ' |
| 185 'specified, outputs the inputs files in a way compatible for ' | 185 'specified, outputs the inputs files in a way compatible for ' |
| 186 'gyp processing. Should be set to the relative path containing the ' | 186 'gyp processing. Should be set to the relative path containing the ' |
| 187 'gyp file, e.g. \'chrome\' or \'net\'') | 187 'gyp file, e.g. \'chrome\' or \'net\'') |
| 188 parser.add_option( | 188 parser.add_option( |
| 189 '-V', '--variable', | 189 '-V', '--variable', |
| 190 nargs=2, | 190 nargs=2, |
| 191 action='append', | 191 action='append', |
| 192 default=default_variables, | 192 default=default_variables, |
| 193 dest='variables', | 193 dest='variables', |
| 194 metavar='FOO BAR', | 194 metavar='FOO BAR', |
| 195 help='Variables to process in the .isolate file, default: %default') | 195 help='Variables to process in the .isolate file, default: %default') |
| 196 parser.add_option( | 196 parser.add_option( |
| 197 '--root-dir', | 197 '--root-dir', |
| 198 default=ROOT_DIR, | 198 default=ROOT_DIR, |
| 199 help='Root directory to base everything off. Default: %default') | 199 help='Root directory to base everything off. Default: %default') |
| 200 parser.add_option( | 200 parser.add_option( |
| 201 '-o', '--out', | 201 '-o', '--out', |
| 202 help='output file, defaults to <executable>.test_cases') | 202 help='output file, defaults to <executable>.test_cases') |
| 203 parser.add_option( | |
| 204 '-j', '--jobs', | |
| 205 type='int', | |
| 206 help='number of parallel jobs') | |
| 207 parser.add_option( | |
| 208 '-t', '--timeout', | |
| 209 default=120, | |
| 210 type='int', | |
| 211 help='number of parallel jobs') | |
| 212 options, args = parser.parse_args() | 203 options, args = parser.parse_args() |
| 213 | 204 |
| 214 if len(args) != 1: | 205 if len(args) != 1: |
| 215 parser.error( | 206 parser.error( |
| 216 'Please provide the executable line to run, if you need fancy things ' | 207 'Please provide the executable line to run, if you need fancy things ' |
| 217 'like xvfb, start this script from *inside* xvfb, it\'ll be much faster' | 208 'like xvfb, start this script from *inside* xvfb, it\'ll be much faster' |
| 218 '.') | 209 '.') |
| 219 | 210 |
| 220 options.root_dir = os.path.abspath(options.root_dir) | 211 options.root_dir = os.path.abspath(options.root_dir) |
| 221 if not os.path.isdir(options.root_dir): | 212 if not os.path.isdir(options.root_dir): |
| 222 parser.error('--root-dir "%s" must exist' % options.root_dir) | 213 parser.error('--root-dir "%s" must exist' % options.root_dir) |
| 223 if not os.path.isdir(os.path.join(options.root_dir, options.cwd)): | 214 if not os.path.isdir(os.path.join(options.root_dir, options.cwd)): |
| 224 parser.error( | 215 parser.error( |
| 225 '--cwd "%s" must be an existing directory relative to %s' % | 216 '--cwd "%s" must be an existing directory relative to %s' % |
| 226 (options.cwd, options.root_dir)) | 217 (options.cwd, options.root_dir)) |
| 227 | 218 |
| 228 executable = args[0] | 219 executable = args[0] |
| 229 if not os.path.isabs(executable): | 220 if not os.path.isabs(executable): |
| 230 executable = os.path.abspath(os.path.join(options.root_dir, executable)) | 221 executable = os.path.abspath(os.path.join(options.root_dir, executable)) |
| 231 if not os.path.isfile(executable): | 222 if not os.path.isfile(executable): |
| 232 parser.error('"%s" doesn\'t exist.' % executable) | 223 parser.error('"%s" doesn\'t exist.' % executable) |
| 233 | 224 |
| 234 if not options.out: | 225 if not options.out: |
| 235 options.out = '%s.test_cases' % executable | 226 options.out = '%s.test_cases' % executable |
| 236 | 227 |
| 237 # First, grab the test cases. | 228 test_cases = parser.process_gtest_options(executable, options) |
| 238 if options.test_case_file: | |
| 239 with open(options.test_case_file, 'r') as f: | |
| 240 test_cases = filter(None, f.read().splitlines()) | |
| 241 else: | |
| 242 test_cases = run_test_cases.get_test_cases( | |
| 243 executable, | |
| 244 options.whitelist, | |
| 245 options.blacklist, | |
| 246 options.index, | |
| 247 options.shards) | |
| 248 | 229 |
| 249 # Then run them. | 230 # Then run them. |
| 250 return trace_test_cases( | 231 return trace_test_cases( |
| 251 executable, | 232 executable, |
| 252 options.root_dir, | 233 options.root_dir, |
| 253 options.cwd, | 234 options.cwd, |
| 254 dict(options.variables), | 235 dict(options.variables), |
| 255 test_cases, | 236 test_cases, |
| 256 options.jobs, | 237 options.jobs, |
| 257 # TODO(maruel): options.timeout, | 238 # TODO(maruel): options.timeout, |
| 258 options.out) | 239 options.out) |
| 259 | 240 |
| 260 | 241 |
| 261 if __name__ == '__main__': | 242 if __name__ == '__main__': |
| 262 sys.exit(main()) | 243 sys.exit(main()) |
| OLD | NEW |