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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 try: | 61 try: |
62 tempfile_dir = tempfile.mkdtemp('telemetry') | 62 tempfile_dir = tempfile.mkdtemp('telemetry') |
63 valid = True | 63 valid = True |
64 failures = [] | 64 failures = [] |
65 chartjson = False | |
66 if '--output-format=chartjson' in rest_args: | |
67 chartjson = True | |
68 chartresults = None | |
65 try: | 69 try: |
66 rc = common.run_command([sys.executable] + rest_args + [ | 70 rc = common.run_command([sys.executable] + rest_args + [ |
67 '--output-dir', tempfile_dir, | 71 '--output-dir', tempfile_dir, |
68 '--output-format=json' | 72 '--output-format=json' |
69 ], env=env) | 73 ], env=env) |
70 tempfile_name = os.path.join(tempfile_dir, 'results.json') | 74 tempfile_name = os.path.join(tempfile_dir, 'results.json') |
71 with open(tempfile_name) as f: | 75 with open(tempfile_name) as f: |
72 results = json.load(f) | 76 results = json.load(f) |
73 for value in results['per_page_values']: | 77 for value in results['per_page_values']: |
74 if value['type'] == 'failure': | 78 if value['type'] == 'failure': |
75 failures.append(results['pages'][str(value['page_id'])]['name']) | 79 failures.append(results['pages'][str(value['page_id'])]['name']) |
76 valid = bool(rc == 0 or failures) | 80 valid = bool(rc == 0 or failures) |
81 # If we have also output chartjson read it in and return it | |
82 if chartjson: | |
83 chart_tempfile_name = os.path.join(tempfile_dir, 'results-chart.json') | |
84 with open(chart_tempfile_name) as f: | |
85 chartresults = json.load(f) | |
77 except Exception: | 86 except Exception: |
78 traceback.print_exc() | 87 traceback.print_exc() |
79 valid = False | 88 valid = False |
80 finally: | 89 finally: |
81 shutil.rmtree(tempfile_dir) | 90 shutil.rmtree(tempfile_dir) |
82 | 91 |
83 if not valid and not failures: | 92 if not valid and not failures: |
84 failures = ['(entire test suite)'] | 93 failures = ['(entire test suite)'] |
85 if rc == 0: | 94 if rc == 0: |
86 rc = 1 # Signal an abnormal exit. | 95 rc = 1 # Signal an abnormal exit. |
87 | 96 |
88 json.dump({ | 97 if chartjson: |
89 'valid': valid, | 98 json.dump({ |
90 'failures': failures, | 99 'valid': valid, |
91 }, args.isolated_script_test_output) | 100 'failures': failures, |
101 'chartjson': chartresults | |
102 }, args.isolated_script_test_output) | |
103 else: | |
104 json.dump({ | |
105 'valid': valid, | |
106 'failures': failures | |
107 }, args.isolated_script_test_output) | |
Ken Russell (switch to Gerrit)
2016/09/12 19:31:42
Rather than overloading the meaning of --isolated-
eyaich1
2016/09/13 11:53:41
Good to know there is another use case coming down
| |
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 |