Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Runs all types of tests from one unified interface.""" | 7 """Runs all types of tests from one unified interface.""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import collections | 10 import collections |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 from pylib.results import json_results | 35 from pylib.results import json_results |
| 36 from pylib.results import report_results | 36 from pylib.results import report_results |
| 37 | 37 |
| 38 from py_utils import contextlib_ext | 38 from py_utils import contextlib_ext |
| 39 | 39 |
| 40 | 40 |
| 41 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( | 41 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( |
| 42 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) | 42 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) |
| 43 | 43 |
| 44 | 44 |
| 45 def AddTestLauncherArgs(parser): | 45 def AddTestLauncherOptions(parser): |
| 46 """Adds arguments mirroring //base/test/launcher. | 46 """Adds arguments mirroring //base/test/launcher. |
| 47 | 47 |
| 48 Args: | 48 Args: |
| 49 parser: The parser to which arguments should be added. | 49 parser: The parser to which arguments should be added. |
| 50 Returns: | 50 Returns: |
| 51 The given parser. | 51 The given parser. |
| 52 """ | 52 """ |
| 53 parser.add_argument( | 53 parser.add_argument( |
| 54 '--test-launcher-retry-limit', | 54 '--test-launcher-retry-limit', |
| 55 '--test_launcher_retry_limit', | 55 '--test_launcher_retry_limit', |
| 56 '--num_retries', '--num-retries', | 56 '--num_retries', '--num-retries', |
| 57 dest='num_retries', type=int, default=2, | 57 dest='num_retries', type=int, default=2, |
| 58 help='Number of retries for a test before ' | 58 help='Number of retries for a test before ' |
| 59 'giving up (default: %(default)s).') | 59 'giving up (default: %(default)s).') |
| 60 parser.add_argument( | 60 parser.add_argument( |
| 61 '--test-launcher-summary-output', | 61 '--test-launcher-summary-output', |
| 62 '--json-results-file', | 62 '--json-results-file', |
| 63 dest='json_results_file', type=os.path.realpath, | 63 dest='json_results_file', type=os.path.realpath, |
| 64 help='If set, will dump results in JSON form ' | 64 help='If set, will dump results in JSON form ' |
| 65 'to specified file.') | 65 'to specified file.') |
| 66 | 66 |
| 67 return parser | 67 return parser |
| 68 | 68 |
| 69 | 69 |
| 70 def AddCommandLineOptions(parser): | |
| 71 """Adds arguments to support passing command-line flags to the device.""" | |
| 72 parser.add_argument( | |
| 73 '--device-flags-file', | |
| 74 type=os.path.realpath, | |
| 75 help='The relative filepath to a file containing ' | |
| 76 'command-line flags to set on the device') | |
| 77 parser.add_argument( | |
| 78 '-a', '--test-arguments', | |
| 79 dest='test_arguments', default='', | |
| 80 help='DEPRECATED. Pass such flags directly.') | |
|
shenghuazhang
2017/03/14 05:45:05
This version enables deprecated argument '--test-a
jbudorick
2017/03/15 18:28:00
hrm, good point. As this is deprecated, though, I'
| |
| 81 parser.set_defaults(allow_unknown=True) | |
| 82 | |
| 83 | |
| 70 def AddTracingOptions(parser): | 84 def AddTracingOptions(parser): |
| 71 # TODO(shenghuazhang): Move this into AddCommonOptions once it's supported | 85 # TODO(shenghuazhang): Move this into AddCommonOptions once it's supported |
| 72 # for all test types. | 86 # for all test types. |
| 73 parser.add_argument( | 87 parser.add_argument( |
| 74 '--trace-output', | 88 '--trace-output', |
| 75 metavar='FILENAME', type=os.path.realpath, | 89 metavar='FILENAME', type=os.path.realpath, |
| 76 help='Path to save test_runner trace data to.') | 90 help='Path to save test_runner trace data to.') |
| 77 | 91 |
| 78 | 92 |
| 79 def AddCommonOptions(parser): | 93 def AddCommonOptions(parser): |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 ' precedence over --debug and --release') | 159 ' precedence over --debug and --release') |
| 146 parser.add_argument( | 160 parser.add_argument( |
| 147 '--repeat', '--gtest_repeat', '--gtest-repeat', | 161 '--repeat', '--gtest_repeat', '--gtest-repeat', |
| 148 dest='repeat', type=int, default=0, | 162 dest='repeat', type=int, default=0, |
| 149 help='Number of times to repeat the specified set of tests.') | 163 help='Number of times to repeat the specified set of tests.') |
| 150 parser.add_argument( | 164 parser.add_argument( |
| 151 '-v', '--verbose', | 165 '-v', '--verbose', |
| 152 dest='verbose_count', default=0, action='count', | 166 dest='verbose_count', default=0, action='count', |
| 153 help='Verbose level (multiple times for more)') | 167 help='Verbose level (multiple times for more)') |
| 154 | 168 |
| 155 AddTestLauncherArgs(parser) | 169 AddTestLauncherOptions(parser) |
| 156 | 170 |
| 157 | 171 |
| 158 def ProcessCommonOptions(args): | 172 def ProcessCommonOptions(args): |
| 159 """Processes and handles all common options.""" | 173 """Processes and handles all common options.""" |
| 160 run_tests_helper.SetLogLevel(args.verbose_count) | 174 run_tests_helper.SetLogLevel(args.verbose_count) |
| 161 constants.SetBuildType(args.build_type) | 175 constants.SetBuildType(args.build_type) |
| 162 if args.output_directory: | 176 if args.output_directory: |
| 163 constants.SetOutputDirectory(args.output_directory) | 177 constants.SetOutputDirectory(args.output_directory) |
| 164 | 178 |
| 165 # Some things such as Forwarder require ADB to be in the environment path. | 179 # Some things such as Forwarder require ADB to be in the environment path. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 dest='store_tombstones', action='store_true', | 289 dest='store_tombstones', action='store_true', |
| 276 help='Add tombstones in results if crash.') | 290 help='Add tombstones in results if crash.') |
| 277 parser.add_argument( | 291 parser.add_argument( |
| 278 '-s', '--suite', | 292 '-s', '--suite', |
| 279 dest='suite_name', nargs='+', metavar='SUITE_NAME', required=True, | 293 dest='suite_name', nargs='+', metavar='SUITE_NAME', required=True, |
| 280 help='Executable name of the test suite to run.') | 294 help='Executable name of the test suite to run.') |
| 281 parser.add_argument( | 295 parser.add_argument( |
| 282 '--test-apk-incremental-install-script', | 296 '--test-apk-incremental-install-script', |
| 283 type=os.path.realpath, | 297 type=os.path.realpath, |
| 284 help='Path to install script for the test apk.') | 298 help='Path to install script for the test apk.') |
| 285 parser.add_argument( | |
| 286 '-a', '--test-arguments', | |
| 287 dest='test_arguments', default='', | |
| 288 help='Additional arguments to pass to the test.') | |
| 289 | 299 |
| 290 filter_group = parser.add_mutually_exclusive_group() | 300 filter_group = parser.add_mutually_exclusive_group() |
| 291 filter_group.add_argument( | 301 filter_group.add_argument( |
| 292 '-f', '--gtest_filter', '--gtest-filter', | 302 '-f', '--gtest_filter', '--gtest-filter', |
| 293 dest='test_filter', | 303 dest='test_filter', |
| 294 help='googletest-style filter string.') | 304 help='googletest-style filter string.') |
| 295 filter_group.add_argument( | 305 filter_group.add_argument( |
| 296 '--gtest-filter-file', | 306 '--gtest-filter-file', |
| 297 dest='test_filter_file', type=os.path.realpath, | 307 dest='test_filter_file', type=os.path.realpath, |
| 298 help='Path to file that contains googletest-style filter strings. ' | 308 help='Path to file that contains googletest-style filter strings. ' |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 325 parser.add_argument( | 335 parser.add_argument( |
| 326 '--coverage-dir', | 336 '--coverage-dir', |
| 327 type=os.path.realpath, | 337 type=os.path.realpath, |
| 328 help='Directory in which to place all generated ' | 338 help='Directory in which to place all generated ' |
| 329 'EMMA coverage files.') | 339 'EMMA coverage files.') |
| 330 parser.add_argument( | 340 parser.add_argument( |
| 331 '--delete-stale-data', | 341 '--delete-stale-data', |
| 332 action='store_true', dest='delete_stale_data', | 342 action='store_true', dest='delete_stale_data', |
| 333 help='Delete stale test data on the device.') | 343 help='Delete stale test data on the device.') |
| 334 parser.add_argument( | 344 parser.add_argument( |
| 335 '--device-flags', | |
| 336 dest='device_flags', | |
| 337 type=os.path.realpath, | |
| 338 help='The relative filepath to a file containing ' | |
| 339 'command-line flags to set on the device') | |
| 340 parser.add_argument( | |
| 341 '--device-flags-file', | |
| 342 type=os.path.realpath, | |
| 343 help='The relative filepath to a file containing ' | |
| 344 'command-line flags to set on the device') | |
| 345 parser.add_argument( | |
| 346 '--disable-dalvik-asserts', | 345 '--disable-dalvik-asserts', |
| 347 dest='set_asserts', action='store_false', default=True, | 346 dest='set_asserts', action='store_false', default=True, |
| 348 help='Removes the dalvik.vm.enableassertions property') | 347 help='Removes the dalvik.vm.enableassertions property') |
| 349 parser.add_argument( | 348 parser.add_argument( |
| 350 '-E', '--exclude-annotation', | 349 '-E', '--exclude-annotation', |
| 351 dest='exclude_annotation_str', | 350 dest='exclude_annotation_str', |
| 352 help='Comma-separated list of annotations. Exclude tests with these ' | 351 help='Comma-separated list of annotations. Exclude tests with these ' |
| 353 'annotations.') | 352 'annotations.') |
| 354 parser.add_argument( | 353 parser.add_argument( |
| 355 '-f', '--test-filter', '--gtest_filter', '--gtest-filter', | 354 '-f', '--test-filter', '--gtest_filter', '--gtest-filter', |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 command_parsers = parser.add_subparsers( | 814 command_parsers = parser.add_subparsers( |
| 816 title='test types', dest='command') | 815 title='test types', dest='command') |
| 817 | 816 |
| 818 subp = command_parsers.add_parser( | 817 subp = command_parsers.add_parser( |
| 819 'gtest', | 818 'gtest', |
| 820 help='googletest-based C++ tests') | 819 help='googletest-based C++ tests') |
| 821 AddCommonOptions(subp) | 820 AddCommonOptions(subp) |
| 822 AddDeviceOptions(subp) | 821 AddDeviceOptions(subp) |
| 823 AddGTestOptions(subp) | 822 AddGTestOptions(subp) |
| 824 AddTracingOptions(subp) | 823 AddTracingOptions(subp) |
| 824 AddCommandLineOptions(subp) | |
| 825 | 825 |
| 826 subp = command_parsers.add_parser( | 826 subp = command_parsers.add_parser( |
| 827 'instrumentation', | 827 'instrumentation', |
| 828 help='InstrumentationTestCase-based Java tests') | 828 help='InstrumentationTestCase-based Java tests') |
| 829 AddCommonOptions(subp) | 829 AddCommonOptions(subp) |
| 830 AddDeviceOptions(subp) | 830 AddDeviceOptions(subp) |
| 831 AddInstrumentationTestOptions(subp) | 831 AddInstrumentationTestOptions(subp) |
| 832 AddTracingOptions(subp) | 832 AddTracingOptions(subp) |
| 833 AddCommandLineOptions(subp) | |
| 833 | 834 |
| 834 subp = command_parsers.add_parser( | 835 subp = command_parsers.add_parser( |
| 835 'junit', | 836 'junit', |
| 836 help='JUnit4-based Java tests') | 837 help='JUnit4-based Java tests') |
| 837 AddCommonOptions(subp) | 838 AddCommonOptions(subp) |
| 838 AddJUnitTestOptions(subp) | 839 AddJUnitTestOptions(subp) |
| 839 | 840 |
| 840 subp = command_parsers.add_parser( | 841 subp = command_parsers.add_parser( |
| 841 'linker', | 842 'linker', |
| 842 help='linker tests') | 843 help='linker tests') |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 858 AddDeviceOptions(subp) | 859 AddDeviceOptions(subp) |
| 859 AddPerfTestOptions(subp) | 860 AddPerfTestOptions(subp) |
| 860 AddTracingOptions(subp) | 861 AddTracingOptions(subp) |
| 861 | 862 |
| 862 subp = command_parsers.add_parser( | 863 subp = command_parsers.add_parser( |
| 863 'python', | 864 'python', |
| 864 help='python tests based on unittest.TestCase') | 865 help='python tests based on unittest.TestCase') |
| 865 AddCommonOptions(subp) | 866 AddCommonOptions(subp) |
| 866 AddPythonTestOptions(subp) | 867 AddPythonTestOptions(subp) |
| 867 | 868 |
| 868 args = parser.parse_args() | 869 args, unknown_args = parser.parse_known_args() |
| 870 if unknown_args: | |
|
mikecase (-- gone --)
2017/03/13 23:59:47
Do we want to do this? Now if you spell an argumen
jbudorick
2017/03/15 18:28:00
This is somewhat of a concern, but as I understand
| |
| 871 if hasattr(args, 'allow_unknown') and args.allow_unknown: | |
| 872 args.command_line_flags = unknown_args | |
| 873 else: | |
| 874 parser.error('unrecognized arguments: %s' % ' '.join(unknown_args)) | |
| 869 | 875 |
| 870 try: | 876 try: |
| 871 return RunTestsCommand(args) | 877 return RunTestsCommand(args) |
| 872 except base_error.BaseError as e: | 878 except base_error.BaseError as e: |
| 873 logging.exception('Error occurred.') | 879 logging.exception('Error occurred.') |
| 874 if e.is_infra_error: | 880 if e.is_infra_error: |
| 875 return constants.INFRA_EXIT_CODE | 881 return constants.INFRA_EXIT_CODE |
| 876 return constants.ERROR_EXIT_CODE | 882 return constants.ERROR_EXIT_CODE |
| 877 except: # pylint: disable=W0702 | 883 except: # pylint: disable=W0702 |
| 878 logging.exception('Unrecognized error occurred.') | 884 logging.exception('Unrecognized error occurred.') |
| 879 return constants.ERROR_EXIT_CODE | 885 return constants.ERROR_EXIT_CODE |
| 880 | 886 |
| 881 | 887 |
| 882 if __name__ == '__main__': | 888 if __name__ == '__main__': |
| 883 sys.exit(main()) | 889 sys.exit(main()) |
| OLD | NEW |