diff --git a/third_party/gtest-parallel/README.webrtc b/third_party/gtest-parallel/README.webrtc index 4d47151087..1f44e5e0f1 100644 --- a/third_party/gtest-parallel/README.webrtc +++ b/third_party/gtest-parallel/README.webrtc @@ -1,9 +1,13 @@ URL: https://github.com/google/gtest-parallel -Version: d0cebaba01c5dbf3af8a1c89b64eed7596c2b56c +Version: 89b859c1412089468599a3366a72a1e774ce5c2c License: Apache 2.0 License File: LICENSE Description: Parallelization script for gtest binaries. -Local Modifications: None +Local Modifications: +Added gtest-parallel-wrapper.py to convert the GTEST_SHARD_INDEX and +GTEST_TOTAL_SHARDS environment variables to flags, since gtest-parallel takes +flags as arguments, and delete them afterwards, since letting them set +introduces a bug where only tests in the first shard are executed. diff --git a/third_party/gtest-parallel/gtest-parallel b/third_party/gtest-parallel/gtest-parallel index 5c4d44e63b..778a29a077 100755 --- a/third_party/gtest-parallel/gtest-parallel +++ b/third_party/gtest-parallel/gtest-parallel @@ -265,16 +265,13 @@ parser.add_option('--gtest_also_run_disabled_tests', action='store_true', parser.add_option('--format', type='string', default='filter', help='output format (raw,filter)') parser.add_option('--print_test_times', action='store_true', default=False, - help='When done, list the run time of each test') -parser.add_option('--shard_count', type='int', - default=int(os.environ.pop('GTEST_TOTAL_SHARDS', 1)), - help=('Total number of shards (for sharding test execution ' - 'between multiple machines). Default: %default')) -parser.add_option('--shard_index', type='int', - default=int(os.environ.pop('GTEST_SHARD_INDEX', 0)), - help=('Zero-indexed number identifying this shard (for ' - 'sharding test execution between multiple machines). ' - 'Default: %default')) + help='list the run time of each test at the end of execution') +parser.add_option('--shard_count', type='int', default=1, + help='total number of shards (for sharding test execution ' + 'between multiple machines)') +parser.add_option('--shard_index', type='int', default=0, + help='zero-indexed number identifying this shard (for ' + 'sharding test execution between multiple machines)') (options, binaries) = parser.parse_args() @@ -288,15 +285,15 @@ if options.format == 'raw': elif options.format == 'filter': logger = FilterFormat() else: - sys.exit("Unknown output format: " + options.format) + parser.error("Unknown output format: " + options.format) if options.shard_count < 1: - sys.exit("Invalid number of shards: %d. Must be at least 1." % - options.shard_count) -if options.shard_index < 0 or options.shard_count <= options.shard_index: - sys.exit("Invalid shard index: %d. Must be between 0 and %d." % - (options.shard_index, options.shard_count - 1)) - + parser.error("Invalid number of shards: %d. Must be at least 1." % + options.shard_count) +if not (0 <= options.shard_index < options.shard_count): + parser.error("Invalid shard index: %d. Must be between 0 and %d " + "(less than the number of shards)." % + (options.shard_index, options.shard_count - 1)) # Find tests. save_file = os.path.join(os.path.expanduser("~"), ".gtest-parallel-times") diff --git a/third_party/gtest-parallel/gtest-parallel-wrapper.py b/third_party/gtest-parallel/gtest-parallel-wrapper.py new file mode 100755 index 0000000000..1d8bcac713 --- /dev/null +++ b/third_party/gtest-parallel/gtest-parallel-wrapper.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import os +import subprocess +import sys + +# GTEST_SHARD_INDEX and GTEST_TOTAL_SHARDS must be removed from the environment +# otherwise it will be picked up by the binary, causing a bug where only tests +# in the firsh shard are executed. +test_env = os.environ.copy() +gtest_shard_index = test_env.pop('GTEST_SHARD_INDEX', '0') +gtest_total_shards = test_env.pop('GTEST_TOTAL_SHARDS', '1') + +gtest_parallel_path = os.path.dirname(os.path.abspath(__file__)) +gtest_parallel_path = os.path.join(gtest_parallel_path, 'gtest-parallel') + +command = [ + sys.executable, + gtest_parallel_path, + '--shard_count', + gtest_total_shards, + '--shard_index', + gtest_shard_index, +] + sys.argv[1:] + +print 'gtest-parallel-wrapper: Executing command %s' % ' '.join(command) +sys.stdout.flush() + +sys.exit(subprocess.call(command, env=test_env, cwd=os.getcwd())) diff --git a/tools/mb/mb.py b/tools/mb/mb.py index 19926c9803..02070c52db 100755 --- a/tools/mb/mb.py +++ b/tools/mb/mb.py @@ -1117,22 +1117,22 @@ class MetaBuildWrapper(object): '../../testing/test_env.py', '../../testing/xvfb.py', '../../third_party/gtest-parallel/gtest-parallel', + '../../third_party/gtest-parallel/gtest-parallel-wrapper.py', ] cmdline = [ - '../../testing/xvfb.py', - '.', - 'python', - '../../third_party/gtest-parallel/gtest-parallel', + '../../testing/xvfb.py', + '.', + '../../third_party/gtest-parallel/gtest-parallel-wrapper.py', ] + common_cmdline elif test_type in ('windowed_test_launcher', 'console_test_launcher'): extra_files = [ '../../testing/test_env.py', '../../third_party/gtest-parallel/gtest-parallel', + '../../third_party/gtest-parallel/gtest-parallel-wrapper.py', ] cmdline = [ '../../testing/test_env.py', - 'python', - '../../third_party/gtest-parallel/gtest-parallel', + '../../third_party/gtest-parallel/gtest-parallel-wrapper.py', ] + common_cmdline elif test_type == 'non_parallel_console_test_launcher': extra_files = [