| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 4 # | |
| 5 # Use of this source code is governed by a BSD-style license | |
| 6 # that can be found in the LICENSE file in the root of the source | |
| 7 # tree. An additional intellectual property rights grant can be found | |
| 8 # in the file PATENTS. All contributing project authors may | |
| 9 # be found in the AUTHORS file in the root of the source tree. | |
| 10 | |
| 11 """ | |
| 12 This script acts as an interface between the Chromium infrastructure and | |
| 13 gtest-parallel, renaming options and translating environment variables into | |
| 14 flags. Developers should execute gtest-parallel directly. | |
| 15 | |
| 16 In particular, this translates the GTEST_SHARD_INDEX and GTEST_TOTAL_SHARDS | |
| 17 environment variables to the --shard_index and --shard_count flags, and renames | |
| 18 the --isolated-script-test-output flag to --dump_json_test_results. | |
| 19 | |
| 20 Note that the flags unprocessed by this script will passed as arguments to the | |
| 21 test executable, i.e. | |
| 22 | |
| 23 gtest-parallel-wrapper.py some_test \ | |
| 24 --isolated-script-test-output=some_dir \ | |
| 25 --unprocessed_arg_1 | |
| 26 -- \ | |
| 27 --unprocessed_arg_2 | |
| 28 | |
| 29 will be converted into | |
| 30 | |
| 31 python gtest-parallel some_test \ | |
| 32 --shard_count 1 \ | |
| 33 --shard_index 0 \ | |
| 34 --dump_json_test_results some_dir \ | |
| 35 -- \ | |
| 36 --unprocessed_arg_1 | |
| 37 --unprocessed_arg_2 | |
| 38 """ | |
| 39 | |
| 40 import argparse | |
| 41 import os | |
| 42 import subprocess | |
| 43 import sys | |
| 44 | |
| 45 # GTEST_SHARD_INDEX and GTEST_TOTAL_SHARDS must be removed from the environment | |
| 46 # otherwise it will be picked up by the binary, causing a bug where only tests | |
| 47 # in the firsh shard are executed. | |
| 48 test_env = os.environ.copy() | |
| 49 gtest_shard_index = test_env.pop('GTEST_SHARD_INDEX', '0') | |
| 50 gtest_total_shards = test_env.pop('GTEST_TOTAL_SHARDS', '1') | |
| 51 | |
| 52 gtest_parallel_path = os.path.dirname(os.path.abspath(__file__)) | |
| 53 gtest_parallel_path = os.path.join(gtest_parallel_path, 'gtest-parallel') | |
| 54 | |
| 55 # Ignore '--'. Options unprocessed by this script will be passed to the test as | |
| 56 # arguments. | |
| 57 if '--' in sys.argv: | |
| 58 del sys.argv[sys.argv.index('--')] | |
| 59 | |
| 60 parser = argparse.ArgumentParser() | |
| 61 parser.add_argument('--isolated-script-test-output', type=str, default=None) | |
| 62 | |
| 63 options, unprocessed = parser.parse_known_args() | |
| 64 test_executable = unprocessed[0] | |
| 65 test_arguments = unprocessed[1:] | |
| 66 | |
| 67 gtest_args = [ | |
| 68 test_executable, | |
| 69 '--shard_count', | |
| 70 gtest_total_shards, | |
| 71 '--shard_index', | |
| 72 gtest_shard_index, | |
| 73 ] | |
| 74 | |
| 75 # --isolated-script-test-output is used to upload results to the flakiness | |
| 76 # dashboard. This translation is made because gtest-parallel expects the flag to | |
| 77 # be called --dump_json_test_results instead. | |
| 78 if options.isolated_script_test_output: | |
| 79 gtest_args += [ | |
| 80 '--dump_json_test_results', | |
| 81 options.isolated_script_test_output, | |
| 82 ] | |
| 83 | |
| 84 command = [ | |
| 85 sys.executable, | |
| 86 gtest_parallel_path, | |
| 87 ] + gtest_args + ['--'] + test_arguments | |
| 88 | |
| 89 print 'gtest-parallel-wrapper: Executing command %s' % ' '.join(command) | |
| 90 sys.stdout.flush() | |
| 91 | |
| 92 sys.exit(subprocess.call(command, env=test_env, cwd=os.getcwd())) | |
| OLD | NEW |