Commit 0fdf0209 authored by Yuzhu Shen's avatar Yuzhu Shen Committed by Commit Bot

Update run_telemetry_benchmark_as_googletest to support --xvfb flag.

This CL follows how run_telemetry_as_googletest.py handles --xvfb flag.

BUG=717738

Change-Id: I0bb746d18be7818c782b7086ca96605a60af0761
Reviewed-on: https://chromium-review.googlesource.com/595227
Commit-Queue: Yuzhu Shen <yzshen@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491092}
parent 9d3e5061
...@@ -48,88 +48,80 @@ def main(): ...@@ -48,88 +48,80 @@ def main():
'--isolated-script-test-chartjson-output', required=False) '--isolated-script-test-chartjson-output', required=False)
parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') parser.add_argument('--xvfb', help='Start xvfb.', action='store_true')
args, rest_args = parser.parse_known_args() args, rest_args = parser.parse_known_args()
xvfb_proc = None
openbox_proc = None
xcompmgr_proc = None
env = os.environ.copy() env = os.environ.copy()
# Assume we want to set up the sandbox environment variables all the # Assume we want to set up the sandbox environment variables all the
# time; doing so is harmless on non-Linux platforms and is needed # time; doing so is harmless on non-Linux platforms and is needed
# all the time on Linux. # all the time on Linux.
env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH
if args.xvfb and xvfb.should_start_xvfb(env): tempfile_dir = tempfile.mkdtemp('telemetry')
xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, valid = True
build_dir='.') failures = []
assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' chartjson_results_present = '--output-format=chartjson' in rest_args
chartresults = None
json_test_results = None
results = None
try: try:
tempfile_dir = tempfile.mkdtemp('telemetry') cmd = [sys.executable] + rest_args + [
valid = True '--output-dir', tempfile_dir,
failures = [] '--output-format=json-test-results',
chartjson_results_present = '--output-format=chartjson' in rest_args ]
chartresults = None if args.xvfb:
json_test_results = None rc = xvfb.run_executable(cmd, env)
else:
results = None rc = common.run_command(cmd, env=env)
try:
rc = common.run_command([sys.executable] + rest_args + [ # If we have also output chartjson read it in and return it.
'--output-dir', tempfile_dir, # results-chart.json is the file name output by telemetry when the
'--output-format=json-test-results', # chartjson output format is included
], env=env) if chartjson_results_present:
# If we have also output chartjson read it in and return it. chart_tempfile_name = os.path.join(tempfile_dir, 'results-chart.json')
# results-chart.json is the file name output by telemetry when the with open(chart_tempfile_name) as f:
# chartjson output format is included chartresults = json.load(f)
if chartjson_results_present: # We need to get chartjson results first as this may be a disabled
chart_tempfile_name = os.path.join(tempfile_dir, 'results-chart.json') # benchmark that was run
with open(chart_tempfile_name) as f: # TODO(ashleymarie): potentially remove the following if it's dead code
chartresults = json.load(f) # http://crbug.com/748638
# We need to get chartjson results first as this may be a disabled if (not chartjson_results_present or
# benchmark that was run (chartjson_results_present and chartresults.get('enabled', True))):
# TODO(ashleymarie): potentially remove the following if it's dead code tempfile_name = os.path.join(tempfile_dir, 'results.json')
# http://crbug.com/748638
if (not chartjson_results_present or
(chartjson_results_present and chartresults.get('enabled', True))):
tempfile_name = os.path.join(tempfile_dir, 'results.json')
with open(tempfile_name) as f:
results = json.load(f)
for value in results['per_page_values']:
if value['type'] == 'failure':
page_data = results['pages'][str(value['page_id'])]
name = page_data.get('name')
if not name:
name = page_data['url']
failures.append(name)
valid = bool(rc == 0 or failures)
tempfile_name = os.path.join(tempfile_dir, 'test-results.json')
with open(tempfile_name) as f: with open(tempfile_name) as f:
json_test_results = json.load(f) results = json.load(f)
for value in results['per_page_values']:
except Exception: if value['type'] == 'failure':
traceback.print_exc() page_data = results['pages'][str(value['page_id'])]
if results: name = page_data.get('name')
print 'results, which possibly caused exception: %s' % json.dumps( if not name:
results, indent=2) name = page_data['url']
valid = False
finally: failures.append(name)
shutil.rmtree(tempfile_dir) valid = bool(rc == 0 or failures)
if not valid and not failures: tempfile_name = os.path.join(tempfile_dir, 'test-results.json')
failures = ['(entire test suite)'] with open(tempfile_name) as f:
if rc == 0: json_test_results = json.load(f)
rc = 1 # Signal an abnormal exit.
except Exception:
if chartjson_results_present and args.isolated_script_test_chartjson_output: traceback.print_exc()
chartjson_output_file = \ if results:
open(args.isolated_script_test_chartjson_output, 'w') print 'results, which possibly caused exception: %s' % json.dumps(
json.dump(chartresults, chartjson_output_file) results, indent=2)
valid = False
json.dump(json_test_results, args.isolated_script_test_output)
return rc
finally: finally:
xvfb.kill(xvfb_proc) shutil.rmtree(tempfile_dir)
xvfb.kill(openbox_proc)
xvfb.kill(xcompmgr_proc) if not valid and not failures:
failures = ['(entire test suite)']
if rc == 0:
rc = 1 # Signal an abnormal exit.
if chartjson_results_present and args.isolated_script_test_chartjson_output:
chartjson_output_file = \
open(args.isolated_script_test_chartjson_output, 'w')
json.dump(chartresults, chartjson_output_file)
json.dump(json_test_results, args.isolated_script_test_output)
return rc
# This is not really a "script test" so does not need to manually add # This is not really a "script test" so does not need to manually add
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment