| 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 | |
| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame] | 35 | |
| Ned Nguyen | 09dcd00 | 2018-10-16 06:01:50 | [diff] [blame^] | 36 | class ChromeDriverAdapter(common.BaseIsolatedScriptArgsAdapter): |
| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame] | 37 | |
| Ned Nguyen | 09dcd00 | 2018-10-16 06:01:50 | [diff] [blame^] | 38 | def generate_test_output_args(self, output): |
| 39 | return ['--isolated-script-test-output', output] |
| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame] | 40 | |
| Ned Nguyen | 09dcd00 | 2018-10-16 06:01:50 | [diff] [blame^] | 41 | def generate_test_filter_args(self, test_filter_str): |
| 42 | if any('--filter' in arg for arg in self.rest_args): |
| 43 | self.parser.error( |
| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame] | 44 | 'can\'t have the test call filter with the' |
| 45 | '--isolated-script-test-filter argument to the wrapper script') |
| 46 | |
| Ned Nguyen | 09dcd00 | 2018-10-16 06:01:50 | [diff] [blame^] | 47 | return ['--filter', test_filter_str.replace('::', ':')] |
| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame] | 48 | |
| Ned Nguyen | 09dcd00 | 2018-10-16 06:01:50 | [diff] [blame^] | 49 | |
| 50 | def main(): |
| 51 | adapter = ChromeDriverAdapter() |
| 52 | adapter.run_test() |
| Stephen Martinis | f7bb823 | 2018-06-26 19:47:54 | [diff] [blame] | 53 | |
| 54 | |
| 55 | # This is not really a "script test" so does not need to manually add |
| 56 | # any additional compile targets. |
| 57 | def main_compile_targets(args): |
| 58 | json.dump([], args.output) |
| 59 | |
| 60 | |
| 61 | if __name__ == '__main__': |
| 62 | # Conform minimally to the protocol defined by ScriptTest. |
| 63 | if 'compile_targets' in sys.argv: |
| 64 | funcs = { |
| 65 | 'run': None, |
| 66 | 'compile_targets': main_compile_targets, |
| 67 | } |
| 68 | sys.exit(common.run_script(sys.argv[1:], funcs)) |
| 69 | sys.exit(main()) |