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 #TODO(craigdh): pylib/utils/ should not depend on pylib/. | 7 #TODO(craigdh): pylib/utils/ should not depend on pylib/. |
8 from pylib import constants | 8 from pylib import constants |
9 | 9 |
10 import optparse | 10 import optparse |
(...skipping 10 matching lines...) Expand all Loading... |
21 default_build_type = os.environ['BUILDTYPE'] | 21 default_build_type = os.environ['BUILDTYPE'] |
22 option_parser.add_option('--debug', action='store_const', const='Debug', | 22 option_parser.add_option('--debug', action='store_const', const='Debug', |
23 dest='build_type', default=default_build_type, | 23 dest='build_type', default=default_build_type, |
24 help='If set, run test suites under out/Debug. ' | 24 help='If set, run test suites under out/Debug. ' |
25 'Default is env var BUILDTYPE or Debug') | 25 'Default is env var BUILDTYPE or Debug') |
26 option_parser.add_option('--release', action='store_const', const='Release', | 26 option_parser.add_option('--release', action='store_const', const='Release', |
27 dest='build_type', | 27 dest='build_type', |
28 help='If set, run test suites under out/Release. ' | 28 help='If set, run test suites under out/Release. ' |
29 'Default is env var BUILDTYPE or Debug.') | 29 'Default is env var BUILDTYPE or Debug.') |
30 | 30 |
| 31 |
31 def AddInstallAPKOption(option_parser): | 32 def AddInstallAPKOption(option_parser): |
32 """Decorates OptionParser with apk option used to install the APK.""" | 33 """Decorates OptionParser with apk option used to install the APK.""" |
33 AddBuildTypeOption(option_parser) | 34 AddBuildTypeOption(option_parser) |
34 option_parser.add_option('--apk', | 35 option_parser.add_option('--apk', |
35 help=('The name of the apk containing the ' | 36 help=('The name of the apk containing the ' |
36 ' application (with the .apk extension).')) | 37 ' application (with the .apk extension).')) |
37 option_parser.add_option('--apk_package', | 38 option_parser.add_option('--apk_package', |
38 help=('The package name used by the apk containing ' | 39 help=('The package name used by the apk containing ' |
39 'the application.')) | 40 'the application.')) |
40 option_parser.add_option('--keep_data', | 41 option_parser.add_option('--keep_data', |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 default=2, | 121 default=2, |
121 help='Repeat count on test timeout.') | 122 help='Repeat count on test timeout.') |
122 option_parser.add_option('--exit_code', action='store_true', | 123 option_parser.add_option('--exit_code', action='store_true', |
123 help='If set, the exit code will be total number ' | 124 help='If set, the exit code will be total number ' |
124 'of failures.') | 125 'of failures.') |
125 option_parser.add_option('--exe', action='store_true', | 126 option_parser.add_option('--exe', action='store_true', |
126 help='If set, use the exe test runner instead of ' | 127 help='If set, use the exe test runner instead of ' |
127 'the APK.') | 128 'the APK.') |
128 | 129 |
129 | 130 |
130 def AddInstrumentationOptions(option_parser): | 131 def AddCommonInstrumentationOptions(option_parser): |
131 """Decorates OptionParser with instrumentation tests options.""" | 132 """Decorates OptionParser with base instrumentation tests options.""" |
132 | 133 |
133 AddTestRunnerOptions(option_parser) | 134 AddTestRunnerOptions(option_parser) |
134 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', | 135 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', |
135 action='store_true', help='Wait for debugger.') | 136 action='store_true', help='Wait for debugger.') |
136 option_parser.add_option('-I', dest='install_apk', help='Install APK.', | |
137 action='store_true') | |
138 option_parser.add_option('-f', '--test_filter', | 137 option_parser.add_option('-f', '--test_filter', |
139 help='Test filter (if not fully qualified, ' | 138 help='Test filter (if not fully qualified, ' |
140 'will run all matches).') | 139 'will run all matches).') |
141 option_parser.add_option('-A', '--annotation', dest='annotation_str', | 140 option_parser.add_option('-A', '--annotation', dest='annotation_str', |
142 help=('Run only tests with any of the given ' | 141 help=('Run only tests with any of the given ' |
143 'annotations. ' | 142 'annotations. ' |
144 'An annotation can be either a key or a ' | 143 'An annotation can be either a key or a ' |
145 'key-values pair. ' | 144 'key-values pair. ' |
146 'A test that has no annotation is ' | 145 'A test that has no annotation is ' |
147 'considered "SmallTest".')) | 146 'considered "SmallTest".')) |
148 option_parser.add_option('-j', '--java_only', action='store_true', | 147 option_parser.add_option('-j', '--java_only', action='store_true', |
149 help='Run only the Java tests.') | 148 help='Run only the Java tests.') |
150 option_parser.add_option('-p', '--python_only', action='store_true', | 149 option_parser.add_option('-p', '--python_only', action='store_true', |
151 help='Run only the Python tests.') | 150 help='Run only the Python tests.') |
152 option_parser.add_option('-n', '--run_count', type='int', | 151 option_parser.add_option('-n', '--run_count', type='int', |
153 dest='number_of_runs', default=1, | 152 dest='number_of_runs', default=1, |
154 help=('How many times to run each test, regardless ' | 153 help=('How many times to run each test, regardless ' |
155 'of the result. (Default is 1)')) | 154 'of the result. (Default is 1)')) |
156 option_parser.add_option('--test-apk', dest='test_apk', | |
157 help=('The name of the apk containing the tests ' | |
158 '(without the .apk extension). For SDK ' | |
159 'builds, the apk name without the debug ' | |
160 'suffix(for example, ContentShellTest).')) | |
161 option_parser.add_option('--screenshot', dest='screenshot_failures', | 155 option_parser.add_option('--screenshot', dest='screenshot_failures', |
162 action='store_true', | 156 action='store_true', |
163 help='Capture screenshots of test failures') | 157 help='Capture screenshots of test failures') |
164 option_parser.add_option('--save-perf-json', action='store_true', | 158 option_parser.add_option('--save-perf-json', action='store_true', |
165 help='Saves the JSON file for each UI Perf test.') | 159 help='Saves the JSON file for each UI Perf test.') |
166 option_parser.add_option('--shard_retries', type=int, default=1, | 160 option_parser.add_option('--shard_retries', type=int, default=1, |
167 help=('Number of times to retry each failure when ' | 161 help=('Number of times to retry each failure when ' |
168 'sharding.')) | 162 'sharding.')) |
169 option_parser.add_option('--official-build', help='Run official build tests.') | 163 option_parser.add_option('--official-build', help='Run official build tests.') |
170 option_parser.add_option('--device', | 164 option_parser.add_option('--device', |
(...skipping 15 matching lines...) Expand all Loading... |
186 help='Run with java assertions disabled.') | 180 help='Run with java assertions disabled.') |
187 option_parser.add_option('--test_data', action='append', default=[], | 181 option_parser.add_option('--test_data', action='append', default=[], |
188 help=('Each instance defines a directory of test ' | 182 help=('Each instance defines a directory of test ' |
189 'data that should be copied to the target(s) ' | 183 'data that should be copied to the target(s) ' |
190 'before running the tests. The argument ' | 184 'before running the tests. The argument ' |
191 'should be of the form <target>:<source>, ' | 185 'should be of the form <target>:<source>, ' |
192 '<target> is relative to the device data' | 186 '<target> is relative to the device data' |
193 'directory, and <source> is relative to the ' | 187 'directory, and <source> is relative to the ' |
194 'chromium build directory.')) | 188 'chromium build directory.')) |
195 | 189 |
196 def ValidateInstrumentationOptions(option_parser, options, args): | 190 |
197 """Validate options/arguments and populate options with defaults.""" | 191 def AddInstrumentationOptions(option_parser): |
| 192 """Decorates OptionParser with instrumentation tests options.""" |
| 193 |
| 194 AddCommonInstrumentationOptions(option_parser) |
| 195 option_parser.add_option('-I', dest='install_apk', |
| 196 help='Install APK.', action='store_true') |
| 197 option_parser.add_option('--test-apk', dest='test_apk', |
| 198 help=('The name of the apk containing the tests ' |
| 199 '(without the .apk extension). For SDK ' |
| 200 'builds, the apk name without the debug ' |
| 201 'suffix(for example, ContentShellTest).')) |
| 202 |
| 203 |
| 204 def AddUIAutomatorOptions(option_parser): |
| 205 """Decorates OptionParser with uiautomator tests options.""" |
| 206 |
| 207 AddCommonInstrumentationOptions(option_parser) |
| 208 option_parser.add_option( |
| 209 '--package-name', |
| 210 help=('The package name used by the apk containing the application.')) |
| 211 option_parser.add_option( |
| 212 '--uiautomator-jar', |
| 213 help=('Path to the uiautomator jar to be installed on the device.')) |
| 214 option_parser.add_option( |
| 215 '--uiautomator-info-jar', |
| 216 help=('Path to the uiautomator jar for use by proguard.')) |
| 217 |
| 218 |
| 219 def ValidateCommonInstrumentationOptions(option_parser, options, args): |
| 220 """Validate common options/arguments and populate options with defaults.""" |
198 if len(args) > 1: | 221 if len(args) > 1: |
199 option_parser.print_help(sys.stderr) | 222 option_parser.print_help(sys.stderr) |
200 option_parser.error('Unknown arguments: %s' % args[1:]) | 223 option_parser.error('Unknown arguments: %s' % args[1:]) |
| 224 |
201 if options.java_only and options.python_only: | 225 if options.java_only and options.python_only: |
202 option_parser.error('Options java_only (-j) and python_only (-p) ' | 226 option_parser.error('Options java_only (-j) and python_only (-p) ' |
203 'are mutually exclusive.') | 227 'are mutually exclusive.') |
204 if not options.test_apk: | |
205 option_parser.error('--test-apk must be specified.') | |
206 | |
207 options.run_java_tests = True | 228 options.run_java_tests = True |
208 options.run_python_tests = True | 229 options.run_python_tests = True |
209 if options.java_only: | 230 if options.java_only: |
210 options.run_python_tests = False | 231 options.run_python_tests = False |
211 elif options.python_only: | 232 elif options.python_only: |
212 options.run_java_tests = False | 233 options.run_java_tests = False |
213 | 234 |
| 235 if options.annotation_str: |
| 236 options.annotation = options.annotation_str.split() |
| 237 elif options.test_filter: |
| 238 options.annotation = [] |
| 239 else: |
| 240 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] |
| 241 |
| 242 |
| 243 def ValidateInstrumentationOptions(option_parser, options, args): |
| 244 """Validate options/arguments and populate options with defaults.""" |
| 245 ValidateCommonInstrumentationOptions(option_parser, options, args) |
| 246 |
| 247 if not options.test_apk: |
| 248 option_parser.error('--test-apk must be specified.') |
| 249 |
214 if os.path.exists(options.test_apk): | 250 if os.path.exists(options.test_apk): |
215 # The APK is fully qualified, assume the JAR lives along side. | 251 # The APK is fully qualified, assume the JAR lives along side. |
216 options.test_apk_path = options.test_apk | 252 options.test_apk_path = options.test_apk |
217 options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] + | 253 options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] + |
218 '.jar') | 254 '.jar') |
219 else: | 255 else: |
220 options.test_apk_path = os.path.join(_SDK_OUT_DIR, | 256 options.test_apk_path = os.path.join(_SDK_OUT_DIR, |
221 options.build_type, | 257 options.build_type, |
222 constants.SDK_BUILD_APKS_DIR, | 258 constants.SDK_BUILD_APKS_DIR, |
223 '%s.apk' % options.test_apk) | 259 '%s.apk' % options.test_apk) |
224 options.test_apk_jar_path = os.path.join( | 260 options.test_apk_jar_path = os.path.join( |
225 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR, | 261 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR, |
226 '%s.jar' % options.test_apk) | 262 '%s.jar' % options.test_apk) |
227 if options.annotation_str: | 263 |
228 options.annotation = options.annotation_str.split() | 264 |
229 elif options.test_filter: | 265 def ValidateUIAutomatorOptions(option_parser, options, args): |
230 options.annotation = [] | 266 """Validate uiautomator options/arguments.""" |
231 else: | 267 ValidateCommonInstrumentationOptions(option_parser, options, args) |
232 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] | 268 |
| 269 if not options.package_name: |
| 270 option_parser.error('--package-name must be specified.') |
| 271 |
| 272 if not options.uiautomator_jar: |
| 273 option_parser.error('--uiautomator-jar must be specified.') |
| 274 |
| 275 if not options.uiautomator_info_jar: |
| 276 option_parser.error('--uiautomator-info-jar must be specified.') |
| 277 |
OLD | NEW |