blob: c9718e2bebba11994fd6a003b0b18082d6e56bb1 [file] [log] [blame]
ehmaldonado3ff7a952017-03-29 09:42:32 -07001#!/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"""
12This script acts as an interface between the Chromium infrastructure and
13gtest-parallel, renaming options and translating environment variables into
14flags. Developers should execute gtest-parallel directly.
15
16In particular, this translates the GTEST_SHARD_INDEX and GTEST_TOTAL_SHARDS
17environment variables to the --shard_index and --shard_count flags, and renames
18the --isolated-script-test-output flag to --dump_json_test_results.
19
20Note that the flags unprocessed by this script will passed as arguments to the
21test 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
29will 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
40import argparse
41import os
42import subprocess
43import 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.
48test_env = os.environ.copy()
49gtest_shard_index = test_env.pop('GTEST_SHARD_INDEX', '0')
50gtest_total_shards = test_env.pop('GTEST_TOTAL_SHARDS', '1')
51
52webrtc_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
53gtest_parallel_path = os.path.join(webrtc_root, 'third_party', 'gtest-parallel',
54 'gtest-parallel')
55
56# Ignore '--'. Options unprocessed by this script will be passed to the test as
57# arguments.
58if '--' in sys.argv:
59 del sys.argv[sys.argv.index('--')]
60
61parser = argparse.ArgumentParser()
62parser.add_argument('--isolated-script-test-output', type=str, default=None)
63parser.add_argument('--output_dir', type=str, default=None)
64parser.add_argument('--timeout', type=int, default=None)
65
66options, unprocessed = parser.parse_known_args()
67test_executable = unprocessed[0]
68test_arguments = unprocessed[1:]
69
70gtest_args = [
71 test_executable,
72 '--shard_count',
73 gtest_total_shards,
74 '--shard_index',
75 gtest_shard_index,
76]
77
78# --isolated-script-test-output is used to upload results to the flakiness
79# dashboard. This translation is made because gtest-parallel expects the flag to
80# be called --dump_json_test_results instead.
81if options.isolated_script_test_output:
82 gtest_args += [
83 '--dump_json_test_results',
84 options.isolated_script_test_output,
85 ]
86
87if options.output_dir:
88 gtest_args += [
89 '--output_dir',
90 options.output_dir,
91 ]
92
93if options.timeout:
94 gtest_args += [
95 '--timeout',
96 str(options.timeout),
97 ]
98
99command = [
100 sys.executable,
101 gtest_parallel_path,
102] + gtest_args + ['--'] + test_arguments
103
104print 'gtest-parallel-wrapper: Executing command %s' % ' '.join(command)
105sys.stdout.flush()
106
107sys.exit(subprocess.call(command, env=test_env, cwd=os.getcwd()))