blob: 480c40102711c5d83ce1dc0c2cf0d0cdb78a7ea2 [file] [log] [blame]
tansell0e6baaf22017-02-16 09:14:531#!/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
8The main requirement is that
9
10 --isolated-script-test-output=[FILENAME]
11
12is passed on the command line to run_isolated_script_tests. This gets
13remapped to the command line argument --write-full-results-to.
14
15json is written to that file in the format produced by
16common.parse_common_test_results.
17
Kenneth Russell40274052017-11-14 00:57:4418Optional argument:
19
Kenneth Russella649a46122017-11-21 06:39:5920 --isolated-script-test-filter=[TEST_NAMES]
Kenneth Russell40274052017-11-14 00:57:4421
Kenneth Russella649a46122017-11-21 06:39:5922is a double-colon-separated ("::") list of test names, to run just that subset
23of tests. This list is parsed by this harness and sent down via the --test-list
24argument.
Kenneth Russell40274052017-11-14 00:57:4425
tansell0e6baaf22017-02-16 09:14:5326This script is intended to be the base command invoked by the isolate,
27followed by a subsequent Python script. It could be generalized to
28invoke an arbitrary executable.
29"""
30
31# TODO(tansell): Remove this script once LayoutTests can accept the isolated
32# arguments and start xvfb itself.
33
34import argparse
35import json
36import os
37import pprint
38import sys
Kenneth Russella649a46122017-11-21 06:39:5939import tempfile
tansell0e6baaf22017-02-16 09:14:5340
41
42import common
43
44# Add src/testing/ into sys.path for importing xvfb.
45sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
46import xvfb
47
48
Stephen Martinis9bcb5a32018-06-21 23:11:3149# 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.
52KNOWN_TYP_TEST_RUNNERS = ['run_blinkpy_tests.py', 'metrics_python_tests.py']
53
54
tansell0e6baaf22017-02-16 09:14:5355def 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 Kuefner9d009517232017-08-14 20:56:4263 # This argument is ignored for now.
64 parser.add_argument('--isolated-script-test-perf-output', type=str)
Kenneth Russell40274052017-11-14 00:57:4465 # This argument is translated below.
Kenneth Russella649a46122017-11-21 06:39:5966 parser.add_argument('--isolated-script-test-filter', type=str)
tansell0e6baaf22017-02-16 09:14:5367
68 args, rest_args = parser.parse_known_args()
69
Dirk Prankeeb695f62017-12-18 23:16:3170 env = os.environ.copy()
71 env['CHROME_HEADLESS'] = '1'
tansell0e6baaf22017-02-16 09:14:5372 cmd = [sys.executable] + rest_args
73 cmd += ['--write-full-results-to', args.isolated_script_test_output]
Kenneth Russella649a46122017-11-21 06:39:5974 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 Martinis9bcb5a32018-06-21 23:11:3182
Stephen Martinis5b3719452018-06-15 23:27:2583 arg_name = 'test-list'
84 for arg in rest_args:
Stephen Martinis9bcb5a32018-06-21 23:11:3185 for runner in KNOWN_TYP_TEST_RUNNERS:
86 if runner in arg:
87 arg_name = 'file-list'
88
Stephen Martinis5b3719452018-06-15 23:27:2589 cmd += ['--%s=' % arg_name + temp_filter_file.name]
Kenneth Russella649a46122017-11-21 06:39:5990 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)
tansell0e6baaf22017-02-16 09:14:5397
98
99# This is not really a "script test" so does not need to manually add
100# any additional compile targets.
101def main_compile_targets(args):
102 json.dump([], args.output)
103
104
105if __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())