blob: 2ac8b3ae2d163af2ece2049e743c6c954e27eb93 [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.
Ned Nguyen09dcd002018-10-16 06:01:5052KNOWN_TYP_TEST_RUNNERS = {'run_blinkpy_tests.py', 'metrics_python_tests.py'}
Stephen Martinis9bcb5a32018-06-21 23:11:3153
54
Ned Nguyen09dcd002018-10-16 06:01:5055class TypUnittestAdapter(common.BaseIsolatedScriptArgsAdapter):
56
57 def __init__(self):
58 super(TypUnittestAdapter, self).__init__()
59 self._temp_filter_file = None
60
61 def generate_sharding_args(self, total_shards, shard_index):
62 # This script only uses environment variable for sharding.
63 del total_shards, shard_index # unused
64 return []
65
66 def generate_test_output_args(self, output):
67 return ['--write-full-results-to', output]
68
69 def generate_test_filter_args(self, test_filter_str):
70 filter_list = common.extract_filter_list(test_filter_str)
71 self._temp_filter_file = tempfile.NamedTemporaryFile(
72 mode='w', delete=False)
73 self._temp_filter_file.write('\n'.join(filter_list))
74 self._temp_filter_file.close()
75 arg_name = 'test-list'
76 if KNOWN_TYP_TEST_RUNNERS.intersection(self.rest_args):
77 arg_name = 'file-list'
78
79 return ['--%s=' % arg_name + self._temp_filter_file.name]
80
81 def run_test(self):
82 try:
83 super(TypUnittestAdapter, self).run_test()
84 finally:
85 # Clean up the temp filter file at the end after the test has
86 # finished the run if needed.
87 if self._temp_filter_file:
88 os.unlink(self._temp_filter_file.name)
89
tansell0e6baaf22017-02-16 09:14:5390def main():
Ned Nguyen09dcd002018-10-16 06:01:5091 adapter = TypUnittestAdapter()
92 adapter.run_test()
tansell0e6baaf22017-02-16 09:14:5393
94# This is not really a "script test" so does not need to manually add
95# any additional compile targets.
96def main_compile_targets(args):
97 json.dump([], args.output)
98
99
100if __name__ == '__main__':
101 # Conform minimally to the protocol defined by ScriptTest.
102 if 'compile_targets' in sys.argv:
103 funcs = {
104 'run': None,
105 'compile_targets': main_compile_targets,
106 }
107 sys.exit(common.run_script(sys.argv[1:], funcs))
108 sys.exit(main())