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 | 7 import constants |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 | 10 |
11 _SDK_OUT_DIR = os.path.join(constants.CHROME_DIR, 'out') | 11 _SDK_OUT_DIR = os.path.join(constants.CHROME_DIR, 'out') |
12 | 12 |
13 | 13 |
14 def AddBuildTypeOption(option_parser): | 14 def AddBuildTypeOption(option_parser): |
| 15 """Decorates OptionParser with build type option.""" |
15 default_build_type = 'Debug' | 16 default_build_type = 'Debug' |
16 if 'BUILDTYPE' in os.environ: | 17 if 'BUILDTYPE' in os.environ: |
17 default_build_type = os.environ['BUILDTYPE'] | 18 default_build_type = os.environ['BUILDTYPE'] |
18 option_parser.add_option('--debug', action='store_const', const='Debug', | 19 option_parser.add_option('--debug', action='store_const', const='Debug', |
19 dest='build_type', default=default_build_type, | 20 dest='build_type', default=default_build_type, |
20 help='If set, run test suites under out/Debug. ' | 21 help='If set, run test suites under out/Debug. ' |
21 'Default is env var BUILDTYPE or Debug') | 22 'Default is env var BUILDTYPE or Debug') |
22 option_parser.add_option('--release', action='store_const', const='Release', | 23 option_parser.add_option('--release', action='store_const', const='Release', |
23 dest='build_type', | 24 dest='build_type', |
24 help='If set, run test suites under out/Release. ' | 25 help='If set, run test suites under out/Release. ' |
25 'Default is env var BUILDTYPE or Debug.') | 26 'Default is env var BUILDTYPE or Debug.') |
26 | 27 |
27 | 28 |
28 def CreateTestRunnerOptionParser(usage=None, default_timeout=60): | 29 def AddTestRunnerOptions(option_parser, default_timeout=60): |
29 """Returns a new OptionParser with arguments applicable to all tests.""" | 30 """Decorates OptionParser with options applicable to all tests.""" |
30 option_parser = optparse.OptionParser(usage=usage) | 31 |
31 option_parser.add_option('-t', dest='timeout', | 32 option_parser.add_option('-t', dest='timeout', |
32 help='Timeout to wait for each test', | 33 help='Timeout to wait for each test', |
33 type='int', | 34 type='int', |
34 default=default_timeout) | 35 default=default_timeout) |
35 option_parser.add_option('-c', dest='cleanup_test_files', | 36 option_parser.add_option('-c', dest='cleanup_test_files', |
36 help='Cleanup test files on the device after run', | 37 help='Cleanup test files on the device after run', |
37 action='store_true') | 38 action='store_true') |
38 option_parser.add_option('-v', | 39 option_parser.add_option('-v', |
39 '--verbose', | 40 '--verbose', |
40 dest='verbose_count', | 41 dest='verbose_count', |
41 default=0, | 42 default=0, |
42 action='count', | 43 action='count', |
43 help='Verbose level (multiple times for more)') | 44 help='Verbose level (multiple times for more)') |
44 profilers = ['devicestatsmonitor', 'chrometrace', 'dumpheap', 'smaps', | 45 profilers = ['devicestatsmonitor', 'chrometrace', 'dumpheap', 'smaps', |
45 'traceview'] | 46 'traceview'] |
46 option_parser.add_option('--profiler', dest='profilers', action='append', | 47 option_parser.add_option('--profiler', dest='profilers', action='append', |
47 choices=profilers, | 48 choices=profilers, |
48 help='Profiling tool to run during test. ' | 49 help='Profiling tool to run during test. ' |
49 'Pass multiple times to run multiple profilers. ' | 50 'Pass multiple times to run multiple profilers. ' |
50 'Available profilers: %s' % profilers) | 51 'Available profilers: %s' % profilers) |
51 option_parser.add_option('--tool', | 52 option_parser.add_option('--tool', |
52 dest='tool', | 53 dest='tool', |
53 help='Run the test under a tool ' | 54 help='Run the test under a tool ' |
54 '(use --tool help to list them)') | 55 '(use --tool help to list them)') |
55 AddBuildTypeOption(option_parser) | 56 AddBuildTypeOption(option_parser) |
56 return option_parser | |
57 | 57 |
58 | 58 |
59 def ParseInstrumentationArgs(args): | 59 def AddInstrumentationOptions(option_parser): |
60 """Parse arguments and return options with defaults.""" | 60 """Decorates OptionParser with instrumentation tests options.""" |
61 | 61 |
62 option_parser = CreateTestRunnerOptionParser() | 62 AddTestRunnerOptions(option_parser) |
63 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', | 63 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', |
64 action='store_true', help='Wait for debugger.') | 64 action='store_true', help='Wait for debugger.') |
65 option_parser.add_option('-I', dest='install_apk', help='Install APK.', | 65 option_parser.add_option('-I', dest='install_apk', help='Install APK.', |
66 action='store_true') | 66 action='store_true') |
67 option_parser.add_option('-f', '--test_filter', | 67 option_parser.add_option('-f', '--test_filter', |
68 help='Test filter (if not fully qualified, ' | 68 help='Test filter (if not fully qualified, ' |
69 'will run all matches).') | 69 'will run all matches).') |
70 option_parser.add_option('-A', '--annotation', dest='annotation_str', | 70 option_parser.add_option('-A', '--annotation', dest='annotation_str', |
71 help=('Run only tests with any of the given ' | 71 help=('Run only tests with any of the given ' |
72 'annotations. ' | 72 'annotations. ' |
(...skipping 22 matching lines...) Expand all Loading... |
95 help='Saves the JSON file for each UI Perf test.') | 95 help='Saves the JSON file for each UI Perf test.') |
96 option_parser.add_option('--shard_retries', type=int, default=1, | 96 option_parser.add_option('--shard_retries', type=int, default=1, |
97 help=('Number of times to retry each failure when ' | 97 help=('Number of times to retry each failure when ' |
98 'sharding.')) | 98 'sharding.')) |
99 option_parser.add_option('--official-build', help='Run official build tests.') | 99 option_parser.add_option('--official-build', help='Run official build tests.') |
100 option_parser.add_option('--device', | 100 option_parser.add_option('--device', |
101 help='Serial number of device we should use.') | 101 help='Serial number of device we should use.') |
102 option_parser.add_option('--python_test_root', | 102 option_parser.add_option('--python_test_root', |
103 help='Root of the python-driven tests.') | 103 help='Root of the python-driven tests.') |
104 | 104 |
105 options, args = option_parser.parse_args(args) | 105 def ValidateInstrumentationOptions(options, args): |
| 106 """Validate options/arguments and populate options with defaults.""" |
106 if len(args) > 1: | 107 if len(args) > 1: |
107 option_parser.error('Unknown argument:', args[1:]) | 108 option_parser.error('Unknown argument:', args[1:]) |
108 if options.java_only and options.python_only: | 109 if options.java_only and options.python_only: |
109 option_parser.error('Options java_only (-j) and python_only (-p) ' | 110 option_parser.error('Options java_only (-j) and python_only (-p) ' |
110 'are mutually exclusive') | 111 'are mutually exclusive') |
111 | 112 |
112 options.run_java_tests = True | 113 options.run_java_tests = True |
113 options.run_python_tests = True | 114 options.run_python_tests = True |
114 if options.java_only: | 115 if options.java_only: |
115 options.run_python_tests = False | 116 options.run_python_tests = False |
116 elif options.python_only: | 117 elif options.python_only: |
117 options.run_java_tests = False | 118 options.run_java_tests = False |
118 | 119 |
119 options.test_apk_path = os.path.join(_SDK_OUT_DIR, | 120 options.test_apk_path = os.path.join(_SDK_OUT_DIR, |
120 options.build_type, | 121 options.build_type, |
121 '%s.apk' % options.test_apk) | 122 '%s.apk' % options.test_apk) |
122 options.test_apk_jar_path = os.path.join(_SDK_OUT_DIR, | 123 options.test_apk_jar_path = os.path.join(_SDK_OUT_DIR, |
123 options.build_type, | 124 options.build_type, |
124 '%s.jar' | 125 '%s.jar' |
125 % options.test_apk) | 126 % options.test_apk) |
126 if options.annotation_str: | 127 if options.annotation_str: |
127 options.annotation = options.annotation_str.split() | 128 options.annotation = options.annotation_str.split() |
128 elif options.test_filter: | 129 elif options.test_filter: |
129 options.annotation = [] | 130 options.annotation = [] |
130 else: | 131 else: |
131 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] | 132 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] |
132 | 133 |
133 return options | |
OLD | NEW |