tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Runs a script that can run as an isolate (or not). |
| 7 | |
| 8 | The main requirement is that |
| 9 | |
| 10 | --isolated-script-test-output=[FILENAME] |
| 11 | |
| 12 | is passed on the command line to run_isolated_script_tests. This gets |
| 13 | remapped to the command line argument --write-full-results-to. |
| 14 | |
| 15 | json is written to that file in the format produced by |
| 16 | common.parse_common_test_results. |
| 17 | |
Kenneth Russell | 4027405 | 2017-11-14 00:57:44 | [diff] [blame] | 18 | Optional argument: |
| 19 | |
Kenneth Russell | a649a4612 | 2017-11-21 06:39:59 | [diff] [blame] | 20 | --isolated-script-test-filter=[TEST_NAMES] |
Kenneth Russell | 4027405 | 2017-11-14 00:57:44 | [diff] [blame] | 21 | |
Kenneth Russell | a649a4612 | 2017-11-21 06:39:59 | [diff] [blame] | 22 | is a double-colon-separated ("::") list of test names, to run just that subset |
| 23 | of tests. This list is parsed by this harness and sent down via the --test-list |
| 24 | argument. |
Kenneth Russell | 4027405 | 2017-11-14 00:57:44 | [diff] [blame] | 25 | |
tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 26 | This script is intended to be the base command invoked by the isolate, |
| 27 | followed by a subsequent Python script. It could be generalized to |
| 28 | invoke an arbitrary executable. |
| 29 | """ |
| 30 | |
| 31 | # TODO(tansell): Remove this script once LayoutTests can accept the isolated |
| 32 | # arguments and start xvfb itself. |
| 33 | |
| 34 | import argparse |
| 35 | import json |
| 36 | import os |
| 37 | import pprint |
| 38 | import sys |
Kenneth Russell | a649a4612 | 2017-11-21 06:39:59 | [diff] [blame] | 39 | import tempfile |
tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 40 | |
| 41 | |
| 42 | import common |
| 43 | |
| 44 | # Add src/testing/ into sys.path for importing xvfb. |
| 45 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 46 | import xvfb |
| 47 | |
| 48 | |
Stephen Martinis | 9bcb5a3 | 2018-06-21 23:11:31 | [diff] [blame^] | 49 | # Known typ test runners this script wraps. They need a different argument name |
| 50 | # when selecting which tests to run. |
| 51 | # TODO(dpranke): Detect if the wrapped test suite uses typ better. |
| 52 | KNOWN_TYP_TEST_RUNNERS = ['run_blinkpy_tests.py', 'metrics_python_tests.py'] |
| 53 | |
| 54 | |
tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 55 | def main(): |
| 56 | parser = argparse.ArgumentParser() |
| 57 | parser.add_argument('--isolated-script-test-output', type=str, |
| 58 | required=True) |
| 59 | parser.add_argument('--xvfb', help='start xvfb', action='store_true') |
| 60 | |
| 61 | # This argument is ignored for now. |
| 62 | parser.add_argument('--isolated-script-test-chartjson-output', type=str) |
Ethan Kuefner | 9d00951723 | 2017-08-14 20:56:42 | [diff] [blame] | 63 | # This argument is ignored for now. |
| 64 | parser.add_argument('--isolated-script-test-perf-output', type=str) |
Kenneth Russell | 4027405 | 2017-11-14 00:57:44 | [diff] [blame] | 65 | # This argument is translated below. |
Kenneth Russell | a649a4612 | 2017-11-21 06:39:59 | [diff] [blame] | 66 | parser.add_argument('--isolated-script-test-filter', type=str) |
tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 67 | |
| 68 | args, rest_args = parser.parse_known_args() |
| 69 | |
Dirk Pranke | eb695f6 | 2017-12-18 23:16:31 | [diff] [blame] | 70 | env = os.environ.copy() |
| 71 | env['CHROME_HEADLESS'] = '1' |
tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 72 | cmd = [sys.executable] + rest_args |
| 73 | cmd += ['--write-full-results-to', args.isolated_script_test_output] |
Kenneth Russell | a649a4612 | 2017-11-21 06:39:59 | [diff] [blame] | 74 | temp_filter_file = None |
| 75 | try: |
| 76 | if args.isolated_script_test_filter: |
| 77 | filter_list = common.extract_filter_list(args.isolated_script_test_filter) |
| 78 | # Need to dump this to a file in order to use --file-list. |
| 79 | temp_filter_file = tempfile.NamedTemporaryFile(mode='w', delete=False) |
| 80 | temp_filter_file.write('\n'.join(filter_list)) |
| 81 | temp_filter_file.close() |
Stephen Martinis | 9bcb5a3 | 2018-06-21 23:11:31 | [diff] [blame^] | 82 | |
Stephen Martinis | 5b371945 | 2018-06-15 23:27:25 | [diff] [blame] | 83 | arg_name = 'test-list' |
| 84 | for arg in rest_args: |
Stephen Martinis | 9bcb5a3 | 2018-06-21 23:11:31 | [diff] [blame^] | 85 | for runner in KNOWN_TYP_TEST_RUNNERS: |
| 86 | if runner in arg: |
| 87 | arg_name = 'file-list' |
| 88 | |
Stephen Martinis | 5b371945 | 2018-06-15 23:27:25 | [diff] [blame] | 89 | cmd += ['--%s=' % arg_name + temp_filter_file.name] |
Kenneth Russell | a649a4612 | 2017-11-21 06:39:59 | [diff] [blame] | 90 | if args.xvfb: |
| 91 | return xvfb.run_executable(cmd, env) |
| 92 | else: |
| 93 | return common.run_command(cmd, env=env) |
| 94 | finally: |
| 95 | if temp_filter_file: |
| 96 | os.unlink(temp_filter_file.name) |
tansell | 0e6baaf2 | 2017-02-16 09:14:53 | [diff] [blame] | 97 | |
| 98 | |
| 99 | # This is not really a "script test" so does not need to manually add |
| 100 | # any additional compile targets. |
| 101 | def main_compile_targets(args): |
| 102 | json.dump([], args.output) |
| 103 | |
| 104 | |
| 105 | if __name__ == '__main__': |
| 106 | # Conform minimally to the protocol defined by ScriptTest. |
| 107 | if 'compile_targets' in sys.argv: |
| 108 | funcs = { |
| 109 | 'run': None, |
| 110 | 'compile_targets': main_compile_targets, |
| 111 | } |
| 112 | sys.exit(common.run_script(sys.argv[1:], funcs)) |
| 113 | sys.exit(main()) |