| 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 """ |
| 11 | 11 |
| 12 import logging | 12 import logging |
| 13 import multiprocessing | 13 import multiprocessing |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import sys | 16 import sys |
| 17 import time | 17 import time |
| 18 | 18 |
| 19 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 20 if not ROOT_DIR in sys.path: |
| 21 sys.path.insert(0, ROOT_DIR) |
| 22 |
| 23 import run_isolated |
| 19 import run_test_cases | 24 import run_test_cases |
| 20 import trace_inputs | 25 import trace_inputs |
| 21 | 26 |
| 22 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 23 ROOT_DIR = os.path.dirname(os.path.dirname(BASE_DIR)) | |
| 24 | |
| 25 | 27 |
| 26 def sanitize_test_case_name(test_case): | 28 def sanitize_test_case_name(test_case): |
| 27 """Removes characters that are valid as test case names but invalid as file | 29 """Removes characters that are valid as test case names but invalid as file |
| 28 names. | 30 names. |
| 29 """ | 31 """ |
| 30 return test_case.replace('/', '-') | 32 return test_case.replace('/', '-') |
| 31 | 33 |
| 32 | 34 |
| 33 class Tracer(object): | 35 class Tracer(object): |
| 34 def __init__(self, tracer, cmd, cwd_dir, progress): | 36 def __init__(self, tracer, cmd, cwd_dir, progress): |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 trace_inputs.write_json( | 143 trace_inputs.write_json( |
| 142 outfile, | 144 outfile, |
| 143 results_processed, | 145 results_processed, |
| 144 len(results_processed) > 20) | 146 len(results_processed) > 20) |
| 145 if exception: | 147 if exception: |
| 146 raise exception[0], exception[1], exception[2] | 148 raise exception[0], exception[1], exception[2] |
| 147 | 149 |
| 148 | 150 |
| 149 def main(): | 151 def main(): |
| 150 """CLI frontend to validate arguments.""" | 152 """CLI frontend to validate arguments.""" |
| 151 run_test_cases.run_isolated.disable_buffering() | 153 run_isolated.disable_buffering() |
| 152 parser = run_test_cases.OptionParserTestCases( | 154 parser = run_test_cases.OptionParserTestCases( |
| 153 usage='%prog <options> [gtest]') | 155 usage='%prog <options> [gtest]') |
| 154 parser.format_description = lambda *_: parser.description | 156 parser.format_description = lambda *_: parser.description |
| 155 parser.add_option( | 157 parser.add_option( |
| 156 '-o', '--out', | 158 '-o', '--out', |
| 157 help='output file, defaults to <executable>.test_cases') | 159 help='output file, defaults to <executable>.test_cases') |
| 158 parser.add_option( | 160 parser.add_option( |
| 159 '-r', '--root-dir', | 161 '-r', '--root-dir', |
| 160 help='Root directory under which file access should be noted') | 162 help='Root directory under which file access should be noted') |
| 161 # TODO(maruel): Add support for options.timeout. | 163 # TODO(maruel): Add support for options.timeout. |
| 162 parser.remove_option('--timeout') | 164 parser.remove_option('--timeout') |
| 163 options, args = parser.parse_args() | 165 options, args = parser.parse_args() |
| 164 | 166 |
| 165 if not args: | 167 if not args: |
| 166 parser.error( | 168 parser.error( |
| 167 'Please provide the executable line to run, if you need fancy things ' | 169 'Please provide the executable line to run, if you need fancy things ' |
| 168 'like xvfb, start this script from *inside* xvfb, it\'ll be much faster' | 170 'like xvfb, start this script from *inside* xvfb, it\'ll be much faster' |
| 169 '.') | 171 '.') |
| 170 | 172 |
| 171 cmd = run_test_cases.fix_python_path(args) | 173 cmd = run_isolated.fix_python_path(args) |
| 172 cmd[0] = os.path.abspath(cmd[0]) | 174 cmd[0] = os.path.abspath(cmd[0]) |
| 173 if not os.path.isfile(cmd[0]): | 175 if not os.path.isfile(cmd[0]): |
| 174 parser.error('Tracing failed for: %s\nIt doesn\'t exit' % ' '.join(cmd)) | 176 parser.error('Tracing failed for: %s\nIt doesn\'t exit' % ' '.join(cmd)) |
| 175 | 177 |
| 176 if not options.out: | 178 if not options.out: |
| 177 options.out = '%s.test_cases' % cmd[-1] | 179 options.out = '%s.test_cases' % cmd[-1] |
| 178 options.out = os.path.abspath(options.out) | 180 options.out = os.path.abspath(options.out) |
| 179 if options.root_dir: | 181 if options.root_dir: |
| 180 options.root_dir = os.path.abspath(options.root_dir) | 182 options.root_dir = os.path.abspath(options.root_dir) |
| 181 logname = options.out + '.log' | 183 logname = options.out + '.log' |
| (...skipping 11 matching lines...) Expand all Loading... |
| 193 test_cases, | 195 test_cases, |
| 194 options.jobs, | 196 options.jobs, |
| 195 logname) | 197 logname) |
| 196 print('Reading trace logs...') | 198 print('Reading trace logs...') |
| 197 write_details(logname, options.out, options.root_dir, blacklist, results) | 199 write_details(logname, options.out, options.root_dir, blacklist, results) |
| 198 return 0 | 200 return 0 |
| 199 | 201 |
| 200 | 202 |
| 201 if __name__ == '__main__': | 203 if __name__ == '__main__': |
| 202 sys.exit(main()) | 204 sys.exit(main()) |
| OLD | NEW |