| 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 30 matching lines...) Expand all Loading... |
| 41 args, rest_args = parser.parse_known_args() | 41 args, rest_args = parser.parse_known_args() |
| 42 # Remove the chartjson extra arg until this script cares about chartjson | 42 # Remove the chartjson extra arg until this script cares about chartjson |
| 43 # results from telemetry | 43 # results from telemetry |
| 44 index = 0 | 44 index = 0 |
| 45 for arg in rest_args: | 45 for arg in rest_args: |
| 46 if '--isolated-script-test-chartjson-output' in arg: | 46 if '--isolated-script-test-chartjson-output' in arg: |
| 47 rest_args.pop(index) | 47 rest_args.pop(index) |
| 48 break | 48 break |
| 49 index += 1 | 49 index += 1 |
| 50 | 50 |
| 51 xvfb_proc = None | |
| 52 openbox_proc = None | |
| 53 xcompmgr_proc = None | |
| 54 env = os.environ.copy() | |
| 55 if args.xvfb and xvfb.should_start_xvfb(env): | |
| 56 xvfb_proc, openbox_proc, xcompmgr_proc = xvfb.start_xvfb(env=env, | |
| 57 build_dir='.') | |
| 58 assert xvfb_proc and openbox_proc and xcompmgr_proc, 'Failed to start xvfb' | |
| 59 # Compatibility with gtest-based sharding. | 51 # Compatibility with gtest-based sharding. |
| 60 total_shards = None | 52 total_shards = None |
| 61 shard_index = None | 53 shard_index = None |
| 54 env = os.environ.copy() |
| 62 if 'GTEST_TOTAL_SHARDS' in env: | 55 if 'GTEST_TOTAL_SHARDS' in env: |
| 63 total_shards = int(env['GTEST_TOTAL_SHARDS']) | 56 total_shards = int(env['GTEST_TOTAL_SHARDS']) |
| 64 del env['GTEST_TOTAL_SHARDS'] | 57 del env['GTEST_TOTAL_SHARDS'] |
| 65 if 'GTEST_SHARD_INDEX' in env: | 58 if 'GTEST_SHARD_INDEX' in env: |
| 66 shard_index = int(env['GTEST_SHARD_INDEX']) | 59 shard_index = int(env['GTEST_SHARD_INDEX']) |
| 67 del env['GTEST_SHARD_INDEX'] | 60 del env['GTEST_SHARD_INDEX'] |
| 68 sharding_args = [] | 61 sharding_args = [] |
| 69 if total_shards is not None and shard_index is not None: | 62 if total_shards is not None and shard_index is not None: |
| 70 sharding_args = [ | 63 sharding_args = [ |
| 71 '--total-shards=%d' % total_shards, | 64 '--total-shards=%d' % total_shards, |
| 72 '--shard-index=%d' % shard_index | 65 '--shard-index=%d' % shard_index |
| 73 ] | 66 ] |
| 74 try: | 67 cmd = [sys.executable] + rest_args + sharding_args + [ |
| 75 return common.run_command([sys.executable] + rest_args + sharding_args + [ | 68 '--write-full-results-to', args.isolated_script_test_output] |
| 76 '--write-full-results-to', args.isolated_script_test_output], env=env) | 69 if args.xvfb: |
| 77 finally: | 70 return xvfb.run_executable(cmd, '.', env) |
| 78 xvfb.kill(xvfb_proc) | 71 else: |
| 79 xvfb.kill(openbox_proc) | 72 return common.run_command(cmd, env=env) |
| 80 xvfb.kill(xcompmgr_proc) | |
| 81 | |
| 82 | 73 |
| 83 | 74 |
| 84 # 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 |
| 85 # any additional compile targets. | 76 # any additional compile targets. |
| 86 def main_compile_targets(args): | 77 def main_compile_targets(args): |
| 87 json.dump([], args.output) | 78 json.dump([], args.output) |
| 88 | 79 |
| 89 | 80 |
| 90 if __name__ == '__main__': | 81 if __name__ == '__main__': |
| 91 # Conform minimally to the protocol defined by ScriptTest. | 82 # Conform minimally to the protocol defined by ScriptTest. |
| 92 if 'compile_targets' in sys.argv: | 83 if 'compile_targets' in sys.argv: |
| 93 funcs = { | 84 funcs = { |
| 94 'run': None, | 85 'run': None, |
| 95 'compile_targets': main_compile_targets, | 86 'compile_targets': main_compile_targets, |
| 96 } | 87 } |
| 97 sys.exit(common.run_script(sys.argv[1:], funcs)) | 88 sys.exit(common.run_script(sys.argv[1:], funcs)) |
| 98 sys.exit(main()) | 89 sys.exit(main()) |
| OLD | NEW |