OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 """Parses options for the instrumentation tests.""" | |
6 | |
7 import constants | |
8 import optparse | |
9 import os | |
10 import sys | |
11 | |
12 _SDK_OUT_DIR = os.path.join(constants.CHROME_DIR, 'out') | |
13 | |
14 | |
15 def AddBuildTypeOption(option_parser): | |
16 """Decorates OptionParser with build type option.""" | |
17 default_build_type = 'Debug' | |
18 if 'BUILDTYPE' in os.environ: | |
19 default_build_type = os.environ['BUILDTYPE'] | |
20 option_parser.add_option('--debug', action='store_const', const='Debug', | |
21 dest='build_type', default=default_build_type, | |
22 help='If set, run test suites under out/Debug. ' | |
23 'Default is env var BUILDTYPE or Debug') | |
24 option_parser.add_option('--release', action='store_const', const='Release', | |
25 dest='build_type', | |
26 help='If set, run test suites under out/Release. ' | |
27 'Default is env var BUILDTYPE or Debug.') | |
28 | |
29 def AddInstallAPKOption(option_parser): | |
30 """Decorates OptionParser with apk option used to install the APK.""" | |
31 AddBuildTypeOption(option_parser) | |
32 option_parser.add_option('--apk', | |
33 help=('The name of the apk containing the ' | |
34 ' application (with the .apk extension).')) | |
35 option_parser.add_option('--apk_package', | |
36 help=('The package name used by the apk containing ' | |
37 'the application.')) | |
38 | |
39 | |
40 def ValidateInstallAPKOption(option_parser, options): | |
41 if not options.apk: | |
42 option_parser.error('--apk is mandatory.') | |
43 if not os.path.exists(options.apk): | |
44 options.apk = os.path.join(os.environ['CHROME_SRC'], | |
45 'out', options.build_type, | |
46 'apks', options.apk) | |
47 | |
48 | |
49 def AddTestRunnerOptions(option_parser, default_timeout=60): | |
50 """Decorates OptionParser with options applicable to all tests.""" | |
51 | |
52 option_parser.add_option('-t', dest='timeout', | |
53 help='Timeout to wait for each test', | |
54 type='int', | |
55 default=default_timeout) | |
56 option_parser.add_option('-c', dest='cleanup_test_files', | |
57 help='Cleanup test files on the device after run', | |
58 action='store_true') | |
59 option_parser.add_option('-v', | |
60 '--verbose', | |
61 dest='verbose_count', | |
62 default=0, | |
63 action='count', | |
64 help='Verbose level (multiple times for more)') | |
65 profilers = ['devicestatsmonitor', 'chrometrace', 'dumpheap', 'smaps', | |
66 'traceview'] | |
67 option_parser.add_option('--profiler', dest='profilers', action='append', | |
68 choices=profilers, | |
69 help='Profiling tool to run during test. ' | |
70 'Pass multiple times to run multiple profilers. ' | |
71 'Available profilers: %s' % profilers) | |
72 option_parser.add_option('--tool', | |
73 dest='tool', | |
74 help='Run the test under a tool ' | |
75 '(use --tool help to list them)') | |
76 option_parser.add_option('--flakiness-dashboard-server', | |
77 dest='flakiness_dashboard_server', | |
78 help=('Address of the server that is hosting the ' | |
79 'Chrome for Android flakiness dashboard.')) | |
80 AddBuildTypeOption(option_parser) | |
81 | |
82 | |
83 def AddInstrumentationOptions(option_parser): | |
84 """Decorates OptionParser with instrumentation tests options.""" | |
85 | |
86 AddTestRunnerOptions(option_parser) | |
87 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', | |
88 action='store_true', help='Wait for debugger.') | |
89 option_parser.add_option('-I', dest='install_apk', help='Install APK.', | |
90 action='store_true') | |
91 option_parser.add_option('-f', '--test_filter', | |
92 help='Test filter (if not fully qualified, ' | |
93 'will run all matches).') | |
94 option_parser.add_option('-A', '--annotation', dest='annotation_str', | |
95 help=('Run only tests with any of the given ' | |
96 'annotations. ' | |
97 'An annotation can be either a key or a ' | |
98 'key-values pair. ' | |
99 'A test that has no annotation is ' | |
100 'considered "SmallTest".')) | |
101 option_parser.add_option('-j', '--java_only', action='store_true', | |
102 help='Run only the Java tests.') | |
103 option_parser.add_option('-p', '--python_only', action='store_true', | |
104 help='Run only the Python tests.') | |
105 option_parser.add_option('-n', '--run_count', type='int', | |
106 dest='number_of_runs', default=1, | |
107 help=('How many times to run each test, regardless ' | |
108 'of the result. (Default is 1)')) | |
109 option_parser.add_option('--test-apk', dest='test_apk', | |
110 help=('The name of the apk containing the tests ' | |
111 '(without the .apk extension). For SDK ' | |
112 'builds, the apk name without the debug ' | |
113 'suffix(for example, ContentShellTest).')) | |
114 option_parser.add_option('--screenshot', dest='screenshot_failures', | |
115 action='store_true', | |
116 help='Capture screenshots of test failures') | |
117 option_parser.add_option('--save-perf-json', action='store_true', | |
118 help='Saves the JSON file for each UI Perf test.') | |
119 option_parser.add_option('--shard_retries', type=int, default=1, | |
120 help=('Number of times to retry each failure when ' | |
121 'sharding.')) | |
122 option_parser.add_option('--official-build', help='Run official build tests.') | |
123 option_parser.add_option('--device', | |
124 help='Serial number of device we should use.') | |
125 option_parser.add_option('--python_test_root', | |
126 help='Root of the python-driven tests.') | |
127 option_parser.add_option('--keep_test_server_ports', | |
128 action='store_true', | |
129 help='Indicates the test server ports must be ' | |
130 'kept. When this is run via a sharder ' | |
131 'the test server ports should be kept and ' | |
132 'should not be reset.') | |
133 option_parser.add_option('--buildbot-step-failure', | |
134 action='store_true', | |
135 help=('If present, will set the buildbot status ' | |
136 'as STEP_FAILURE, otherwise as STEP_WARNINGS ' | |
137 'when test(s) fail.')) | |
138 option_parser.add_option('--disable_assertions', action='store_true', | |
139 help='Run with java assertions disabled.') | |
140 option_parser.add_option('--test_data', action='append', default=[], | |
141 help=('Each instance defines a directory of test ' | |
142 'data that should be copied to the target(s) ' | |
143 'before running the tests. The argument ' | |
144 'should be of the form <target>:<source>, ' | |
145 '<target> is relative to the device data' | |
146 'directory, and <source> is relative to the ' | |
147 'chromium build directory.')) | |
148 | |
149 def ValidateInstrumentationOptions(option_parser, options, args): | |
150 """Validate options/arguments and populate options with defaults.""" | |
151 if len(args) > 1: | |
152 option_parser.print_help(sys.stderr) | |
153 option_parser.error('Unknown arguments: %s' % args[1:]) | |
154 if options.java_only and options.python_only: | |
155 option_parser.error('Options java_only (-j) and python_only (-p) ' | |
156 'are mutually exclusive.') | |
157 if not options.test_apk: | |
158 option_parser.error('--test-apk must be specified.') | |
159 | |
160 options.run_java_tests = True | |
161 options.run_python_tests = True | |
162 if options.java_only: | |
163 options.run_python_tests = False | |
164 elif options.python_only: | |
165 options.run_java_tests = False | |
166 | |
167 if os.path.exists(options.test_apk): | |
168 # The APK is fully qualified, assume the JAR lives along side. | |
169 options.test_apk_path = options.test_apk | |
170 options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] + | |
171 '.jar') | |
172 else: | |
173 options.test_apk_path = os.path.join(_SDK_OUT_DIR, | |
174 options.build_type, | |
175 constants.SDK_BUILD_APKS_DIR, | |
176 '%s.apk' % options.test_apk) | |
177 options.test_apk_jar_path = os.path.join( | |
178 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR, | |
179 '%s.jar' % options.test_apk) | |
180 if options.annotation_str: | |
181 options.annotation = options.annotation_str.split() | |
182 elif options.test_filter: | |
183 options.annotation = [] | |
184 else: | |
185 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] | |
OLD | NEW |