OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs an isolate bundled Telemetry benchmark. | 6 """Runs an isolate bundled Telemetry GPU integration test. |
7 | 7 |
8 This script attempts to emulate the contract of gtest-style tests | 8 This script attempts to emulate the contract of gtest-style tests |
9 invoked via recipes. The main contract is that the caller passes the | 9 invoked via recipes. The main contract is that the caller passes the |
10 argument: | 10 argument: |
11 | 11 |
12 --isolated-script-test-output=[FILENAME] | 12 --isolated-script-test-output=[FILENAME] |
13 | 13 |
14 json is written to that file in the format produced by | 14 json is written to that file in the format produced by |
15 common.parse_common_test_results. | 15 common.parse_common_test_results. |
16 | 16 |
(...skipping 18 matching lines...) Expand all Loading... |
35 | 35 |
36 # Unfortunately we need to copy these variables from ../test_env.py. | 36 # Unfortunately we need to copy these variables from ../test_env.py. |
37 # Importing it and using its get_sandbox_env breaks test runs on Linux | 37 # Importing it and using its get_sandbox_env breaks test runs on Linux |
38 # (it seems to unset DISPLAY). | 38 # (it seems to unset DISPLAY). |
39 CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX' | 39 CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX' |
40 CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox' | 40 CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox' |
41 | 41 |
42 def main(): | 42 def main(): |
43 parser = argparse.ArgumentParser() | 43 parser = argparse.ArgumentParser() |
44 parser.add_argument( | 44 parser.add_argument( |
45 '--isolated-script-test-output', type=argparse.FileType('w'), | 45 '--isolated-script-test-output', type=str, |
46 required=True) | 46 required=True) |
47 parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') | 47 parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') |
48 args, rest_args = parser.parse_known_args() | 48 args, rest_args = parser.parse_known_args() |
49 xvfb_proc = None | 49 xvfb_proc = None |
50 openbox_proc = None | 50 openbox_proc = None |
51 xcompmgr_proc = None | 51 xcompmgr_proc = None |
52 env = os.environ.copy() | 52 env = os.environ.copy() |
53 # Assume we want to set up the sandbox environment variables all the | 53 # Assume we want to set up the sandbox environment variables all the |
54 # time; doing so is harmless on non-Linux platforms and is needed | 54 # time; doing so is harmless on non-Linux platforms and is needed |
55 # all the time on Linux. | 55 # all the time on Linux. |
56 env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH | 56 env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH |
57 if args.xvfb and xvfb.should_start_xvfb(env): | 57 if args.xvfb and xvfb.should_start_xvfb(env): |
58 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, | 58 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, |
59 build_dir='.') | 59 build_dir='.') |
60 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' | 60 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' |
| 61 # Compatibility with gtest-based sharding. |
| 62 total_shards = None |
| 63 shard_index = None |
| 64 if 'GTEST_TOTAL_SHARDS' in env: |
| 65 total_shards = int(env['GTEST_TOTAL_SHARDS']) |
| 66 del env['GTEST_TOTAL_SHARDS'] |
| 67 if 'GTEST_SHARD_INDEX' in env: |
| 68 shard_index = int(env['GTEST_SHARD_INDEX']) |
| 69 del env['GTEST_SHARD_INDEX'] |
| 70 sharding_args = [] |
| 71 if total_shards is not None and shard_index is not None: |
| 72 sharding_args = [ |
| 73 '--total-shards=%d' % total_shards, |
| 74 '--shard-index=%d' % shard_index |
| 75 ] |
61 try: | 76 try: |
62 tempfile_dir = tempfile.mkdtemp('telemetry') | |
63 valid = True | 77 valid = True |
64 failures = [] | 78 rc = 0 |
65 try: | 79 try: |
66 rc = common.run_command([sys.executable] + rest_args + [ | 80 rc = common.run_command([sys.executable] + rest_args + sharding_args + [ |
67 '--output-dir', tempfile_dir, | 81 '--write-abbreviated-json-results-to', args.isolated_script_test_output, |
68 '--output-format=json' | |
69 ], env=env) | 82 ], env=env) |
70 tempfile_name = os.path.join(tempfile_dir, 'results.json') | 83 valid = bool(rc == 0) |
71 with open(tempfile_name) as f: | |
72 results = json.load(f) | |
73 for value in results['per_page_values']: | |
74 if value['type'] == 'failure': | |
75 failures.append(results['pages'][str(value['page_id'])]['name']) | |
76 valid = bool(rc == 0 or failures) | |
77 except Exception: | 84 except Exception: |
78 traceback.print_exc() | 85 traceback.print_exc() |
79 valid = False | 86 valid = False |
80 finally: | |
81 shutil.rmtree(tempfile_dir) | |
82 | 87 |
83 if not valid and not failures: | 88 if not valid: |
84 failures = ['(entire test suite)'] | 89 failures = ['(entire test suite)'] |
85 if rc == 0: | 90 with open(args.isolated_script_test_output, 'w') as fp: |
86 rc = 1 # Signal an abnormal exit. | 91 json.dump({ |
| 92 'valid': valid, |
| 93 'failures': failures, |
| 94 }, fp) |
87 | 95 |
88 json.dump({ | |
89 'valid': valid, | |
90 'failures': failures, | |
91 }, args.isolated_script_test_output) | |
92 return rc | 96 return rc |
93 | 97 |
94 finally: | 98 finally: |
95 xvfb.kill(xvfb_proc) | 99 xvfb.kill(xvfb_proc) |
96 xvfb.kill(openbox_proc) | 100 xvfb.kill(openbox_proc) |
97 xvfb.kill(xcompmgr_proc) | 101 xvfb.kill(xcompmgr_proc) |
98 | 102 |
99 | 103 |
100 # This is not really a "script test" so does not need to manually add | 104 # This is not really a "script test" so does not need to manually add |
101 # any additional compile targets. | 105 # any additional compile targets. |
102 def main_compile_targets(args): | 106 def main_compile_targets(args): |
103 json.dump([], args.output) | 107 json.dump([], args.output) |
104 | 108 |
105 | 109 |
106 if __name__ == '__main__': | 110 if __name__ == '__main__': |
107 # Conform minimally to the protocol defined by ScriptTest. | 111 # Conform minimally to the protocol defined by ScriptTest. |
108 if 'compile_targets' in sys.argv: | 112 if 'compile_targets' in sys.argv: |
109 funcs = { | 113 funcs = { |
110 'run': None, | 114 'run': None, |
111 'compile_targets': main_compile_targets, | 115 'compile_targets': main_compile_targets, |
112 } | 116 } |
113 sys.exit(common.run_script(sys.argv[1:], funcs)) | 117 sys.exit(common.run_script(sys.argv[1:], funcs)) |
114 sys.exit(main()) | 118 sys.exit(main()) |
OLD | NEW |