Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 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 import argparse | 6 import argparse |
| 7 import json | 7 import json |
| 8 import os | |
| 8 import sys | 9 import sys |
| 9 | 10 |
| 10 from gpu_tests import path_util | 11 from gpu_tests import path_util |
| 11 import gpu_project_config | 12 import gpu_project_config |
| 12 | 13 |
| 13 path_util.SetupTelemetryPaths() | 14 path_util.SetupTelemetryPaths() |
| 14 | 15 |
| 15 from telemetry.testing import browser_test_runner | 16 from telemetry.testing import browser_test_runner |
| 16 | 17 |
| 17 def PostprocessJSON(file_name, run_test_args): | 18 def PostprocessJSON(file_name, run_test_args): |
| 18 def TrimPrefix(s): | 19 # The file is not necessarily written depending on the arguments - only |
| 19 return s[1 + s.rfind('.'):] | 20 # postprocess it in case it is. |
| 20 with open(file_name) as f: | 21 if os.path.isfile(file_name): |
| 21 test_result = json.load(f) | 22 with open(file_name) as f: |
| 22 test_result['successes'] = map(TrimPrefix, test_result['successes']) | 23 test_result = json.load(f) |
| 23 test_result['failures'] = map(TrimPrefix, test_result['failures']) | 24 test_result['run_test_args'] = run_test_args |
| 24 test_result['run_test_args'] = run_test_args | 25 with open(file_name, 'w') as f: |
| 25 with open(file_name, 'w') as f: | 26 json.dump(test_result, f, indent=2) |
| 26 json.dump(test_result, f) | |
| 27 | 27 |
| 28 def main(): | 28 def main(): |
| 29 rest_args = sys.argv[1:] | 29 rest_args = sys.argv[1:] |
| 30 parser = argparse.ArgumentParser(description='Extra argument parser', | |
| 31 add_help=False) | |
| 32 | |
| 33 parser.add_argument( | |
| 34 '--write-run-test-arguments', | |
| 35 action='store_true', | |
| 36 help=('Write the test script arguments to the results file.')) | |
| 37 option, _ = parser.parse_known_args(rest_args) | |
| 38 | |
| 39 rest_args_filtered = [] | |
| 40 if option.write_run_test_arguments: | |
| 41 for arg in rest_args: | |
| 42 if arg != '--write-run-test-arguments': | |
| 43 rest_args_filtered.append(arg) | |
| 44 else: | |
| 45 rest_args_filtered = rest_args | |
|
Ken Russell (switch to Gerrit)
2017/03/15 04:25:29
This is redundant. Just assign:
option, rest_arg
oetuaho-nv
2017/03/15 10:26:17
Done.
| |
| 46 | |
| 30 retval = browser_test_runner.Run( | 47 retval = browser_test_runner.Run( |
| 31 gpu_project_config.CONFIG, rest_args) | 48 gpu_project_config.CONFIG, rest_args_filtered) |
| 32 # Postprocess the outputted JSON to trim all of the prefixes from | 49 |
| 33 # the test names, to keep them as similar to the old form as | 50 # We're not relying on argparse to print the help in the normal way, because |
| 34 # possible -- and keep them from getting crazily long. | 51 # we need the help output from both the argument parser here and the argument |
| 35 parser = argparse.ArgumentParser(description='Temporary argument parser') | 52 # parser in browser_test_runner. |
| 53 if '--help' in rest_args: | |
| 54 parser.print_help() | |
| 55 return retval | |
| 56 | |
| 57 # This duplicates an argument of browser_test_runner. | |
| 36 parser.add_argument( | 58 parser.add_argument( |
| 37 '--write-abbreviated-json-results-to', metavar='FILENAME', | 59 '--write-full-results-to', metavar='FILENAME', |
| 38 action='store', | 60 action='store', |
| 39 help=('Full path for json results')) | 61 help=('If specified, writes the full results to that path.')) |
| 62 | |
| 40 option, _ = parser.parse_known_args(rest_args) | 63 option, _ = parser.parse_known_args(rest_args) |
|
Ken Russell (switch to Gerrit)
2017/03/15 04:25:29
I really wish it weren't necessary to do this seco
oetuaho-nv
2017/03/15 10:26:17
Yep, it's ugly but I couldn't think of a better wa
| |
| 41 if option.write_abbreviated_json_results_to: | 64 |
| 42 PostprocessJSON(option.write_abbreviated_json_results_to, rest_args) | 65 # Postprocess the outputted JSON to add test arguments. |
| 66 if option.write_run_test_arguments and option.write_full_results_to: | |
| 67 PostprocessJSON(option.write_full_results_to, rest_args) | |
| 43 return retval | 68 return retval |
| 44 | 69 |
| 45 if __name__ == '__main__': | 70 if __name__ == '__main__': |
| 46 sys.exit(main()) | 71 sys.exit(main()) |
| OLD | NEW |