| 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', |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 type=int, default=os.environ.get('GTEST_SHARD_INDEX', 0), | 68 type=int, default=os.environ.get('GTEST_SHARD_INDEX', 0), |
| 69 help='Index of the external shard to run.') | 69 help='Index of the external shard to run.') |
| 70 parser.add_argument( | 70 parser.add_argument( |
| 71 '--test-launcher-total-shards', | 71 '--test-launcher-total-shards', |
| 72 type=int, default=os.environ.get('GTEST_TOTAL_SHARDS', 1), | 72 type=int, default=os.environ.get('GTEST_TOTAL_SHARDS', 1), |
| 73 help='Total number of external shards.') | 73 help='Total number of external shards.') |
| 74 | 74 |
| 75 return parser | 75 return parser |
| 76 | 76 |
| 77 | 77 |
| 78 def AddCommandLineOptions(parser): |
| 79 """Adds arguments to support passing command-line flags to the device.""" |
| 80 parser.add_argument( |
| 81 '--device-flags-file', |
| 82 type=os.path.realpath, |
| 83 help='The relative filepath to a file containing ' |
| 84 'command-line flags to set on the device') |
| 85 # TODO(jbudorick): This is deprecated. Remove once clients have switched |
| 86 # to passing command-line flags directly. |
| 87 parser.add_argument( |
| 88 '-a', '--test-arguments', |
| 89 dest='test_arguments', default='', |
| 90 help=argparse.SUPPRESS) |
| 91 parser.set_defaults(allow_unknown=True) |
| 92 parser.set_defaults(command_line_flags=None) |
| 93 |
| 94 |
| 78 def AddTracingOptions(parser): | 95 def AddTracingOptions(parser): |
| 79 # TODO(shenghuazhang): Move this into AddCommonOptions once it's supported | 96 # TODO(shenghuazhang): Move this into AddCommonOptions once it's supported |
| 80 # for all test types. | 97 # for all test types. |
| 81 parser.add_argument( | 98 parser.add_argument( |
| 82 '--trace-output', | 99 '--trace-output', |
| 83 metavar='FILENAME', type=os.path.realpath, | 100 metavar='FILENAME', type=os.path.realpath, |
| 84 help='Path to save test_runner trace data to.') | 101 help='Path to save test_runner trace data to.') |
| 85 | 102 |
| 86 | 103 |
| 87 def AddCommonOptions(parser): | 104 def AddCommonOptions(parser): |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ' precedence over --debug and --release') | 170 ' precedence over --debug and --release') |
| 154 parser.add_argument( | 171 parser.add_argument( |
| 155 '--repeat', '--gtest_repeat', '--gtest-repeat', | 172 '--repeat', '--gtest_repeat', '--gtest-repeat', |
| 156 dest='repeat', type=int, default=0, | 173 dest='repeat', type=int, default=0, |
| 157 help='Number of times to repeat the specified set of tests.') | 174 help='Number of times to repeat the specified set of tests.') |
| 158 parser.add_argument( | 175 parser.add_argument( |
| 159 '-v', '--verbose', | 176 '-v', '--verbose', |
| 160 dest='verbose_count', default=0, action='count', | 177 dest='verbose_count', default=0, action='count', |
| 161 help='Verbose level (multiple times for more)') | 178 help='Verbose level (multiple times for more)') |
| 162 | 179 |
| 163 AddTestLauncherArgs(parser) | 180 AddTestLauncherOptions(parser) |
| 164 | 181 |
| 165 | 182 |
| 166 def ProcessCommonOptions(args): | 183 def ProcessCommonOptions(args): |
| 167 """Processes and handles all common options.""" | 184 """Processes and handles all common options.""" |
| 168 run_tests_helper.SetLogLevel(args.verbose_count) | 185 run_tests_helper.SetLogLevel(args.verbose_count) |
| 169 constants.SetBuildType(args.build_type) | 186 constants.SetBuildType(args.build_type) |
| 170 if args.output_directory: | 187 if args.output_directory: |
| 171 constants.SetOutputDirectory(args.output_directory) | 188 constants.SetOutputDirectory(args.output_directory) |
| 172 | 189 |
| 173 | 190 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 dest='store_tombstones', action='store_true', | 295 dest='store_tombstones', action='store_true', |
| 279 help='Add tombstones in results if crash.') | 296 help='Add tombstones in results if crash.') |
| 280 parser.add_argument( | 297 parser.add_argument( |
| 281 '-s', '--suite', | 298 '-s', '--suite', |
| 282 dest='suite_name', nargs='+', metavar='SUITE_NAME', required=True, | 299 dest='suite_name', nargs='+', metavar='SUITE_NAME', required=True, |
| 283 help='Executable name of the test suite to run.') | 300 help='Executable name of the test suite to run.') |
| 284 parser.add_argument( | 301 parser.add_argument( |
| 285 '--test-apk-incremental-install-script', | 302 '--test-apk-incremental-install-script', |
| 286 type=os.path.realpath, | 303 type=os.path.realpath, |
| 287 help='Path to install script for the test apk.') | 304 help='Path to install script for the test apk.') |
| 288 parser.add_argument( | |
| 289 '-a', '--test-arguments', | |
| 290 dest='test_arguments', default='', | |
| 291 help='Additional arguments to pass to the test.') | |
| 292 | 305 |
| 293 filter_group = parser.add_mutually_exclusive_group() | 306 filter_group = parser.add_mutually_exclusive_group() |
| 294 filter_group.add_argument( | 307 filter_group.add_argument( |
| 295 '-f', '--gtest_filter', '--gtest-filter', | 308 '-f', '--gtest_filter', '--gtest-filter', |
| 296 dest='test_filter', | 309 dest='test_filter', |
| 297 help='googletest-style filter string.') | 310 help='googletest-style filter string.') |
| 298 filter_group.add_argument( | 311 filter_group.add_argument( |
| 299 '--gtest-filter-file', | 312 '--gtest-filter-file', |
| 300 dest='test_filter_file', type=os.path.realpath, | 313 dest='test_filter_file', type=os.path.realpath, |
| 301 help='Path to file that contains googletest-style filter strings. ' | 314 help='Path to file that contains googletest-style filter strings. ' |
| (...skipping 26 matching lines...) Expand all Loading... |
| 328 parser.add_argument( | 341 parser.add_argument( |
| 329 '--coverage-dir', | 342 '--coverage-dir', |
| 330 type=os.path.realpath, | 343 type=os.path.realpath, |
| 331 help='Directory in which to place all generated ' | 344 help='Directory in which to place all generated ' |
| 332 'EMMA coverage files.') | 345 'EMMA coverage files.') |
| 333 parser.add_argument( | 346 parser.add_argument( |
| 334 '--delete-stale-data', | 347 '--delete-stale-data', |
| 335 action='store_true', dest='delete_stale_data', | 348 action='store_true', dest='delete_stale_data', |
| 336 help='Delete stale test data on the device.') | 349 help='Delete stale test data on the device.') |
| 337 parser.add_argument( | 350 parser.add_argument( |
| 338 '--device-flags', | |
| 339 dest='device_flags', | |
| 340 type=os.path.realpath, | |
| 341 help='The relative filepath to a file containing ' | |
| 342 'command-line flags to set on the device') | |
| 343 parser.add_argument( | |
| 344 '--device-flags-file', | |
| 345 type=os.path.realpath, | |
| 346 help='The relative filepath to a file containing ' | |
| 347 'command-line flags to set on the device') | |
| 348 parser.add_argument( | |
| 349 '--disable-dalvik-asserts', | 351 '--disable-dalvik-asserts', |
| 350 dest='set_asserts', action='store_false', default=True, | 352 dest='set_asserts', action='store_false', default=True, |
| 351 help='Removes the dalvik.vm.enableassertions property') | 353 help='Removes the dalvik.vm.enableassertions property') |
| 352 parser.add_argument( | 354 parser.add_argument( |
| 353 '-E', '--exclude-annotation', | 355 '-E', '--exclude-annotation', |
| 354 dest='exclude_annotation_str', | 356 dest='exclude_annotation_str', |
| 355 help='Comma-separated list of annotations. Exclude tests with these ' | 357 help='Comma-separated list of annotations. Exclude tests with these ' |
| 356 'annotations.') | 358 'annotations.') |
| 357 parser.add_argument( | 359 parser.add_argument( |
| 358 '-f', '--test-filter', '--gtest_filter', '--gtest-filter', | 360 '-f', '--test-filter', '--gtest_filter', '--gtest-filter', |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 command_parsers = parser.add_subparsers( | 820 command_parsers = parser.add_subparsers( |
| 819 title='test types', dest='command') | 821 title='test types', dest='command') |
| 820 | 822 |
| 821 subp = command_parsers.add_parser( | 823 subp = command_parsers.add_parser( |
| 822 'gtest', | 824 'gtest', |
| 823 help='googletest-based C++ tests') | 825 help='googletest-based C++ tests') |
| 824 AddCommonOptions(subp) | 826 AddCommonOptions(subp) |
| 825 AddDeviceOptions(subp) | 827 AddDeviceOptions(subp) |
| 826 AddGTestOptions(subp) | 828 AddGTestOptions(subp) |
| 827 AddTracingOptions(subp) | 829 AddTracingOptions(subp) |
| 830 AddCommandLineOptions(subp) |
| 828 | 831 |
| 829 subp = command_parsers.add_parser( | 832 subp = command_parsers.add_parser( |
| 830 'instrumentation', | 833 'instrumentation', |
| 831 help='InstrumentationTestCase-based Java tests') | 834 help='InstrumentationTestCase-based Java tests') |
| 832 AddCommonOptions(subp) | 835 AddCommonOptions(subp) |
| 833 AddDeviceOptions(subp) | 836 AddDeviceOptions(subp) |
| 834 AddInstrumentationTestOptions(subp) | 837 AddInstrumentationTestOptions(subp) |
| 835 AddTracingOptions(subp) | 838 AddTracingOptions(subp) |
| 839 AddCommandLineOptions(subp) |
| 836 | 840 |
| 837 subp = command_parsers.add_parser( | 841 subp = command_parsers.add_parser( |
| 838 'junit', | 842 'junit', |
| 839 help='JUnit4-based Java tests') | 843 help='JUnit4-based Java tests') |
| 840 AddCommonOptions(subp) | 844 AddCommonOptions(subp) |
| 841 AddJUnitTestOptions(subp) | 845 AddJUnitTestOptions(subp) |
| 842 | 846 |
| 843 subp = command_parsers.add_parser( | 847 subp = command_parsers.add_parser( |
| 844 'linker', | 848 'linker', |
| 845 help='linker tests') | 849 help='linker tests') |
| (...skipping 15 matching lines...) Expand all Loading... |
| 861 AddDeviceOptions(subp) | 865 AddDeviceOptions(subp) |
| 862 AddPerfTestOptions(subp) | 866 AddPerfTestOptions(subp) |
| 863 AddTracingOptions(subp) | 867 AddTracingOptions(subp) |
| 864 | 868 |
| 865 subp = command_parsers.add_parser( | 869 subp = command_parsers.add_parser( |
| 866 'python', | 870 'python', |
| 867 help='python tests based on unittest.TestCase') | 871 help='python tests based on unittest.TestCase') |
| 868 AddCommonOptions(subp) | 872 AddCommonOptions(subp) |
| 869 AddPythonTestOptions(subp) | 873 AddPythonTestOptions(subp) |
| 870 | 874 |
| 871 args = parser.parse_args() | 875 args, unknown_args = parser.parse_known_args() |
| 876 if unknown_args: |
| 877 if hasattr(args, 'allow_unknown') and args.allow_unknown: |
| 878 args.command_line_flags = unknown_args |
| 879 else: |
| 880 parser.error('unrecognized arguments: %s' % ' '.join(unknown_args)) |
| 872 | 881 |
| 873 try: | 882 try: |
| 874 return RunTestsCommand(args) | 883 return RunTestsCommand(args) |
| 875 except base_error.BaseError as e: | 884 except base_error.BaseError as e: |
| 876 logging.exception('Error occurred.') | 885 logging.exception('Error occurred.') |
| 877 if e.is_infra_error: | 886 if e.is_infra_error: |
| 878 return constants.INFRA_EXIT_CODE | 887 return constants.INFRA_EXIT_CODE |
| 879 return constants.ERROR_EXIT_CODE | 888 return constants.ERROR_EXIT_CODE |
| 880 except: # pylint: disable=W0702 | 889 except: # pylint: disable=W0702 |
| 881 logging.exception('Unrecognized error occurred.') | 890 logging.exception('Unrecognized error occurred.') |
| 882 return constants.ERROR_EXIT_CODE | 891 return constants.ERROR_EXIT_CODE |
| 883 | 892 |
| 884 | 893 |
| 885 if __name__ == '__main__': | 894 if __name__ == '__main__': |
| 886 sys.exit(main()) | 895 sys.exit(main()) |
| OLD | NEW |