OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Parses options for the instrumentation tests.""" | 5 """Parses options for the instrumentation tests.""" |
6 | 6 |
| 7 import constants |
| 8 import optparse |
7 import os | 9 import os |
8 import optparse | 10 |
9 | 11 |
10 | 12 |
11 def CreateTestRunnerOptionParser(usage=None, default_timeout=60): | 13 def CreateTestRunnerOptionParser(usage=None, default_timeout=60): |
12 """Returns a new OptionParser with arguments applicable to all tests.""" | 14 """Returns a new OptionParser with arguments applicable to all tests.""" |
13 option_parser = optparse.OptionParser(usage=usage) | 15 option_parser = optparse.OptionParser(usage=usage) |
14 option_parser.add_option('-t', dest='timeout', | 16 option_parser.add_option('-t', dest='timeout', |
15 help='Timeout to wait for each test', | 17 help='Timeout to wait for each test', |
16 type='int', | 18 type='int', |
17 default=default_timeout) | 19 default=default_timeout) |
18 option_parser.add_option('-c', dest='cleanup_test_files', | 20 option_parser.add_option('-c', dest='cleanup_test_files', |
19 help='Cleanup test files on the device after run', | 21 help='Cleanup test files on the device after run', |
20 action='store_true', | 22 action='store_true') |
21 default=False) | |
22 option_parser.add_option('-v', | 23 option_parser.add_option('-v', |
23 '--verbose', | 24 '--verbose', |
24 dest='verbose_count', | 25 dest='verbose_count', |
25 default=0, | 26 default=0, |
26 action='count', | 27 action='count', |
27 help='Verbose level (multiple times for more)') | 28 help='Verbose level (multiple times for more)') |
28 profilers = ['activitymonitor', 'chrometrace', 'dumpheap', 'smaps', | 29 profilers = ['activitymonitor', 'chrometrace', 'dumpheap', 'smaps', |
29 'traceview'] | 30 'traceview'] |
30 option_parser.add_option('--profiler', dest='profilers', action='append', | 31 option_parser.add_option('--profiler', dest='profilers', action='append', |
31 choices=profilers, | 32 choices=profilers, |
32 help='Profiling tool to run during test. ' | 33 help='Profiling tool to run during test. ' |
33 'Pass multiple times to run multiple profilers. ' | 34 'Pass multiple times to run multiple profilers. ' |
34 'Available profilers: %s' % profilers) | 35 'Available profilers: %s' % profilers) |
35 option_parser.add_option('--tool', | 36 option_parser.add_option('--tool', |
36 dest='tool', | 37 dest='tool', |
37 help='Run the test under a tool ' | 38 help='Run the test under a tool ' |
38 '(use --tool help to list them)') | 39 '(use --tool help to list them)') |
39 return option_parser | 40 return option_parser |
| 41 |
| 42 |
| 43 def ParseInstrumentationArgs(args): |
| 44 """Parse arguments and return options with defaults.""" |
| 45 |
| 46 option_parser = CreateTestRunnerOptionParser() |
| 47 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', |
| 48 action='store_true', help='Wait for debugger.') |
| 49 option_parser.add_option('-I', dest='install_apk', help='Install APK.', |
| 50 action='store_true') |
| 51 option_parser.add_option('-f', '--test_filter', |
| 52 help='Test filter (if not fully qualified, ' |
| 53 'will run all matches).') |
| 54 option_parser.add_option('-A', '--annotation', dest='annotation_str', |
| 55 help=('Run only tests with any of the given ' |
| 56 'annotations. ' |
| 57 'An annotation can be either a key or a ' |
| 58 'key-values pair. ' |
| 59 'A test that has no annotation is ' |
| 60 'considered "SmallTest".')) |
| 61 option_parser.add_option('-j', '--java_only', action='store_true', |
| 62 help='Run only the Java tests.') |
| 63 option_parser.add_option('-p', '--python_only', action='store_true', |
| 64 help='Run only the Python tests.') |
| 65 option_parser.add_option('-n', '--run_count', type='int', |
| 66 dest='number_of_runs', default=1, |
| 67 help=('How many times to run each test, regardless ' |
| 68 'of the result. (Default is 1)')) |
| 69 option_parser.add_option('--test-apk', dest='test_apk', |
| 70 help=('The name of the apk containing the tests ' |
| 71 '(without the .apk extension).')) |
| 72 option_parser.add_option('--screenshot', dest='screenshot_failures', |
| 73 action='store_true', |
| 74 help='Capture screenshots of test failures') |
| 75 option_parser.add_option('--save-perf-json', action='store_true', |
| 76 help='Saves the JSON file for each UI Perf test.') |
| 77 option_parser.add_option('--shard_retries', type=int, default=1, |
| 78 help=('Number of times to retry each failure when ' |
| 79 'sharding.')) |
| 80 option_parser.add_option('--official-build', help='Run official build tests.') |
| 81 option_parser.add_option('--device', |
| 82 help='Serial number of device we should use.') |
| 83 option_parser.add_option('--python_test_root', |
| 84 help='Root of the python-driven tests.') |
| 85 |
| 86 options, args = option_parser.parse_args(args) |
| 87 if len(args) > 1: |
| 88 option_parser.error('Unknown argument:', args[1:]) |
| 89 if options.java_only and options.python_only: |
| 90 option_parser.error('Options java_only (-j) and python_only (-p) ' |
| 91 'are mutually exclusive') |
| 92 |
| 93 options.run_java_tests = True |
| 94 options.run_python_tests = True |
| 95 if options.java_only: |
| 96 options.run_python_tests = False |
| 97 elif options.python_only: |
| 98 options.run_java_tests = False |
| 99 |
| 100 options.test_apk_path = os.path.join(constants.CHROME_DIR, |
| 101 'out', 'Release', |
| 102 '%s.apk' % options.test_apk) |
| 103 options.test_apk_jar_path = os.path.join(constants.CHROME_DIR, |
| 104 'out', 'Release', |
| 105 '%s.jar' % options.test_apk) |
| 106 if options.annotation_str: |
| 107 options.annotation = options.annotation_str.split() |
| 108 elif options.test_filter: |
| 109 options.annotation = [] |
| 110 else: |
| 111 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] |
| 112 |
| 113 return options |
OLD | NEW |