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: |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 def main(): | 35 def main(): |
36 parser = argparse.ArgumentParser() | 36 parser = argparse.ArgumentParser() |
37 parser.add_argument( | 37 parser.add_argument( |
38 '--isolated-script-test-output', type=argparse.FileType('w'), | 38 '--isolated-script-test-output', type=argparse.FileType('w'), |
39 required=True) | 39 required=True) |
40 parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') | 40 parser.add_argument('--xvfb', help='Start xvfb.', action='store_true') |
41 args, rest_args = parser.parse_known_args() | 41 args, rest_args = parser.parse_known_args() |
42 xvfb_proc = None | 42 xvfb_proc = None |
43 openbox_proc = None | 43 openbox_proc = None |
| 44 xcompmgr_proc = None |
44 env = os.environ.copy() | 45 env = os.environ.copy() |
45 if args.xvfb and xvfb.should_start_xvfb(env): | 46 if args.xvfb and xvfb.should_start_xvfb(env): |
46 xvfb_proc, openbox_proc = xvfb.start_xvfb(env=env, build_dir='.') | 47 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, |
47 assert xvfb_proc and openbox_proc, 'Failed to start xvfb' | 48 build_dir='.') |
| 49 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' |
48 try: | 50 try: |
49 with common.temporary_file() as tempfile_path: | 51 with common.temporary_file() as tempfile_path: |
50 rc = common.run_command([sys.executable] + rest_args + [ | 52 rc = common.run_command([sys.executable] + rest_args + [ |
51 '--write-full-results-to', tempfile_path, | 53 '--write-full-results-to', tempfile_path, |
52 ], env=env) | 54 ], env=env) |
53 with open(tempfile_path) as f: | 55 with open(tempfile_path) as f: |
54 results = json.load(f) | 56 results = json.load(f) |
55 parsed_results = common.parse_common_test_results(results, | 57 parsed_results = common.parse_common_test_results(results, |
56 test_separator='.') | 58 test_separator='.') |
57 failures = parsed_results['unexpected_failures'] | 59 failures = parsed_results['unexpected_failures'] |
58 | 60 |
59 json.dump({ | 61 json.dump({ |
60 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and | 62 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and |
61 ((rc == 0) or failures)), | 63 ((rc == 0) or failures)), |
62 'failures': failures.keys(), | 64 'failures': failures.keys(), |
63 }, args.isolated_script_test_output) | 65 }, args.isolated_script_test_output) |
64 | 66 |
65 return rc | 67 return rc |
66 finally: | 68 finally: |
67 xvfb.kill(xvfb_proc) | 69 xvfb.kill(xvfb_proc) |
68 xvfb.kill(openbox_proc) | 70 xvfb.kill(openbox_proc) |
| 71 xvfb.kill(xcompmgr_proc) |
69 | 72 |
70 | 73 |
71 | 74 |
72 # This is not really a "script test" so does not need to manually add | 75 # This is not really a "script test" so does not need to manually add |
73 # any additional compile targets. | 76 # any additional compile targets. |
74 def main_compile_targets(args): | 77 def main_compile_targets(args): |
75 json.dump([], args.output) | 78 json.dump([], args.output) |
76 | 79 |
77 | 80 |
78 if __name__ == '__main__': | 81 if __name__ == '__main__': |
79 # Conform minimally to the protocol defined by ScriptTest. | 82 # Conform minimally to the protocol defined by ScriptTest. |
80 if 'compile_targets' in sys.argv: | 83 if 'compile_targets' in sys.argv: |
81 funcs = { | 84 funcs = { |
82 'run': None, | 85 'run': None, |
83 'compile_targets': main_compile_targets, | 86 'compile_targets': main_compile_targets, |
84 } | 87 } |
85 sys.exit(common.run_script(sys.argv[1:], funcs)) | 88 sys.exit(common.run_script(sys.argv[1:], funcs)) |
86 sys.exit(main()) | 89 sys.exit(main()) |
OLD | NEW |