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 with common.temporary_file() as tempfile_path: | 38 with common.temporary_file() as tempfile_path: |
39 rc = common.run_command([sys.executable] + rest_args + [ | 39 rc = common.run_command([sys.executable] + rest_args + [ |
40 '--write-full-results-to', tempfile_path, | 40 '--write-full-results-to', tempfile_path, |
41 ]) | 41 ]) |
42 with open(tempfile_path) as f: | 42 with open(tempfile_path) as f: |
43 results = json.load(f) | 43 results = json.load(f) |
44 parsed_results = common.parse_common_test_results(results, | 44 parsed_results = common.parse_common_test_results(results, |
45 test_separator='.') | 45 test_separator='.') |
46 failures = parsed_results['unexpected_failures'] | 46 failures = parsed_results['unexpected_failures'] |
47 | 47 |
48 json.dump({ | 48 json.dump({ |
49 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and | 49 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and |
50 ((rc == 0) or failures)), | 50 ((rc == 0) or failures)), |
51 'failures': failures.keys(), | 51 'failures': failures.keys(), |
52 }, args.test_launcher_summary_output) | 52 }, args.isolated_script_test_output) |
53 | 53 |
54 return rc | 54 return rc |
55 | 55 |
56 | 56 |
57 # This is not really a "script test" so does not need to manually add | 57 # This is not really a "script test" so does not need to manually add |
58 # any additional compile targets. | 58 # any additional compile targets. |
59 def main_compile_targets(args): | 59 def main_compile_targets(args): |
60 json.dump([], args.output) | 60 json.dump([], args.output) |
61 | 61 |
62 | 62 |
63 if __name__ == '__main__': | 63 if __name__ == '__main__': |
64 # Conform minimally to the protocol defined by ScriptTest. | 64 # Conform minimally to the protocol defined by ScriptTest. |
65 if 'compile_targets' in sys.argv: | 65 if 'compile_targets' in sys.argv: |
66 funcs = { | 66 funcs = { |
67 'run': None, | 67 'run': None, |
68 'compile_targets': main_compile_targets, | 68 'compile_targets': main_compile_targets, |
69 } | 69 } |
70 sys.exit(common.run_script(sys.argv[1:], funcs)) | 70 sys.exit(common.run_script(sys.argv[1:], funcs)) |
71 sys.exit(main()) | 71 sys.exit(main()) |
OLD | NEW |