| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2018 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 chrome driver tests. |
| 7 | |
| 8 | This script attempts to emulate the contract of gtest-style tests |
| 9 | invoked via recipes. The main contract is that the caller passes the |
| 10 | argument: |
| 11 | |
| 12 | --isolated-script-test-output=[FILENAME] |
| 13 | |
| 14 | json is written to that file in the format detailed here: |
| 15 | https://www.chromium.org/developers/the-json-test-results-format |
| 16 | |
| 17 | Optional argument: |
| 18 | |
| 19 | --isolated-script-test-filter=[TEST_NAMES] |
| 20 | |
| 21 | is a double-colon-separated ("::") list of test names, to run just that subset |
| 22 | of tests. This list is forwarded to the chrome driver test runner. |
| 23 | """ |
| 24 | |
| 25 | import argparse |
| 26 | import json |
| 27 | import os |
| 28 | import shutil |
| 29 | import sys |
| 30 | import tempfile |
| 31 | import traceback |
| 32 | |
| 33 | import common |
| 34 | |
| 35 | def main(): |
| 36 | parser = argparse.ArgumentParser() |
| 37 | |
| 38 | # --isolated-script-test-output is passed through to the script. |
| 39 | |
| 40 | # This argument is ignored for now. |
| 41 | parser.add_argument('--isolated-script-test-chartjson-output', type=str) |
| 42 | # This argument is ignored for now. |
| 43 | parser.add_argument('--isolated-script-test-perf-output', type=str) |
| 44 | # This argument is translated below. |
| 45 | parser.add_argument('--isolated-script-test-filter', type=str) |
| 46 | |
| 47 | args, rest_args = parser.parse_known_args() |
| 48 | |
| 49 | filtered_tests = args.isolated_script_test_filter |
| 50 | if filtered_tests: |
| 51 | if any('--filter' in arg for arg in rest_args): |
| 52 | parser.error( |
| 53 | 'can\'t have the test call filter with the' |
| 54 | '--isolated-script-test-filter argument to the wrapper script') |
| 55 | |
| 56 | # https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#running-a-subset-of-the-tests |
| 57 | # says that the gtest filter should accept single colons separating |
| 58 | # individual tests. The input is double colon separated, so translate it. |
| 59 | rest_args = rest_args + ['--filter', filtered_tests.replace('::', ':')] |
| 60 | |
| 61 | cmd = [sys.executable] + rest_args |
| 62 | return common.run_command(cmd) |
| 63 | |
| 64 | |
| 65 | # This is not really a "script test" so does not need to manually add |
| 66 | # any additional compile targets. |
| 67 | def main_compile_targets(args): |
| 68 | json.dump([], args.output) |
| 69 | |
| 70 | |
| 71 | if __name__ == '__main__': |
| 72 | # Conform minimally to the protocol defined by ScriptTest. |
| 73 | if 'compile_targets' in sys.argv: |
| 74 | funcs = { |
| 75 | 'run': None, |
| 76 | 'compile_targets': main_compile_targets, |
| 77 | } |
| 78 | sys.exit(common.run_script(sys.argv[1:], funcs)) |
| 79 | sys.exit(main()) |