blob: 09b99d5e31b5eb64b4eddfdbd315d9b68cf5822f [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',
Peter Kotwiczc10750c2020-10-07 20:57:4562 'monochrome_python_tests.py',
Robert Sesekb8421292019-05-06 18:13:2763}
Stephen Martinis9bcb5a32018-06-21 23:11:3164
65
Kenneth Russell1df696c42019-01-30 02:44:2466class IsolatedScriptTestAdapter(common.BaseIsolatedScriptArgsAdapter):
67 def __init__(self):
68 super(IsolatedScriptTestAdapter, self).__init__()
69
70 def generate_sharding_args(self, total_shards, shard_index):
71 # This script only uses environment variable for sharding.
72 del total_shards, shard_index # unused
73 return []
74
75 def generate_test_also_run_disabled_tests_args(self):
76 return ['--isolated-script-test-also-run-disabled-tests']
77
78 def generate_test_filter_args(self, test_filter_str):
79 return ['--isolated-script-test-filter=%s' % test_filter_str]
80
81 def generate_test_output_args(self, output):
82 return ['--isolated-script-test-output=%s' % output]
83
84 def generate_test_launcher_retry_limit_args(self, retry_limit):
Kenneth Russelld87758a2019-01-31 23:19:3285 return ['--isolated-script-test-launcher-retry-limit=%d' % retry_limit]
Kenneth Russell1df696c42019-01-30 02:44:2486
87 def generate_test_repeat_args(self, repeat_count):
88 return ['--isolated-script-test-repeat=%d' % repeat_count]
89
90
Ned Nguyen09dcd002018-10-16 06:01:5091class TypUnittestAdapter(common.BaseIsolatedScriptArgsAdapter):
92
93 def __init__(self):
94 super(TypUnittestAdapter, self).__init__()
95 self._temp_filter_file = None
96
97 def generate_sharding_args(self, total_shards, shard_index):
98 # This script only uses environment variable for sharding.
99 del total_shards, shard_index # unused
100 return []
101
102 def generate_test_output_args(self, output):
103 return ['--write-full-results-to', output]
104
105 def generate_test_filter_args(self, test_filter_str):
106 filter_list = common.extract_filter_list(test_filter_str)
107 self._temp_filter_file = tempfile.NamedTemporaryFile(
108 mode='w', delete=False)
109 self._temp_filter_file.write('\n'.join(filter_list))
110 self._temp_filter_file.close()
111 arg_name = 'test-list'
Peter Kotwicz72fc99f2020-10-06 05:09:24112 if any(r in self.rest_args[0] for r in KNOWN_TYP_TEST_RUNNERS):
Ned Nguyen09dcd002018-10-16 06:01:50113 arg_name = 'file-list'
114
115 return ['--%s=' % arg_name + self._temp_filter_file.name]
116
Ned Nguyen68c34982018-11-01 01:07:58117 def clean_up_after_test_run(self):
118 if self._temp_filter_file:
119 os.unlink(self._temp_filter_file.name)
120
Ned Nguyen09dcd002018-10-16 06:01:50121 def run_test(self):
Ned Nguyen68c34982018-11-01 01:07:58122 return super(TypUnittestAdapter, self).run_test()
123
Ned Nguyen09dcd002018-10-16 06:01:50124
tansell0e6baaf22017-02-16 09:14:53125def main():
Kenneth Russell1df696c42019-01-30 02:44:24126 if any(r in sys.argv[1] for r in KNOWN_ISOLATED_SCRIPT_TEST_RUNNERS):
127 adapter = IsolatedScriptTestAdapter()
128 else:
129 adapter = TypUnittestAdapter()
Stephen Martinis08650052018-10-22 18:50:37130 return adapter.run_test()
tansell0e6baaf22017-02-16 09:14:53131
132# This is not really a "script test" so does not need to manually add
133# any additional compile targets.
134def main_compile_targets(args):
135 json.dump([], args.output)
136
137
138if __name__ == '__main__':
139 # Conform minimally to the protocol defined by ScriptTest.
140 if 'compile_targets' in sys.argv:
141 funcs = {
142 'run': None,
143 'compile_targets': main_compile_targets,
144 }
145 sys.exit(common.run_script(sys.argv[1:], funcs))
146 sys.exit(main())