Chromium Code Reviews| 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 isolate bundled Telemetry unittests. | 6 """Runs isolate bundled Telemetry unittests. |
| 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 --test-launcher-summary-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 |
| 17 This script is intended to be the base command invoked by the isolate, | 17 This script is intended to be the base command invoked by the isolate, |
| 18 followed by a subsequent Python script. It could be generalized to | 18 followed by a subsequent Python script. It could be generalized to |
| 19 invoke an arbitrary executable. | 19 invoke an arbitrary executable. |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 import argparse | 22 import argparse |
| 23 import json | 23 import json |
| 24 import os | 24 import os |
| 25 import sys | 25 import sys |
| 26 | 26 |
| 27 | 27 |
| 28 import common | 28 import common |
| 29 | 29 |
| 30 | 30 |
| 31 def main(): | 31 def main(): |
| 32 parser = argparse.ArgumentParser() | 32 parser = argparse.ArgumentParser() |
| 33 parser.add_argument( | 33 parser.add_argument( |
| 34 '--test-launcher-summary-output', | 34 '--isolated-script-test-output', |
| 35 type=argparse.FileType('w'), | 35 type=argparse.FileType('w'), |
| 36 required=True) | 36 required=True) |
| 37 args, rest_args = parser.parse_known_args() | 37 args, rest_args = parser.parse_known_args() |
| 38 print 'Writing results to %s' % args.isolated_script_test_output | |
|
Ken Russell (switch to Gerrit)
2015/09/18 23:52:51
Please remove debugging print statement.
nednguyen
2015/09/21 17:26:18
Done.
| |
| 38 with common.temporary_file() as tempfile_path: | 39 with common.temporary_file() as tempfile_path: |
| 39 rc = common.run_command([sys.executable] + rest_args + [ | 40 rc = common.run_command([sys.executable] + rest_args + [ |
| 40 '--write-full-results-to', tempfile_path, | 41 '--write-full-results-to', tempfile_path, |
| 41 ]) | 42 ]) |
| 42 with open(tempfile_path) as f: | 43 with open(tempfile_path) as f: |
| 43 results = json.load(f) | 44 results = json.load(f) |
| 44 parsed_results = common.parse_common_test_results(results, | 45 parsed_results = common.parse_common_test_results(results, |
| 45 test_separator='.') | 46 test_separator='.') |
| 46 failures = parsed_results['unexpected_failures'] | 47 failures = parsed_results['unexpected_failures'] |
| 47 | 48 |
| 48 json.dump({ | 49 json.dump({ |
| 49 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and | 50 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and |
| 50 ((rc == 0) or failures)), | 51 ((rc == 0) or failures)), |
| 51 'failures': failures.keys(), | 52 'failures': failures.keys(), |
| 52 }, args.test_launcher_summary_output) | 53 }, args.isolated_script_test_output) |
| 53 | 54 |
| 54 return rc | 55 return rc |
| 55 | 56 |
| 56 | 57 |
| 57 # This is not really a "script test" so does not need to manually add | 58 # This is not really a "script test" so does not need to manually add |
| 58 # any additional compile targets. | 59 # any additional compile targets. |
| 59 def main_compile_targets(args): | 60 def main_compile_targets(args): |
| 60 json.dump([], args.output) | 61 json.dump([], args.output) |
| 61 | 62 |
| 62 | 63 |
| 63 if __name__ == '__main__': | 64 if __name__ == '__main__': |
| 64 # Conform minimally to the protocol defined by ScriptTest. | 65 # Conform minimally to the protocol defined by ScriptTest. |
| 65 if 'compile_targets' in sys.argv: | 66 if 'compile_targets' in sys.argv: |
| 66 funcs = { | 67 funcs = { |
| 67 'run': None, | 68 'run': None, |
| 68 'compile_targets': main_compile_targets, | 69 'compile_targets': main_compile_targets, |
| 69 } | 70 } |
| 70 sys.exit(common.run_script(sys.argv[1:], funcs)) | 71 sys.exit(common.run_script(sys.argv[1:], funcs)) |
| 71 sys.exit(main()) | 72 sys.exit(main()) |
| OLD | NEW |