OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python2 |
2 # Copyright 2013 Google Inc. All rights reserved. | 2 # Copyright 2013 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
7 # | 7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # | 9 # |
10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
11 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 parser.add_option('--gtest_color', type='string', default='yes', | 259 parser.add_option('--gtest_color', type='string', default='yes', |
260 help='color output') | 260 help='color output') |
261 parser.add_option('--gtest_filter', type='string', default='', | 261 parser.add_option('--gtest_filter', type='string', default='', |
262 help='test filter') | 262 help='test filter') |
263 parser.add_option('--gtest_also_run_disabled_tests', action='store_true', | 263 parser.add_option('--gtest_also_run_disabled_tests', action='store_true', |
264 default=False, help='run disabled tests too') | 264 default=False, help='run disabled tests too') |
265 parser.add_option('--format', type='string', default='filter', | 265 parser.add_option('--format', type='string', default='filter', |
266 help='output format (raw,filter)') | 266 help='output format (raw,filter)') |
267 parser.add_option('--print_test_times', action='store_true', default=False, | 267 parser.add_option('--print_test_times', action='store_true', default=False, |
268 help='When done, list the run time of each test') | 268 help='When done, list the run time of each test') |
269 parser.add_option('--shard-count', type='int', | 269 parser.add_option('--shard_count', type='int', |
270 default=int(os.environ.get('GTEST_TOTAL_SHARDS', 1)), | 270 default=int(os.environ.pop('GTEST_TOTAL_SHARDS', 1)), |
271 help=('Total number of shards (for sharding test execution ' | 271 help=('Total number of shards (for sharding test execution ' |
272 'between multiple machines). Default: %default')) | 272 'between multiple machines). Default: %default')) |
273 parser.add_option('--shard-index', type='int', | 273 parser.add_option('--shard_index', type='int', |
274 default=int(os.environ.get('GTEST_SHARD_INDEX', 0)), | 274 default=int(os.environ.pop('GTEST_SHARD_INDEX', 0)), |
275 help=('Zero-indexed number identifying this shard (for ' | 275 help=('Zero-indexed number identifying this shard (for ' |
276 'sharding test execution between multiple machines). ' | 276 'sharding test execution between multiple machines). ' |
277 'Default: %default')) | 277 'Default: %default')) |
278 | 278 |
279 (options, binaries) = parser.parse_args() | 279 (options, binaries) = parser.parse_args() |
280 | 280 |
281 if binaries == []: | 281 if binaries == []: |
282 parser.print_usage() | 282 parser.print_usage() |
283 sys.exit(1) | 283 sys.exit(1) |
284 | 284 |
285 logger = RawFormat() | 285 logger = RawFormat() |
286 if options.format == 'raw': | 286 if options.format == 'raw': |
287 pass | 287 pass |
288 elif options.format == 'filter': | 288 elif options.format == 'filter': |
289 logger = FilterFormat() | 289 logger = FilterFormat() |
290 else: | 290 else: |
291 sys.exit("Unknown output format: " + options.format) | 291 sys.exit("Unknown output format: " + options.format) |
292 | 292 |
| 293 if options.shard_count < 1: |
| 294 sys.exit("Invalid number of shards: %d. Must be at least 1." % |
| 295 options.shard_count) |
| 296 if options.shard_index < 0 or options.shard_count <= options.shard_index: |
| 297 sys.exit("Invalid shard index: %d. Must be between 0 and %d." % |
| 298 (options.shard_index, options.shard_count - 1)) |
| 299 |
| 300 |
293 # Find tests. | 301 # Find tests. |
294 save_file = os.path.join(os.path.expanduser("~"), ".gtest-parallel-times") | 302 save_file = os.path.join(os.path.expanduser("~"), ".gtest-parallel-times") |
295 times = TestTimes(save_file) | 303 times = TestTimes(save_file) |
296 tests = [] | 304 tests = [] |
297 for test_binary in binaries: | 305 for test_binary in binaries: |
298 command = [test_binary] | 306 command = [test_binary] |
299 if options.gtest_also_run_disabled_tests: | 307 if options.gtest_also_run_disabled_tests: |
300 command += ['--gtest_also_run_disabled_tests'] | 308 command += ['--gtest_also_run_disabled_tests'] |
301 | 309 |
302 list_command = list(command) | 310 list_command = list(command) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 [t.join() for t in workers] | 421 [t.join() for t in workers] |
414 logger.end() | 422 logger.end() |
415 times.write_to_file(save_file) | 423 times.write_to_file(save_file) |
416 if options.print_test_times: | 424 if options.print_test_times: |
417 ts = sorted((times.get_test_time(test_binary, test), test_binary, test) | 425 ts = sorted((times.get_test_time(test_binary, test), test_binary, test) |
418 for (_, test_binary, test, _) in tests | 426 for (_, test_binary, test, _) in tests |
419 if times.get_test_time(test_binary, test) is not None) | 427 if times.get_test_time(test_binary, test) is not None) |
420 for (time_ms, test_binary, test) in ts: | 428 for (time_ms, test_binary, test) in ts: |
421 print "%8s %s" % ("%dms" % time_ms, test) | 429 print "%8s %s" % ("%dms" % time_ms, test) |
422 sys.exit(-signal.SIGINT if sigint_handler.got_sigint() else exit_code) | 430 sys.exit(-signal.SIGINT if sigint_handler.got_sigint() else exit_code) |
OLD | NEW |