OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Runs a script that can run as an isolate (or not). | |
7 | |
8 The main requirement is that | |
9 | |
10 --isolated-script-test-output=[FILENAME] | |
11 | |
12 is passed on the command line to run_isolated_script_tests. This gets | |
13 remapped to the command line argument --write-full-results-to. | |
14 | |
15 json is written to that file in the format produced by | |
16 common.parse_common_test_results. | |
17 | |
18 For compatibility with //base/test/launcher-based tests, the script | |
19 will also remap the env vars GTEST_TOTAL_SHARDS and GTEST_SHARD_INDEX | |
20 to the command line arguments --total-shards and --shard-index. | |
21 | |
22 This script is intended to be the base command invoked by the isolate, | |
23 followed by a subsequent Python script. It could be generalized to | |
24 invoke an arbitrary executable. | |
25 """ | |
26 | |
27 import argparse | |
28 import json | |
29 import os | |
30 import pprint | |
31 import sys | |
32 | |
33 | |
34 import common | |
35 | |
36 # Add src/testing/ into sys.path for importing xvfb. | |
37 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
38 import xvfb | |
39 | |
40 | |
41 def main(): | |
42 parser = argparse.ArgumentParser() | |
43 parser.add_argument('--isolated-script-test-output', type=str, | |
44 required=True) | |
45 parser.add_argument('--shards', type=int, help='number of shards') | |
46 parser.add_argument('--xvfb', help='start xvfb', action='store_true') | |
47 | |
48 # This argument is ignored for now. | |
49 parser.add_argument('--isolated-script-test-chartjson-output', type=str) | |
50 | |
51 args, rest_args = parser.parse_known_args() | |
52 | |
53 sharding_args, env = _remap_gtest_env_vars(os.environ) | |
54 | |
55 cmd = [sys.executable] + rest_args + sharding_args | |
56 cmd += ['--write-full-results-to', args.isolated_script_test_output] | |
57 if args.xvfb: | |
58 return xvfb.run_executable(cmd, env) | |
59 else: | |
60 return common.run_command(cmd, env=env) | |
61 | |
62 | |
63 def _remap_gtest_env_vars(orig_env): | |
mithro
2017/01/31 23:51:42
run_webkit_tests.py already supports these GTEST a
Dirk Pranke
2017/02/01 01:32:51
I think both maruel@ and I consider the support fo
| |
64 total_shards = None | |
65 shard_index = None | |
66 env = orig_env.copy() | |
67 if 'GTEST_TOTAL_SHARDS' in env: | |
68 total_shards = int(env['GTEST_TOTAL_SHARDS']) | |
69 del env['GTEST_TOTAL_SHARDS'] | |
70 if 'GTEST_SHARD_INDEX' in env: | |
71 shard_index = int(env['GTEST_SHARD_INDEX']) | |
72 del env['GTEST_SHARD_INDEX'] | |
73 sharding_args = [] | |
74 if total_shards is not None and shard_index is not None: | |
75 sharding_args = [ | |
76 '--total-shards=%d' % total_shards, | |
77 '--shard-index=%d' % shard_index | |
78 ] | |
79 return sharding_args, env | |
80 | |
81 | |
82 | |
83 # This is not really a "script test" so does not need to manually add | |
84 # any additional compile targets. | |
85 def main_compile_targets(args): | |
86 json.dump([], args.output) | |
87 | |
88 | |
89 if __name__ == '__main__': | |
90 # Conform minimally to the protocol defined by ScriptTest. | |
91 if 'compile_targets' in sys.argv: | |
92 funcs = { | |
93 'run': None, | |
94 'compile_targets': main_compile_targets, | |
95 } | |
96 sys.exit(common.run_script(sys.argv[1:], funcs)) | |
97 sys.exit(main()) | |
OLD | NEW |