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 benchmark. |
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: |
(...skipping 26 matching lines...) Expand all Loading... |
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=argparse.FileType('w'), |
46 required=True) | 46 required=True) |
| 47 parser.add_argument( |
| 48 '--isolated-script-test-chartjson-output', type=argparse.FileType('w'), |
| 49 required=False) |
47 parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') | 50 parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') |
48 args, rest_args = parser.parse_known_args() | 51 args, rest_args = parser.parse_known_args() |
49 xvfb_proc = None | 52 xvfb_proc = None |
50 openbox_proc = None | 53 openbox_proc = None |
51 xcompmgr_proc = None | 54 xcompmgr_proc = None |
52 env = os.environ.copy() | 55 env = os.environ.copy() |
53 # Assume we want to set up the sandbox environment variables all the | 56 # 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 | 57 # time; doing so is harmless on non-Linux platforms and is needed |
55 # all the time on Linux. | 58 # all the time on Linux. |
56 env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH | 59 env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH |
57 if args.xvfb and xvfb.should_start_xvfb(env): | 60 if args.xvfb and xvfb.should_start_xvfb(env): |
58 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, | 61 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, |
59 build_dir='.') | 62 build_dir='.') |
60 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' | 63 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' |
61 try: | 64 try: |
62 tempfile_dir = tempfile.mkdtemp('telemetry') | 65 tempfile_dir = tempfile.mkdtemp('telemetry') |
63 valid = True | 66 valid = True |
64 failures = [] | 67 failures = [] |
| 68 chartjson = (args.isolated_script_test_chartjson_output is not None and |
| 69 '--output-format=chartjson' in rest_args) |
| 70 chartresults = None |
65 try: | 71 try: |
66 rc = common.run_command([sys.executable] + rest_args + [ | 72 rc = common.run_command([sys.executable] + rest_args + [ |
67 '--output-dir', tempfile_dir, | 73 '--output-dir', tempfile_dir, |
68 '--output-format=json' | 74 '--output-format=json' |
69 ], env=env) | 75 ], env=env) |
70 tempfile_name = os.path.join(tempfile_dir, 'results.json') | 76 tempfile_name = os.path.join(tempfile_dir, 'results.json') |
71 with open(tempfile_name) as f: | 77 with open(tempfile_name) as f: |
72 results = json.load(f) | 78 results = json.load(f) |
73 for value in results['per_page_values']: | 79 for value in results['per_page_values']: |
74 if value['type'] == 'failure': | 80 if value['type'] == 'failure': |
75 failures.append(results['pages'][str(value['page_id'])]['name']) | 81 failures.append(results['pages'][str(value['page_id'])]['name']) |
76 valid = bool(rc == 0 or failures) | 82 valid = bool(rc == 0 or failures) |
| 83 # If we have also output chartjson read it in and return it. |
| 84 # results-chart.json is the file name output by telemetry when the |
| 85 # chartjson output format is included |
| 86 if chartjson: |
| 87 chart_tempfile_name = os.path.join(tempfile_dir, 'results-chart.json') |
| 88 with open(chart_tempfile_name) as f: |
| 89 chartresults = json.load(f) |
77 except Exception: | 90 except Exception: |
78 traceback.print_exc() | 91 traceback.print_exc() |
79 valid = False | 92 valid = False |
80 finally: | 93 finally: |
81 shutil.rmtree(tempfile_dir) | 94 shutil.rmtree(tempfile_dir) |
82 | 95 |
83 if not valid and not failures: | 96 if not valid and not failures: |
84 failures = ['(entire test suite)'] | 97 failures = ['(entire test suite)'] |
85 if rc == 0: | 98 if rc == 0: |
86 rc = 1 # Signal an abnormal exit. | 99 rc = 1 # Signal an abnormal exit. |
87 | 100 |
| 101 if chartjson: |
| 102 json.dump(chartresults, args.isolated_script_test_chartjson_output) |
| 103 |
88 json.dump({ | 104 json.dump({ |
89 'valid': valid, | 105 'valid': valid, |
90 'failures': failures, | 106 'failures': failures |
91 }, args.isolated_script_test_output) | 107 }, args.isolated_script_test_output) |
92 return rc | 108 return rc |
93 | 109 |
94 finally: | 110 finally: |
95 xvfb.kill(xvfb_proc) | 111 xvfb.kill(xvfb_proc) |
96 xvfb.kill(openbox_proc) | 112 xvfb.kill(openbox_proc) |
97 xvfb.kill(xcompmgr_proc) | 113 xvfb.kill(xcompmgr_proc) |
98 | 114 |
99 | 115 |
100 # This is not really a "script test" so does not need to manually add | 116 # This is not really a "script test" so does not need to manually add |
101 # any additional compile targets. | 117 # any additional compile targets. |
102 def main_compile_targets(args): | 118 def main_compile_targets(args): |
103 json.dump([], args.output) | 119 json.dump([], args.output) |
104 | 120 |
105 | 121 |
106 if __name__ == '__main__': | 122 if __name__ == '__main__': |
107 # Conform minimally to the protocol defined by ScriptTest. | 123 # Conform minimally to the protocol defined by ScriptTest. |
108 if 'compile_targets' in sys.argv: | 124 if 'compile_targets' in sys.argv: |
109 funcs = { | 125 funcs = { |
110 'run': None, | 126 'run': None, |
111 'compile_targets': main_compile_targets, | 127 'compile_targets': main_compile_targets, |
112 } | 128 } |
113 sys.exit(common.run_script(sys.argv[1:], funcs)) | 129 sys.exit(common.run_script(sys.argv[1:], funcs)) |
114 sys.exit(main()) | 130 sys.exit(main()) |
OLD | NEW |