| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 4 # | 4 # |
| 5 # Use of this source code is governed by a BSD-style license | 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 | 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 | 7 # tree. An additional intellectual property rights grant can be found |
| 8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
| 9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 -- \ | 35 -- \ |
| 36 --unprocessed_arg_1 | 36 --unprocessed_arg_1 |
| 37 --unprocessed_arg_2 | 37 --unprocessed_arg_2 |
| 38 """ | 38 """ |
| 39 | 39 |
| 40 import argparse | 40 import argparse |
| 41 import os | 41 import os |
| 42 import subprocess | 42 import subprocess |
| 43 import sys | 43 import sys |
| 44 | 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 | 45 |
| 52 webrtc_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 46 def cat_files(file_list, output_file): |
| 53 gtest_parallel_path = os.path.join(webrtc_root, 'third_party', 'gtest-parallel', | 47 with open(output_file, 'w') as output_file: |
| 54 'gtest-parallel') | 48 for filename in file_list: |
| 49 with open(filename) as input_file: |
| 50 output_file.write(input_file.read()) |
| 51 os.remove(filename) |
| 55 | 52 |
| 56 # Ignore '--'. Options unprocessed by this script will be passed to the test as | |
| 57 # arguments. | |
| 58 if '--' in sys.argv: | |
| 59 del sys.argv[sys.argv.index('--')] | |
| 60 | 53 |
| 61 parser = argparse.ArgumentParser() | 54 def main(): |
| 62 parser.add_argument('--isolated-script-test-output', type=str, default=None) | 55 # Ignore '--'. Options unprocessed by this script will be passed to the test |
| 63 parser.add_argument('--output_dir', type=str, default=None) | 56 # as arguments. |
| 64 parser.add_argument('--timeout', type=int, default=None) | 57 if '--' in sys.argv: |
| 58 del sys.argv[sys.argv.index('--')] |
| 65 | 59 |
| 66 options, unprocessed = parser.parse_known_args() | 60 parser = argparse.ArgumentParser() |
| 67 test_executable = unprocessed[0] | 61 parser.add_argument('--isolated-script-test-output', type=str, default=None) |
| 68 test_arguments = unprocessed[1:] | 62 parser.add_argument('--output_dir', type=str, default=None) |
| 63 parser.add_argument('--timeout', type=int, default=None) |
| 69 | 64 |
| 70 gtest_args = [ | 65 # GTEST_SHARD_INDEX and GTEST_TOTAL_SHARDS must be removed from the |
| 71 test_executable, | 66 # environment. Otherwise it will be picked up by the binary, causing a bug |
| 72 '--shard_count', | 67 # where only tests in the first shard are executed. |
| 73 gtest_total_shards, | 68 test_env = os.environ.copy() |
| 74 '--shard_index', | 69 gtest_shard_index = test_env.pop('GTEST_SHARD_INDEX', '0') |
| 75 gtest_shard_index, | 70 gtest_total_shards = test_env.pop('GTEST_TOTAL_SHARDS', '1') |
| 76 ] | |
| 77 | 71 |
| 78 # --isolated-script-test-output is used to upload results to the flakiness | 72 webrtc_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 79 # dashboard. This translation is made because gtest-parallel expects the flag to | 73 gtest_parallel_path = os.path.join( |
| 80 # be called --dump_json_test_results instead. | 74 webrtc_root, 'third_party', 'gtest-parallel', 'gtest-parallel') |
| 81 if options.isolated_script_test_output: | 75 |
| 82 gtest_args += [ | 76 options, unprocessed = parser.parse_known_args() |
| 83 '--dump_json_test_results', | 77 test_executable = unprocessed[0] |
| 84 options.isolated_script_test_output, | 78 test_arguments = unprocessed[1:] |
| 79 |
| 80 gtest_args = [ |
| 81 test_executable, |
| 82 '--shard_count', |
| 83 gtest_total_shards, |
| 84 '--shard_index', |
| 85 gtest_shard_index, |
| 85 ] | 86 ] |
| 86 | 87 |
| 87 if options.output_dir: | 88 # --isolated-script-test-output is used to upload results to the flakiness |
| 88 gtest_args += [ | 89 # dashboard. This translation is made because gtest-parallel expects the flag |
| 89 '--output_dir', | 90 # to be called --dump_json_test_results instead. |
| 90 options.output_dir, | 91 if options.isolated_script_test_output: |
| 91 ] | 92 gtest_args += [ |
| 93 '--dump_json_test_results', |
| 94 options.isolated_script_test_output, |
| 95 ] |
| 92 | 96 |
| 93 if options.timeout: | 97 if options.output_dir: |
| 94 gtest_args += [ | 98 gtest_args += [ |
| 95 '--timeout', | 99 '--output_dir', |
| 96 str(options.timeout), | 100 options.output_dir, |
| 97 ] | 101 ] |
| 98 | 102 |
| 99 command = [ | 103 if options.timeout: |
| 100 sys.executable, | 104 gtest_args += [ |
| 101 gtest_parallel_path, | 105 '--timeout', |
| 102 ] + gtest_args + ['--'] + test_arguments | 106 str(options.timeout), |
| 107 ] |
| 103 | 108 |
| 104 print 'gtest-parallel-wrapper: Executing command %s' % ' '.join(command) | 109 command = [ |
| 105 sys.stdout.flush() | 110 sys.executable, |
| 111 gtest_parallel_path, |
| 112 ] + gtest_args + ['--'] + test_arguments |
| 106 | 113 |
| 107 sys.exit(subprocess.call(command, env=test_env, cwd=os.getcwd())) | 114 print 'gtest-parallel-wrapper: Executing command %s' % ' '.join(command) |
| 115 sys.stdout.flush() |
| 116 |
| 117 exit_code = subprocess.call(command, env=test_env, cwd=os.getcwd()) |
| 118 |
| 119 for test_status in 'passed', 'failed', 'interrupted': |
| 120 logs_dir = os.path.join(options.output_dir, test_status) |
| 121 if not os.path.isdir(logs_dir): |
| 122 continue |
| 123 logs = [os.path.join(logs_dir, log) for log in os.listdir(logs_dir)] |
| 124 log_file = os.path.join(options.output_dir, '%s-tests.log' % test_status) |
| 125 cat_files(logs, log_file) |
| 126 os.rmdir(logs_dir) |
| 127 |
| 128 return exit_code |
| 129 |
| 130 |
| 131 if __name__ == '__main__': |
| 132 sys.exit(main()) |
| OLD | NEW |