| 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 29 matching lines...) Expand all Loading... |
| 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 xcompmgr_proc = None |
| 45 env = os.environ.copy() | 45 env = os.environ.copy() |
| 46 if args.xvfb and xvfb.should_start_xvfb(env): | 46 if args.xvfb and xvfb.should_start_xvfb(env): |
| 47 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, | 47 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, |
| 48 build_dir='.') | 48 build_dir='.') |
| 49 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' | 49 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' |
| 50 # Compatibility with gtest-based sharding. |
| 51 total_shards = None |
| 52 shard_index = None |
| 53 if 'GTEST_TOTAL_SHARDS' in env: |
| 54 total_shards = int(env['GTEST_TOTAL_SHARDS']) |
| 55 del env['GTEST_TOTAL_SHARDS'] |
| 56 if 'GTEST_SHARD_INDEX' in env: |
| 57 shard_index = int(env['GTEST_SHARD_INDEX']) |
| 58 del env['GTEST_SHARD_INDEX'] |
| 59 sharding_args = [] |
| 60 if total_shards is not None and shard_index is not None: |
| 61 sharding_args = [ |
| 62 '--total-shards=%d' % total_shards, |
| 63 '--shard-index=%d' % shard_index |
| 64 ] |
| 50 try: | 65 try: |
| 51 with common.temporary_file() as tempfile_path: | 66 with common.temporary_file() as tempfile_path: |
| 52 rc = common.run_command([sys.executable] + rest_args + [ | 67 rc = common.run_command([sys.executable] + rest_args + sharding_args + [ |
| 53 '--write-full-results-to', tempfile_path, | 68 '--write-full-results-to', tempfile_path, |
| 54 ], env=env) | 69 ], env=env) |
| 55 with open(tempfile_path) as f: | 70 with open(tempfile_path) as f: |
| 56 results = json.load(f) | 71 results = json.load(f) |
| 57 parsed_results = common.parse_common_test_results(results, | 72 parsed_results = common.parse_common_test_results(results, |
| 58 test_separator='.') | 73 test_separator='.') |
| 59 failures = parsed_results['unexpected_failures'] | 74 failures = parsed_results['unexpected_failures'] |
| 60 | 75 |
| 61 json.dump({ | 76 json.dump({ |
| 62 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and | 77 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 | 95 |
| 81 if __name__ == '__main__': | 96 if __name__ == '__main__': |
| 82 # Conform minimally to the protocol defined by ScriptTest. | 97 # Conform minimally to the protocol defined by ScriptTest. |
| 83 if 'compile_targets' in sys.argv: | 98 if 'compile_targets' in sys.argv: |
| 84 funcs = { | 99 funcs = { |
| 85 'run': None, | 100 'run': None, |
| 86 'compile_targets': main_compile_targets, | 101 'compile_targets': main_compile_targets, |
| 87 } | 102 } |
| 88 sys.exit(common.run_script(sys.argv[1:], funcs)) | 103 sys.exit(common.run_script(sys.argv[1:], funcs)) |
| 89 sys.exit(main()) | 104 sys.exit(main()) |
| OLD | NEW |