Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: build/android/pylib/utils/test_options_parser.py

Issue 18514008: Relands test_runner.py, updates buildbot scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moves test_suite option back into gtest only Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/uiautomator/dispatch.py ('k') | build/android/run_browser_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/.
8 from pylib import constants
9
10 import optparse
11 import os 7 import os
12 import sys
13
14 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out')
15 8
16 9
10 # TODO(gkanwar): Some downstream scripts current rely on these functions
11 # existing. This dependency should be removed, and this file deleted, in the
12 # future.
17 def AddBuildTypeOption(option_parser): 13 def AddBuildTypeOption(option_parser):
18 """Decorates OptionParser with build type option.""" 14 """Decorates OptionParser with build type option."""
19 default_build_type = 'Debug' 15 default_build_type = 'Debug'
20 if 'BUILDTYPE' in os.environ: 16 if 'BUILDTYPE' in os.environ:
21 default_build_type = os.environ['BUILDTYPE'] 17 default_build_type = os.environ['BUILDTYPE']
22 option_parser.add_option('--debug', action='store_const', const='Debug', 18 option_parser.add_option('--debug', action='store_const', const='Debug',
23 dest='build_type', default=default_build_type, 19 dest='build_type', default=default_build_type,
24 help='If set, run test suites under out/Debug. ' 20 help='If set, run test suites under out/Debug. '
25 'Default is env var BUILDTYPE or Debug') 21 'Default is env var BUILDTYPE or Debug')
26 option_parser.add_option('--release', action='store_const', const='Release', 22 option_parser.add_option('--release', action='store_const', const='Release',
27 dest='build_type', 23 dest='build_type',
28 help='If set, run test suites under out/Release. ' 24 help='If set, run test suites under out/Release. '
29 'Default is env var BUILDTYPE or Debug.') 25 'Default is env var BUILDTYPE or Debug.')
30
31
32 def AddInstallAPKOption(option_parser):
33 """Decorates OptionParser with apk option used to install the APK."""
34 AddBuildTypeOption(option_parser)
35 option_parser.add_option('--apk',
36 help=('The name of the apk containing the '
37 ' application (with the .apk extension).'))
38 option_parser.add_option('--apk_package',
39 help=('The package name used by the apk containing '
40 'the application.'))
41 option_parser.add_option('--keep_data',
42 action='store_true',
43 default=False,
44 help=('Keep the package data when installing '
45 'the application.'))
46
47
48 def ValidateInstallAPKOption(option_parser, options):
49 if not options.apk:
50 option_parser.error('--apk is mandatory.')
51 if not os.path.exists(options.apk):
52 options.apk = os.path.join(constants.DIR_SOURCE_ROOT,
53 'out', options.build_type,
54 'apks', options.apk)
55 26
56 27
57 def AddTestRunnerOptions(option_parser, default_timeout=60): 28 def AddTestRunnerOptions(option_parser, default_timeout=60):
58 """Decorates OptionParser with options applicable to all tests.""" 29 """Decorates OptionParser with options applicable to all tests."""
59 30
60 option_parser.add_option('-t', dest='timeout', 31 option_parser.add_option('-t', dest='timeout',
61 help='Timeout to wait for each test', 32 help='Timeout to wait for each test',
62 type='int', 33 type='int',
63 default=default_timeout) 34 default=default_timeout)
64 option_parser.add_option('-c', dest='cleanup_test_files', 35 option_parser.add_option('-c', dest='cleanup_test_files',
(...skipping 19 matching lines...) Expand all
84 option_parser.add_option('--tool', 55 option_parser.add_option('--tool',
85 dest='tool', 56 dest='tool',
86 help='Run the test under a tool ' 57 help='Run the test under a tool '
87 '(use --tool help to list them)') 58 '(use --tool help to list them)')
88 option_parser.add_option('--flakiness-dashboard-server', 59 option_parser.add_option('--flakiness-dashboard-server',
89 dest='flakiness_dashboard_server', 60 dest='flakiness_dashboard_server',
90 help=('Address of the server that is hosting the ' 61 help=('Address of the server that is hosting the '
91 'Chrome for Android flakiness dashboard.')) 62 'Chrome for Android flakiness dashboard.'))
92 option_parser.add_option('--skip-deps-push', dest='push_deps', 63 option_parser.add_option('--skip-deps-push', dest='push_deps',
93 action='store_false', default=True, 64 action='store_false', default=True,
94 help='Do not push data dependencies to the device. ' 65 help='Do not push dependencies to the device. '
95 'Use this at own risk for speeding up test ' 66 'Use this at own risk for speeding up test '
96 'execution on local machine.') 67 'execution on local machine.')
97 AddBuildTypeOption(option_parser) 68 AddBuildTypeOption(option_parser)
98
99
100 def AddGTestOptions(option_parser):
101 """Decorates OptionParser with GTest tests options."""
102
103 AddTestRunnerOptions(option_parser, default_timeout=0)
104 option_parser.add_option('-s', '--suite', dest='test_suite',
105 help='Executable name of the test suite to run '
106 '(use -s help to list them).')
107 option_parser.add_option('--out-directory', dest='out_directory',
108 help='Path to the out/ directory, irrespective of '
109 'the build type. Only for non-Chromium uses.')
110 option_parser.add_option('-d', '--device', dest='test_device',
111 help='Target device for the test suite to run on.')
112 option_parser.add_option('-f', '--gtest_filter', dest='gtest_filter',
113 help='gtest filter.')
114 #TODO(craigdh): Replace _ with - in arguments for consistency.
115 option_parser.add_option('-a', '--test_arguments', dest='test_arguments',
116 help='Additional arguments to pass to the test.')
117 option_parser.add_option('-e', '--emulator', dest='use_emulator',
118 action='store_true',
119 help='Run tests in a new instance of emulator.')
120 option_parser.add_option('-n', '--emulator_count',
121 type='int', default=1,
122 help='Number of emulators to launch for running the '
123 'tests.')
124 option_parser.add_option('-x', '--xvfb', dest='use_xvfb',
125 action='store_true',
126 help='Use Xvfb around tests (ignored if not Linux).')
127 option_parser.add_option('--webkit', action='store_true',
128 help='Run the tests from a WebKit checkout.')
129 option_parser.add_option('--exit_code', action='store_true',
130 help='If set, the exit code will be total number '
131 'of failures.')
132 option_parser.add_option('--exe', action='store_true',
133 help='If set, use the exe test runner instead of '
134 'the APK.')
135 option_parser.add_option('--abi', default='armeabi-v7a',
136 help='Platform of emulators to launch.')
137
138
139 def AddCommonInstrumentationOptions(option_parser):
140 """Decorates OptionParser with base instrumentation tests options."""
141
142 AddTestRunnerOptions(option_parser)
143 option_parser.add_option('-f', '--test_filter',
144 help='Test filter (if not fully qualified, '
145 'will run all matches).')
146 option_parser.add_option(
147 '-A', '--annotation', dest='annotation_str',
148 help=('Comma-separated list of annotations. Run only tests with any of '
149 'the given annotations. An annotation can be either a key or a '
150 'key-values pair. A test that has no annotation is considered '
151 '"SmallTest".'))
152 option_parser.add_option(
153 '-E', '--exclude-annotation', dest='exclude_annotation_str',
154 help=('Comma-separated list of annotations. Exclude tests with these '
155 'annotations.'))
156 option_parser.add_option('-j', '--java_only', action='store_true',
157 help='Run only the Java tests.')
158 option_parser.add_option('-p', '--python_only', action='store_true',
159 help='Run only the Python tests.')
160 option_parser.add_option('--screenshot', dest='screenshot_failures',
161 action='store_true',
162 help='Capture screenshots of test failures')
163 option_parser.add_option('--save-perf-json', action='store_true',
164 help='Saves the JSON file for each UI Perf test.')
165 option_parser.add_option('--shard_retries', type=int, default=1,
166 help=('Number of times to retry each failure when '
167 'sharding.'))
168 option_parser.add_option('--official-build', help='Run official build tests.')
169 option_parser.add_option('--device',
170 help='Serial number of device we should use.')
171 option_parser.add_option('--python_test_root',
172 help='Root of the python-driven tests.')
173 option_parser.add_option('--keep_test_server_ports',
174 action='store_true',
175 help='Indicates the test server ports must be '
176 'kept. When this is run via a sharder '
177 'the test server ports should be kept and '
178 'should not be reset.')
179 option_parser.add_option('--buildbot-step-failure',
180 action='store_true',
181 help=('If present, will set the buildbot status '
182 'as STEP_FAILURE, otherwise as STEP_WARNINGS '
183 'when test(s) fail.'))
184 option_parser.add_option('--disable_assertions', action='store_true',
185 help='Run with java assertions disabled.')
186 option_parser.add_option('--test_data', action='append', default=[],
187 help=('Each instance defines a directory of test '
188 'data that should be copied to the target(s) '
189 'before running the tests. The argument '
190 'should be of the form <target>:<source>, '
191 '<target> is relative to the device data'
192 'directory, and <source> is relative to the '
193 'chromium build directory.'))
194
195
196 def AddInstrumentationOptions(option_parser):
197 """Decorates OptionParser with instrumentation tests options."""
198
199 AddCommonInstrumentationOptions(option_parser)
200 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger',
201 action='store_true', help='Wait for debugger.')
202 option_parser.add_option('-I', dest='install_apk',
203 help='Install APK.', action='store_true')
204 option_parser.add_option(
205 '--test-apk', dest='test_apk',
206 help=('The name of the apk containing the tests (without the .apk '
207 'extension; e.g. "ContentShellTest"). Alternatively, this can '
208 'be a full path to the apk.'))
209
210
211 def AddUIAutomatorOptions(option_parser):
212 """Decorates OptionParser with uiautomator tests options."""
213
214 AddCommonInstrumentationOptions(option_parser)
215 option_parser.add_option(
216 '--package-name',
217 help=('The package name used by the apk containing the application.'))
218 option_parser.add_option(
219 '--test-jar', dest='test_jar',
220 help=('The name of the dexed jar containing the tests (without the '
221 '.dex.jar extension). Alternatively, this can be a full path to '
222 'the jar.'))
223
224
225 def ValidateCommonInstrumentationOptions(option_parser, options, args):
226 """Validate common options/arguments and populate options with defaults."""
227 if len(args) > 1:
228 option_parser.print_help(sys.stderr)
229 option_parser.error('Unknown arguments: %s' % args[1:])
230
231 if options.java_only and options.python_only:
232 option_parser.error('Options java_only (-j) and python_only (-p) '
233 'are mutually exclusive.')
234 options.run_java_tests = True
235 options.run_python_tests = True
236 if options.java_only:
237 options.run_python_tests = False
238 elif options.python_only:
239 options.run_java_tests = False
240
241 if options.annotation_str:
242 options.annotations = options.annotation_str.split(',')
243 elif options.test_filter:
244 options.annotations = []
245 else:
246 options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest']
247
248 if options.exclude_annotation_str:
249 options.exclude_annotations = options.exclude_annotation_str.split(',')
250 else:
251 options.exclude_annotations = []
252
253
254 def ValidateInstrumentationOptions(option_parser, options, args):
255 """Validate options/arguments and populate options with defaults."""
256 ValidateCommonInstrumentationOptions(option_parser, options, args)
257
258 if not options.test_apk:
259 option_parser.error('--test-apk must be specified.')
260
261 if os.path.exists(options.test_apk):
262 # The APK is fully qualified, assume the JAR lives along side.
263 options.test_apk_path = options.test_apk
264 options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] +
265 '.jar')
266 else:
267 options.test_apk_path = os.path.join(_SDK_OUT_DIR,
268 options.build_type,
269 constants.SDK_BUILD_APKS_DIR,
270 '%s.apk' % options.test_apk)
271 options.test_apk_jar_path = os.path.join(
272 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR,
273 '%s.jar' % options.test_apk)
274
275
276 def ValidateUIAutomatorOptions(option_parser, options, args):
277 """Validate uiautomator options/arguments."""
278 ValidateCommonInstrumentationOptions(option_parser, options, args)
279
280 if not options.package_name:
281 option_parser.error('--package-name must be specified.')
282
283 if not options.test_jar:
284 option_parser.error('--test-jar must be specified.')
285
286 if os.path.exists(options.test_jar):
287 # The dexed JAR is fully qualified, assume the info JAR lives along side.
288 options.uiautomator_jar = options.test_jar
289 else:
290 options.uiautomator_jar = os.path.join(
291 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR,
292 '%s.dex.jar' % options.test_jar)
293 options.uiautomator_info_jar = (
294 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] +
295 '_java.jar')
296
OLDNEW
« no previous file with comments | « build/android/pylib/uiautomator/dispatch.py ('k') | build/android/run_browser_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698