blob: 70c04a8f3db8052728afffdda7f6affe76b70136 [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
Kenneth Russell1df696c42019-01-30 02:44:2449# Some harnesses understand the --isolated-script-test arguments
50# directly and prefer that they be passed through.
51KNOWN_ISOLATED_SCRIPT_TEST_RUNNERS = {'run_web_tests.py'}
52
53
Stephen Martinis9bcb5a32018-06-21 23:11:3154# Known typ test runners this script wraps. They need a different argument name
55# when selecting which tests to run.
56# TODO(dpranke): Detect if the wrapped test suite uses typ better.
Robert Sesekb8421292019-05-06 18:13:2757KNOWN_TYP_TEST_RUNNERS = {
58 'run_blinkpy_tests.py',
59 'metrics_python_tests.py',
60 'run_mac_signing_tests.py',
rbpotterd8ca34c2019-07-25 18:48:0561 'run_polymer_tools_tests.py',
Robert Sesekb8421292019-05-06 18:13:2762}
Stephen Martinis9bcb5a32018-06-21 23:11:3163
64
Kenneth Russell1df696c42019-01-30 02:44:2465class IsolatedScriptTestAdapter(common.BaseIsolatedScriptArgsAdapter):
66 def __init__(self):
67 super(IsolatedScriptTestAdapter, self).__init__()
68
69 def generate_sharding_args(self, total_shards, shard_index):
70 # This script only uses environment variable for sharding.
71 del total_shards, shard_index # unused
72 return []
73
74 def generate_test_also_run_disabled_tests_args(self):
75 return ['--isolated-script-test-also-run-disabled-tests']
76
77 def generate_test_filter_args(self, test_filter_str):
78 return ['--isolated-script-test-filter=%s' % test_filter_str]
79
80 def generate_test_output_args(self, output):
81 return ['--isolated-script-test-output=%s' % output]
82
83 def generate_test_launcher_retry_limit_args(self, retry_limit):
Kenneth Russelld87758a2019-01-31 23:19:3284 return ['--isolated-script-test-launcher-retry-limit=%d' % retry_limit]
Kenneth Russell1df696c42019-01-30 02:44:2485
86 def generate_test_repeat_args(self, repeat_count):
87 return ['--isolated-script-test-repeat=%d' % repeat_count]
88
89
Ned Nguyen09dcd002018-10-16 06:01:5090class TypUnittestAdapter(common.BaseIsolatedScriptArgsAdapter):
91
92 def __init__(self):
93 super(TypUnittestAdapter, self).__init__()
94 self._temp_filter_file = None
95
96 def generate_sharding_args(self, total_shards, shard_index):
97 # This script only uses environment variable for sharding.
98 del total_shards, shard_index # unused
99 return []
100
101 def generate_test_output_args(self, output):
102 return ['--write-full-results-to', output]
103
104 def generate_test_filter_args(self, test_filter_str):
105 filter_list = common.extract_filter_list(test_filter_str)
106 self._temp_filter_file = tempfile.NamedTemporaryFile(
107 mode='w', delete=False)
108 self._temp_filter_file.write('\n'.join(filter_list))
109 self._temp_filter_file.close()
110 arg_name = 'test-list'
Peter Kotwicz72fc99f2020-10-06 05:09:24111 if any(r in self.rest_args[0] for r in KNOWN_TYP_TEST_RUNNERS):
Ned Nguyen09dcd002018-10-16 06:01:50112 arg_name = 'file-list'
113
114 return ['--%s=' % arg_name + self._temp_filter_file.name]
115
Ned Nguyen68c34982018-11-01 01:07:58116 def clean_up_after_test_run(self):
117 if self._temp_filter_file:
118 os.unlink(self._temp_filter_file.name)
119
Ned Nguyen09dcd002018-10-16 06:01:50120 def run_test(self):
Ned Nguyen68c34982018-11-01 01:07:58121 return super(TypUnittestAdapter, self).run_test()
122
Ned Nguyen09dcd002018-10-16 06:01:50123
tansell0e6baaf22017-02-16 09:14:53124def main():
Kenneth Russell1df696c42019-01-30 02:44:24125 if any(r in sys.argv[1] for r in KNOWN_ISOLATED_SCRIPT_TEST_RUNNERS):
126 adapter = IsolatedScriptTestAdapter()
127 else:
128 adapter = TypUnittestAdapter()
Stephen Martinis08650052018-10-22 18:50:37129 return adapter.run_test()
tansell0e6baaf22017-02-16 09:14:53130
131# This is not really a "script test" so does not need to manually add
132# any additional compile targets.
133def main_compile_targets(args):
134 json.dump([], args.output)
135
136
137if __name__ == '__main__':
138 # Conform minimally to the protocol defined by ScriptTest.
139 if 'compile_targets' in sys.argv:
140 funcs = {
141 'run': None,
142 'compile_targets': main_compile_targets,
143 }
144 sys.exit(common.run_script(sys.argv[1:], funcs))
145 sys.exit(main())