xref: /aosp_15_r20/tools/asuite/atest/arg_parser.py (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env python
2*c2e18aaaSAndroid Build Coastguard Worker#
3*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2018, The Android Open Source Project
4*c2e18aaaSAndroid Build Coastguard Worker#
5*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*c2e18aaaSAndroid Build Coastguard Worker#
9*c2e18aaaSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*c2e18aaaSAndroid Build Coastguard Worker#
11*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License.
16*c2e18aaaSAndroid Build Coastguard Worker
17*c2e18aaaSAndroid Build Coastguard Worker"""Atest Argument Parser class for atest."""
18*c2e18aaaSAndroid Build Coastguard Worker
19*c2e18aaaSAndroid Build Coastguard Workerimport argparse
20*c2e18aaaSAndroid Build Coastguard Worker
21*c2e18aaaSAndroid Build Coastguard Workerfrom atest import bazel_mode
22*c2e18aaaSAndroid Build Coastguard Workerfrom atest import constants
23*c2e18aaaSAndroid Build Coastguard Workerfrom atest.atest_utils import BuildOutputMode
24*c2e18aaaSAndroid Build Coastguard Worker
25*c2e18aaaSAndroid Build Coastguard Worker
26*c2e18aaaSAndroid Build Coastguard Workerdef _output_mode_msg() -> str:
27*c2e18aaaSAndroid Build Coastguard Worker  """Generate helper strings for BuildOutputMode."""
28*c2e18aaaSAndroid Build Coastguard Worker  msg = []
29*c2e18aaaSAndroid Build Coastguard Worker  for _, value in BuildOutputMode.__members__.items():
30*c2e18aaaSAndroid Build Coastguard Worker    if value == BuildOutputMode.STREAMED:
31*c2e18aaaSAndroid Build Coastguard Worker      msg.append(
32*c2e18aaaSAndroid Build Coastguard Worker          f'\t\t{BuildOutputMode.STREAMED.value}: '
33*c2e18aaaSAndroid Build Coastguard Worker          'full output like what "m" does. (default)'
34*c2e18aaaSAndroid Build Coastguard Worker      )
35*c2e18aaaSAndroid Build Coastguard Worker    elif value == BuildOutputMode.LOGGED:
36*c2e18aaaSAndroid Build Coastguard Worker      msg.append(
37*c2e18aaaSAndroid Build Coastguard Worker          f'\t\t{BuildOutputMode.LOGGED.value}: '
38*c2e18aaaSAndroid Build Coastguard Worker          'print build output to a log file.'
39*c2e18aaaSAndroid Build Coastguard Worker      )
40*c2e18aaaSAndroid Build Coastguard Worker    else:
41*c2e18aaaSAndroid Build Coastguard Worker      raise RuntimeError('Found unknown attribute!')
42*c2e18aaaSAndroid Build Coastguard Worker  return '\n'.join(msg)
43*c2e18aaaSAndroid Build Coastguard Worker
44*c2e18aaaSAndroid Build Coastguard Worker
45*c2e18aaaSAndroid Build Coastguard Workerdef _positive_int(value):
46*c2e18aaaSAndroid Build Coastguard Worker  """Verify value by whether or not a positive integer.
47*c2e18aaaSAndroid Build Coastguard Worker
48*c2e18aaaSAndroid Build Coastguard Worker  Args:
49*c2e18aaaSAndroid Build Coastguard Worker      value: A string of a command-line argument.
50*c2e18aaaSAndroid Build Coastguard Worker
51*c2e18aaaSAndroid Build Coastguard Worker  Returns:
52*c2e18aaaSAndroid Build Coastguard Worker      int of value, if it is a positive integer.
53*c2e18aaaSAndroid Build Coastguard Worker      Otherwise, raise argparse.ArgumentTypeError.
54*c2e18aaaSAndroid Build Coastguard Worker  """
55*c2e18aaaSAndroid Build Coastguard Worker  err_msg = "invalid positive int value: '%s'" % value
56*c2e18aaaSAndroid Build Coastguard Worker  try:
57*c2e18aaaSAndroid Build Coastguard Worker    converted_value = int(value)
58*c2e18aaaSAndroid Build Coastguard Worker    if converted_value < 1:
59*c2e18aaaSAndroid Build Coastguard Worker      raise argparse.ArgumentTypeError(err_msg)
60*c2e18aaaSAndroid Build Coastguard Worker    return converted_value
61*c2e18aaaSAndroid Build Coastguard Worker  except ValueError as value_err:
62*c2e18aaaSAndroid Build Coastguard Worker    raise argparse.ArgumentTypeError(err_msg) from value_err
63*c2e18aaaSAndroid Build Coastguard Worker
64*c2e18aaaSAndroid Build Coastguard Worker
65*c2e18aaaSAndroid Build Coastguard Workerdef create_atest_arg_parser():
66*c2e18aaaSAndroid Build Coastguard Worker  """Creates an instance of the default Atest arg parser."""
67*c2e18aaaSAndroid Build Coastguard Worker
68*c2e18aaaSAndroid Build Coastguard Worker  parser = argparse.ArgumentParser(
69*c2e18aaaSAndroid Build Coastguard Worker      description=_HELP_DESCRIPTION,
70*c2e18aaaSAndroid Build Coastguard Worker      add_help=True,
71*c2e18aaaSAndroid Build Coastguard Worker      formatter_class=argparse.RawDescriptionHelpFormatter,
72*c2e18aaaSAndroid Build Coastguard Worker  )
73*c2e18aaaSAndroid Build Coastguard Worker
74*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument('tests', nargs='*', help='Tests to build and/or run.')
75*c2e18aaaSAndroid Build Coastguard Worker
76*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
77*c2e18aaaSAndroid Build Coastguard Worker      '--minimal-build',
78*c2e18aaaSAndroid Build Coastguard Worker      action=argparse.BooleanOptionalAction,
79*c2e18aaaSAndroid Build Coastguard Worker      default=True,
80*c2e18aaaSAndroid Build Coastguard Worker      help=(
81*c2e18aaaSAndroid Build Coastguard Worker          'Build required dependencies only (default: True). Use'
82*c2e18aaaSAndroid Build Coastguard Worker          ' --no-minimal-build to disable it.'
83*c2e18aaaSAndroid Build Coastguard Worker      ),
84*c2e18aaaSAndroid Build Coastguard Worker  )
85*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
86*c2e18aaaSAndroid Build Coastguard Worker      '--update-device',
87*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
88*c2e18aaaSAndroid Build Coastguard Worker      help=(
89*c2e18aaaSAndroid Build Coastguard Worker          'Build and deploy your changes to the device. By default, ATest'
90*c2e18aaaSAndroid Build Coastguard Worker          ' will build `sync` and use `adevice` to update the device. '
91*c2e18aaaSAndroid Build Coastguard Worker          'Note, this feature currently only works for incremental device '
92*c2e18aaaSAndroid Build Coastguard Worker          'updates and not after a repo sync. Please flash the device after a '
93*c2e18aaaSAndroid Build Coastguard Worker          'repo sync.'
94*c2e18aaaSAndroid Build Coastguard Worker      ),
95*c2e18aaaSAndroid Build Coastguard Worker  )
96*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
97*c2e18aaaSAndroid Build Coastguard Worker      '--update:modules',
98*c2e18aaaSAndroid Build Coastguard Worker      dest='update_modules',
99*c2e18aaaSAndroid Build Coastguard Worker      type=lambda value: value.split(','),
100*c2e18aaaSAndroid Build Coastguard Worker      help=(
101*c2e18aaaSAndroid Build Coastguard Worker          'Modules that are built if the device is being updated. '
102*c2e18aaaSAndroid Build Coastguard Worker          'Modules should be separated by comma.'
103*c2e18aaaSAndroid Build Coastguard Worker      ),
104*c2e18aaaSAndroid Build Coastguard Worker  )
105*c2e18aaaSAndroid Build Coastguard Worker
106*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
107*c2e18aaaSAndroid Build Coastguard Worker      '-a',
108*c2e18aaaSAndroid Build Coastguard Worker      '--all-abi',
109*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
110*c2e18aaaSAndroid Build Coastguard Worker      help='Set to run tests for all ABIs (Application Binary Interfaces).',
111*c2e18aaaSAndroid Build Coastguard Worker  )
112*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
113*c2e18aaaSAndroid Build Coastguard Worker      '-b',
114*c2e18aaaSAndroid Build Coastguard Worker      '--build',
115*c2e18aaaSAndroid Build Coastguard Worker      action='append_const',
116*c2e18aaaSAndroid Build Coastguard Worker      dest='steps',
117*c2e18aaaSAndroid Build Coastguard Worker      const=constants.BUILD_STEP,
118*c2e18aaaSAndroid Build Coastguard Worker      help='Run a build.',
119*c2e18aaaSAndroid Build Coastguard Worker  )
120*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
121*c2e18aaaSAndroid Build Coastguard Worker      '--bazel-mode',
122*c2e18aaaSAndroid Build Coastguard Worker      default=True,
123*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
124*c2e18aaaSAndroid Build Coastguard Worker      help='Run tests using Bazel (default: True).',
125*c2e18aaaSAndroid Build Coastguard Worker  )
126*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
127*c2e18aaaSAndroid Build Coastguard Worker      '--no-bazel-mode',
128*c2e18aaaSAndroid Build Coastguard Worker      dest='bazel_mode',
129*c2e18aaaSAndroid Build Coastguard Worker      action='store_false',
130*c2e18aaaSAndroid Build Coastguard Worker      help='Run tests without using Bazel.',
131*c2e18aaaSAndroid Build Coastguard Worker  )
132*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
133*c2e18aaaSAndroid Build Coastguard Worker      '--bazel-arg',
134*c2e18aaaSAndroid Build Coastguard Worker      nargs='*',
135*c2e18aaaSAndroid Build Coastguard Worker      action='append',
136*c2e18aaaSAndroid Build Coastguard Worker      help=(
137*c2e18aaaSAndroid Build Coastguard Worker          'Forward a flag to Bazel for tests executed with Bazel; see'
138*c2e18aaaSAndroid Build Coastguard Worker          ' --bazel-mode.'
139*c2e18aaaSAndroid Build Coastguard Worker      ),
140*c2e18aaaSAndroid Build Coastguard Worker  )
141*c2e18aaaSAndroid Build Coastguard Worker  bazel_mode.add_parser_arguments(parser, dest='bazel_mode_features')
142*c2e18aaaSAndroid Build Coastguard Worker
143*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
144*c2e18aaaSAndroid Build Coastguard Worker      '-d',
145*c2e18aaaSAndroid Build Coastguard Worker      '--disable-teardown',
146*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
147*c2e18aaaSAndroid Build Coastguard Worker      help=(
148*c2e18aaaSAndroid Build Coastguard Worker          'Disable teardown phase implemented using TradeFed interfaces. Note'
149*c2e18aaaSAndroid Build Coastguard Worker          " if a test contains teardown logic without implementing TradeFed's"
150*c2e18aaaSAndroid Build Coastguard Worker          ' teardown interface methods or puts its cleanup steps within the'
151*c2e18aaaSAndroid Build Coastguard Worker          " test phase then setting this flag won't prevent those cleanup steps"
152*c2e18aaaSAndroid Build Coastguard Worker          ' from being executed.'
153*c2e18aaaSAndroid Build Coastguard Worker      ),
154*c2e18aaaSAndroid Build Coastguard Worker  )
155*c2e18aaaSAndroid Build Coastguard Worker
156*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
157*c2e18aaaSAndroid Build Coastguard Worker      '--code-under-test',
158*c2e18aaaSAndroid Build Coastguard Worker      type=lambda value: set(value.split(',')),
159*c2e18aaaSAndroid Build Coastguard Worker      help=(
160*c2e18aaaSAndroid Build Coastguard Worker          'Comma-separated list of modules whose sources should be included in'
161*c2e18aaaSAndroid Build Coastguard Worker          ' the code coverage report. The dependencies of these modules are not'
162*c2e18aaaSAndroid Build Coastguard Worker          ' included. For use with the --experimental-coverage flag.'
163*c2e18aaaSAndroid Build Coastguard Worker      ),
164*c2e18aaaSAndroid Build Coastguard Worker  )
165*c2e18aaaSAndroid Build Coastguard Worker
166*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
167*c2e18aaaSAndroid Build Coastguard Worker      '--experimental-coverage',
168*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
169*c2e18aaaSAndroid Build Coastguard Worker      help=(
170*c2e18aaaSAndroid Build Coastguard Worker          'Instrument tests with code coverage and generate a code coverage'
171*c2e18aaaSAndroid Build Coastguard Worker          ' report.'
172*c2e18aaaSAndroid Build Coastguard Worker      ),
173*c2e18aaaSAndroid Build Coastguard Worker  )
174*c2e18aaaSAndroid Build Coastguard Worker
175*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
176*c2e18aaaSAndroid Build Coastguard Worker      '--group-test',
177*c2e18aaaSAndroid Build Coastguard Worker      default=True,
178*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
179*c2e18aaaSAndroid Build Coastguard Worker      help=(
180*c2e18aaaSAndroid Build Coastguard Worker          'Group tests by module name during the test run (default: True). To'
181*c2e18aaaSAndroid Build Coastguard Worker          ' run tests in the same order as they are input, use'
182*c2e18aaaSAndroid Build Coastguard Worker          ' `--no-group-test`'
183*c2e18aaaSAndroid Build Coastguard Worker      ),
184*c2e18aaaSAndroid Build Coastguard Worker  )
185*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
186*c2e18aaaSAndroid Build Coastguard Worker      '--no-group-test',
187*c2e18aaaSAndroid Build Coastguard Worker      dest='group_test',
188*c2e18aaaSAndroid Build Coastguard Worker      action='store_false',
189*c2e18aaaSAndroid Build Coastguard Worker      help=(
190*c2e18aaaSAndroid Build Coastguard Worker          'Group the tests by module name for running the test, if you want'
191*c2e18aaaSAndroid Build Coastguard Worker          ' to run the test using the same input order, use --no-group-test.'
192*c2e18aaaSAndroid Build Coastguard Worker      ),
193*c2e18aaaSAndroid Build Coastguard Worker  )
194*c2e18aaaSAndroid Build Coastguard Worker
195*c2e18aaaSAndroid Build Coastguard Worker  hgroup = parser.add_mutually_exclusive_group()
196*c2e18aaaSAndroid Build Coastguard Worker  hgroup.add_argument(
197*c2e18aaaSAndroid Build Coastguard Worker      '--host',
198*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
199*c2e18aaaSAndroid Build Coastguard Worker      help=(
200*c2e18aaaSAndroid Build Coastguard Worker          'Run the test completely on the host without a device. (Note:'
201*c2e18aaaSAndroid Build Coastguard Worker          ' running a host test that requires a device without --host will'
202*c2e18aaaSAndroid Build Coastguard Worker          ' fail.)'
203*c2e18aaaSAndroid Build Coastguard Worker      ),
204*c2e18aaaSAndroid Build Coastguard Worker  )
205*c2e18aaaSAndroid Build Coastguard Worker  hgroup.add_argument(
206*c2e18aaaSAndroid Build Coastguard Worker      '--device-only',
207*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
208*c2e18aaaSAndroid Build Coastguard Worker      help=(
209*c2e18aaaSAndroid Build Coastguard Worker          'Only run tests that require a device. (Note: only workable with'
210*c2e18aaaSAndroid Build Coastguard Worker          ' --test-mapping.)'
211*c2e18aaaSAndroid Build Coastguard Worker      ),
212*c2e18aaaSAndroid Build Coastguard Worker  )
213*c2e18aaaSAndroid Build Coastguard Worker
214*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
215*c2e18aaaSAndroid Build Coastguard Worker      '-i',
216*c2e18aaaSAndroid Build Coastguard Worker      '--install',
217*c2e18aaaSAndroid Build Coastguard Worker      action='append_const',
218*c2e18aaaSAndroid Build Coastguard Worker      dest='steps',
219*c2e18aaaSAndroid Build Coastguard Worker      const=constants.INSTALL_STEP,
220*c2e18aaaSAndroid Build Coastguard Worker      help='Install an APK.',
221*c2e18aaaSAndroid Build Coastguard Worker  )
222*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
223*c2e18aaaSAndroid Build Coastguard Worker      '-m',
224*c2e18aaaSAndroid Build Coastguard Worker      constants.REBUILD_MODULE_INFO_FLAG,
225*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
226*c2e18aaaSAndroid Build Coastguard Worker      help=(
227*c2e18aaaSAndroid Build Coastguard Worker          'Forces a rebuild of the module-info.json file. This may be'
228*c2e18aaaSAndroid Build Coastguard Worker          ' necessary following a repo sync or when writing a new test.'
229*c2e18aaaSAndroid Build Coastguard Worker      ),
230*c2e18aaaSAndroid Build Coastguard Worker  )
231*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
232*c2e18aaaSAndroid Build Coastguard Worker      '--sharding',
233*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
234*c2e18aaaSAndroid Build Coastguard Worker      const=2,
235*c2e18aaaSAndroid Build Coastguard Worker      type=_positive_int,
236*c2e18aaaSAndroid Build Coastguard Worker      default=0,
237*c2e18aaaSAndroid Build Coastguard Worker      help='Option to specify sharding count. (default: 2)',
238*c2e18aaaSAndroid Build Coastguard Worker  )
239*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
240*c2e18aaaSAndroid Build Coastguard Worker      '--sqlite-module-cache',
241*c2e18aaaSAndroid Build Coastguard Worker      action=argparse.BooleanOptionalAction,
242*c2e18aaaSAndroid Build Coastguard Worker      default=True,
243*c2e18aaaSAndroid Build Coastguard Worker      help='Use SQLite database as cache instead of JSON.',
244*c2e18aaaSAndroid Build Coastguard Worker  )
245*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
246*c2e18aaaSAndroid Build Coastguard Worker      '-t',
247*c2e18aaaSAndroid Build Coastguard Worker      '--test',
248*c2e18aaaSAndroid Build Coastguard Worker      action='append_const',
249*c2e18aaaSAndroid Build Coastguard Worker      dest='steps',
250*c2e18aaaSAndroid Build Coastguard Worker      const=constants.TEST_STEP,
251*c2e18aaaSAndroid Build Coastguard Worker      help=(
252*c2e18aaaSAndroid Build Coastguard Worker          'Run the tests. WARNING: Many test configs force cleanup of device'
253*c2e18aaaSAndroid Build Coastguard Worker          ' after test run. In this case, "-d" must be used in previous test'
254*c2e18aaaSAndroid Build Coastguard Worker          ' run to disable cleanup for "-t" to work. Otherwise, device will'
255*c2e18aaaSAndroid Build Coastguard Worker          ' need to be setup again with "-i".'
256*c2e18aaaSAndroid Build Coastguard Worker      ),
257*c2e18aaaSAndroid Build Coastguard Worker  )
258*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
259*c2e18aaaSAndroid Build Coastguard Worker      '--use-modules-in',
260*c2e18aaaSAndroid Build Coastguard Worker      help=(
261*c2e18aaaSAndroid Build Coastguard Worker          'Force include MODULES-IN-* as build targets. Hint: This may solve'
262*c2e18aaaSAndroid Build Coastguard Worker          ' missing test dependencies issue.'
263*c2e18aaaSAndroid Build Coastguard Worker      ),
264*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
265*c2e18aaaSAndroid Build Coastguard Worker  )
266*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
267*c2e18aaaSAndroid Build Coastguard Worker      '-w',
268*c2e18aaaSAndroid Build Coastguard Worker      '--wait-for-debugger',
269*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
270*c2e18aaaSAndroid Build Coastguard Worker      help='Wait for debugger prior to execution (Instrumentation tests only).',
271*c2e18aaaSAndroid Build Coastguard Worker  )
272*c2e18aaaSAndroid Build Coastguard Worker
273*c2e18aaaSAndroid Build Coastguard Worker  ugroup = parser.add_mutually_exclusive_group()
274*c2e18aaaSAndroid Build Coastguard Worker  ugroup.add_argument(
275*c2e18aaaSAndroid Build Coastguard Worker      '--request-upload-result',
276*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
277*c2e18aaaSAndroid Build Coastguard Worker      help=(
278*c2e18aaaSAndroid Build Coastguard Worker          'Request permission to upload test result. This option only needs'
279*c2e18aaaSAndroid Build Coastguard Worker          ' to set once and takes effect until --disable-upload-result is'
280*c2e18aaaSAndroid Build Coastguard Worker          ' set.'
281*c2e18aaaSAndroid Build Coastguard Worker      ),
282*c2e18aaaSAndroid Build Coastguard Worker  )
283*c2e18aaaSAndroid Build Coastguard Worker  ugroup.add_argument(
284*c2e18aaaSAndroid Build Coastguard Worker      '--disable-upload-result',
285*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
286*c2e18aaaSAndroid Build Coastguard Worker      help=(
287*c2e18aaaSAndroid Build Coastguard Worker          'Turn off the upload of test result. This option only needs to set'
288*c2e18aaaSAndroid Build Coastguard Worker          ' once and takes effect until --request-upload-result is set'
289*c2e18aaaSAndroid Build Coastguard Worker      ),
290*c2e18aaaSAndroid Build Coastguard Worker  )
291*c2e18aaaSAndroid Build Coastguard Worker
292*c2e18aaaSAndroid Build Coastguard Worker  test_mapping_or_host_unit_group = parser.add_mutually_exclusive_group()
293*c2e18aaaSAndroid Build Coastguard Worker  test_mapping_or_host_unit_group.add_argument(
294*c2e18aaaSAndroid Build Coastguard Worker      '-p',
295*c2e18aaaSAndroid Build Coastguard Worker      '--test-mapping',
296*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
297*c2e18aaaSAndroid Build Coastguard Worker      help='Run tests defined in TEST_MAPPING files.',
298*c2e18aaaSAndroid Build Coastguard Worker  )
299*c2e18aaaSAndroid Build Coastguard Worker  test_mapping_or_host_unit_group.add_argument(
300*c2e18aaaSAndroid Build Coastguard Worker      '--host-unit-test-only',
301*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
302*c2e18aaaSAndroid Build Coastguard Worker      help='Run all host unit tests under the current directory.',
303*c2e18aaaSAndroid Build Coastguard Worker  )
304*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
305*c2e18aaaSAndroid Build Coastguard Worker      '--include-subdirs',
306*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
307*c2e18aaaSAndroid Build Coastguard Worker      help='Search TEST_MAPPING files in subdirs as well.',
308*c2e18aaaSAndroid Build Coastguard Worker  )
309*c2e18aaaSAndroid Build Coastguard Worker  # TODO(b/146980564): Remove enable-file-patterns when support
310*c2e18aaaSAndroid Build Coastguard Worker  # file-patterns in TEST_MAPPING by default.
311*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
312*c2e18aaaSAndroid Build Coastguard Worker      '--enable-file-patterns',
313*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
314*c2e18aaaSAndroid Build Coastguard Worker      help='Enable FILE_PATTERNS in TEST_MAPPING.',
315*c2e18aaaSAndroid Build Coastguard Worker  )
316*c2e18aaaSAndroid Build Coastguard Worker
317*c2e18aaaSAndroid Build Coastguard Worker  group = parser.add_mutually_exclusive_group()
318*c2e18aaaSAndroid Build Coastguard Worker  group.add_argument(
319*c2e18aaaSAndroid Build Coastguard Worker      '--collect-tests-only',
320*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
321*c2e18aaaSAndroid Build Coastguard Worker      help=(
322*c2e18aaaSAndroid Build Coastguard Worker          'Collect a list test cases of the instrumentation tests without'
323*c2e18aaaSAndroid Build Coastguard Worker          ' testing them in real.'
324*c2e18aaaSAndroid Build Coastguard Worker      ),
325*c2e18aaaSAndroid Build Coastguard Worker  )
326*c2e18aaaSAndroid Build Coastguard Worker  group.add_argument(
327*c2e18aaaSAndroid Build Coastguard Worker      '--dry-run',
328*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
329*c2e18aaaSAndroid Build Coastguard Worker      help=(
330*c2e18aaaSAndroid Build Coastguard Worker          'Dry run atest without building, installing and running tests in'
331*c2e18aaaSAndroid Build Coastguard Worker          ' real.'
332*c2e18aaaSAndroid Build Coastguard Worker      ),
333*c2e18aaaSAndroid Build Coastguard Worker  )
334*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
335*c2e18aaaSAndroid Build Coastguard Worker      '-L', '--list-modules', help='List testable modules of the given suite.'
336*c2e18aaaSAndroid Build Coastguard Worker  )
337*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
338*c2e18aaaSAndroid Build Coastguard Worker      '-v',
339*c2e18aaaSAndroid Build Coastguard Worker      '--verbose',
340*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
341*c2e18aaaSAndroid Build Coastguard Worker      help='Display DEBUG level logging.',
342*c2e18aaaSAndroid Build Coastguard Worker  )
343*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
344*c2e18aaaSAndroid Build Coastguard Worker      '-V', '--version', action='store_true', help='Display version string.'
345*c2e18aaaSAndroid Build Coastguard Worker  )
346*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
347*c2e18aaaSAndroid Build Coastguard Worker      '--build-output',
348*c2e18aaaSAndroid Build Coastguard Worker      default=BuildOutputMode.STREAMED,
349*c2e18aaaSAndroid Build Coastguard Worker      choices=BuildOutputMode,
350*c2e18aaaSAndroid Build Coastguard Worker      type=BuildOutputMode,
351*c2e18aaaSAndroid Build Coastguard Worker      help=(
352*c2e18aaaSAndroid Build Coastguard Worker          'Specifies the desired build output mode. Valid values are:'
353*c2e18aaaSAndroid Build Coastguard Worker          f' {_output_mode_msg()}'
354*c2e18aaaSAndroid Build Coastguard Worker      ),
355*c2e18aaaSAndroid Build Coastguard Worker  )
356*c2e18aaaSAndroid Build Coastguard Worker
357*c2e18aaaSAndroid Build Coastguard Worker  agroup = parser.add_mutually_exclusive_group()
358*c2e18aaaSAndroid Build Coastguard Worker  agroup.add_argument(
359*c2e18aaaSAndroid Build Coastguard Worker      '--acloud-create',
360*c2e18aaaSAndroid Build Coastguard Worker      nargs=argparse.REMAINDER,
361*c2e18aaaSAndroid Build Coastguard Worker      type=str,
362*c2e18aaaSAndroid Build Coastguard Worker      help='(For testing with AVDs) Create AVD(s) via acloud command.',
363*c2e18aaaSAndroid Build Coastguard Worker  )
364*c2e18aaaSAndroid Build Coastguard Worker  agroup.add_argument(
365*c2e18aaaSAndroid Build Coastguard Worker      '--start-avd',
366*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
367*c2e18aaaSAndroid Build Coastguard Worker      help=(
368*c2e18aaaSAndroid Build Coastguard Worker          '(For testing with AVDs) Automatically create an AVD and run tests'
369*c2e18aaaSAndroid Build Coastguard Worker          ' on the virtual device.'
370*c2e18aaaSAndroid Build Coastguard Worker      ),
371*c2e18aaaSAndroid Build Coastguard Worker  )
372*c2e18aaaSAndroid Build Coastguard Worker  agroup.add_argument(
373*c2e18aaaSAndroid Build Coastguard Worker      '-s', '--serial', action='append', help='The device to run the test on.'
374*c2e18aaaSAndroid Build Coastguard Worker  )
375*c2e18aaaSAndroid Build Coastguard Worker
376*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
377*c2e18aaaSAndroid Build Coastguard Worker      '--test-config-select',
378*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
379*c2e18aaaSAndroid Build Coastguard Worker      help=(
380*c2e18aaaSAndroid Build Coastguard Worker          'If multiple test config belong to same test module pop out a'
381*c2e18aaaSAndroid Build Coastguard Worker          ' selection menu on console.'
382*c2e18aaaSAndroid Build Coastguard Worker      ),
383*c2e18aaaSAndroid Build Coastguard Worker  )
384*c2e18aaaSAndroid Build Coastguard Worker
385*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
386*c2e18aaaSAndroid Build Coastguard Worker      '--instant',
387*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
388*c2e18aaaSAndroid Build Coastguard Worker      help=(
389*c2e18aaaSAndroid Build Coastguard Worker          '(For module parameterization) Run the instant_app version of the'
390*c2e18aaaSAndroid Build Coastguard Worker          " module if the module supports it. Note: Nothing's going to run if"
391*c2e18aaaSAndroid Build Coastguard Worker          " it's not an Instant App test and '--instant' is passed."
392*c2e18aaaSAndroid Build Coastguard Worker      ),
393*c2e18aaaSAndroid Build Coastguard Worker  )
394*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
395*c2e18aaaSAndroid Build Coastguard Worker      '--user-type',
396*c2e18aaaSAndroid Build Coastguard Worker      help=(
397*c2e18aaaSAndroid Build Coastguard Worker          '(For module parameterization) Run test with specific user type,'
398*c2e18aaaSAndroid Build Coastguard Worker          ' e.g. atest <test> --user-type secondary_user'
399*c2e18aaaSAndroid Build Coastguard Worker      ),
400*c2e18aaaSAndroid Build Coastguard Worker  )
401*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
402*c2e18aaaSAndroid Build Coastguard Worker      '--annotation-filter',
403*c2e18aaaSAndroid Build Coastguard Worker      action='append',
404*c2e18aaaSAndroid Build Coastguard Worker      help=(
405*c2e18aaaSAndroid Build Coastguard Worker          '(For module parameterization) Accept keyword that will be'
406*c2e18aaaSAndroid Build Coastguard Worker          ' translated to fully qualified annotation class name.'
407*c2e18aaaSAndroid Build Coastguard Worker      ),
408*c2e18aaaSAndroid Build Coastguard Worker  )
409*c2e18aaaSAndroid Build Coastguard Worker
410*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
411*c2e18aaaSAndroid Build Coastguard Worker      '-c',
412*c2e18aaaSAndroid Build Coastguard Worker      '--clear-cache',
413*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
414*c2e18aaaSAndroid Build Coastguard Worker      help='Wipe out the test_infos cache of the test and start a new search.',
415*c2e18aaaSAndroid Build Coastguard Worker  )
416*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
417*c2e18aaaSAndroid Build Coastguard Worker      '-D',
418*c2e18aaaSAndroid Build Coastguard Worker      '--tf-debug',
419*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
420*c2e18aaaSAndroid Build Coastguard Worker      const=10888,
421*c2e18aaaSAndroid Build Coastguard Worker      type=_positive_int,
422*c2e18aaaSAndroid Build Coastguard Worker      default=0,
423*c2e18aaaSAndroid Build Coastguard Worker      help='Enable tradefed debug mode with a specified port. (default: 10888)',
424*c2e18aaaSAndroid Build Coastguard Worker  )
425*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
426*c2e18aaaSAndroid Build Coastguard Worker      '--tf-template',
427*c2e18aaaSAndroid Build Coastguard Worker      action='append',
428*c2e18aaaSAndroid Build Coastguard Worker      help=(
429*c2e18aaaSAndroid Build Coastguard Worker          'Add extra tradefed template for ATest suite, e.g. atest <test>'
430*c2e18aaaSAndroid Build Coastguard Worker          ' --tf-template <template_key>=<template_path>'
431*c2e18aaaSAndroid Build Coastguard Worker      ),
432*c2e18aaaSAndroid Build Coastguard Worker  )
433*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
434*c2e18aaaSAndroid Build Coastguard Worker      '--test-filter',
435*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
436*c2e18aaaSAndroid Build Coastguard Worker      # TODO(b/326457393): JarHostTest to support running parameterized tests
437*c2e18aaaSAndroid Build Coastguard Worker      # with base method
438*c2e18aaaSAndroid Build Coastguard Worker      # TODO(b/326141263): TradeFed to support wildcard in include-filter for
439*c2e18aaaSAndroid Build Coastguard Worker      # parametrized JarHostTests
440*c2e18aaaSAndroid Build Coastguard Worker      help=(
441*c2e18aaaSAndroid Build Coastguard Worker          'Run only the tests which are specified with this option. This value'
442*c2e18aaaSAndroid Build Coastguard Worker          ' is passed directly to the testing framework so you should use'
443*c2e18aaaSAndroid Build Coastguard Worker          " appropriate syntax (e.g. JUnit supports regex, while python's"
444*c2e18aaaSAndroid Build Coastguard Worker          ' unittest supports fnmatch syntax).'
445*c2e18aaaSAndroid Build Coastguard Worker      ),
446*c2e18aaaSAndroid Build Coastguard Worker  )
447*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
448*c2e18aaaSAndroid Build Coastguard Worker      '--test-timeout',
449*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
450*c2e18aaaSAndroid Build Coastguard Worker      type=int,
451*c2e18aaaSAndroid Build Coastguard Worker      help=(
452*c2e18aaaSAndroid Build Coastguard Worker          'Customize test timeout. E.g. 60000(in milliseconds) represents 1'
453*c2e18aaaSAndroid Build Coastguard Worker          ' minute timeout. For no timeout, set to 0.'
454*c2e18aaaSAndroid Build Coastguard Worker      ),
455*c2e18aaaSAndroid Build Coastguard Worker  )
456*c2e18aaaSAndroid Build Coastguard Worker
457*c2e18aaaSAndroid Build Coastguard Worker  iteration_group = parser.add_mutually_exclusive_group()
458*c2e18aaaSAndroid Build Coastguard Worker  iteration_group.add_argument(
459*c2e18aaaSAndroid Build Coastguard Worker      '--iterations',
460*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
461*c2e18aaaSAndroid Build Coastguard Worker      type=_positive_int,
462*c2e18aaaSAndroid Build Coastguard Worker      const=10,
463*c2e18aaaSAndroid Build Coastguard Worker      default=0,
464*c2e18aaaSAndroid Build Coastguard Worker      metavar='MAX_ITERATIONS',
465*c2e18aaaSAndroid Build Coastguard Worker      help=(
466*c2e18aaaSAndroid Build Coastguard Worker          '(For iteration testing) Loop-run tests until the max iteration is'
467*c2e18aaaSAndroid Build Coastguard Worker          ' reached. (default: 10)'
468*c2e18aaaSAndroid Build Coastguard Worker      ),
469*c2e18aaaSAndroid Build Coastguard Worker  )
470*c2e18aaaSAndroid Build Coastguard Worker  iteration_group.add_argument(
471*c2e18aaaSAndroid Build Coastguard Worker      '--rerun-until-failure',
472*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
473*c2e18aaaSAndroid Build Coastguard Worker      type=_positive_int,
474*c2e18aaaSAndroid Build Coastguard Worker      const=2147483647,  # Java's Integer.MAX_VALUE for TradeFed.
475*c2e18aaaSAndroid Build Coastguard Worker      default=0,
476*c2e18aaaSAndroid Build Coastguard Worker      metavar='MAX_ITERATIONS',
477*c2e18aaaSAndroid Build Coastguard Worker      help=(
478*c2e18aaaSAndroid Build Coastguard Worker          '(For iteration testing) Rerun all tests until a failure occurs or'
479*c2e18aaaSAndroid Build Coastguard Worker          ' the max iteration is reached. (default: forever!)'
480*c2e18aaaSAndroid Build Coastguard Worker      ),
481*c2e18aaaSAndroid Build Coastguard Worker  )
482*c2e18aaaSAndroid Build Coastguard Worker  iteration_group.add_argument(
483*c2e18aaaSAndroid Build Coastguard Worker      '--retry-any-failure',
484*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
485*c2e18aaaSAndroid Build Coastguard Worker      type=_positive_int,
486*c2e18aaaSAndroid Build Coastguard Worker      const=10,
487*c2e18aaaSAndroid Build Coastguard Worker      default=0,
488*c2e18aaaSAndroid Build Coastguard Worker      metavar='MAX_ITERATIONS',
489*c2e18aaaSAndroid Build Coastguard Worker      help=(
490*c2e18aaaSAndroid Build Coastguard Worker          '(For iteration testing) Rerun failed tests until passed or the max'
491*c2e18aaaSAndroid Build Coastguard Worker          ' iteration is reached. (default: 10)'
492*c2e18aaaSAndroid Build Coastguard Worker      ),
493*c2e18aaaSAndroid Build Coastguard Worker  )
494*c2e18aaaSAndroid Build Coastguard Worker
495*c2e18aaaSAndroid Build Coastguard Worker  history_group = parser.add_mutually_exclusive_group()
496*c2e18aaaSAndroid Build Coastguard Worker  history_group.add_argument(
497*c2e18aaaSAndroid Build Coastguard Worker      '--latest-result', action='store_true', help='Print latest test result.'
498*c2e18aaaSAndroid Build Coastguard Worker  )
499*c2e18aaaSAndroid Build Coastguard Worker  history_group.add_argument(
500*c2e18aaaSAndroid Build Coastguard Worker      '--history',
501*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
502*c2e18aaaSAndroid Build Coastguard Worker      const='99999',
503*c2e18aaaSAndroid Build Coastguard Worker      help=(
504*c2e18aaaSAndroid Build Coastguard Worker          'Show test results in chronological order(with specified number or'
505*c2e18aaaSAndroid Build Coastguard Worker          ' all by default).'
506*c2e18aaaSAndroid Build Coastguard Worker      ),
507*c2e18aaaSAndroid Build Coastguard Worker  )
508*c2e18aaaSAndroid Build Coastguard Worker
509*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
510*c2e18aaaSAndroid Build Coastguard Worker      constants.NO_METRICS_ARG,
511*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
512*c2e18aaaSAndroid Build Coastguard Worker      help='(For metrics) Do not send metrics.',
513*c2e18aaaSAndroid Build Coastguard Worker  )
514*c2e18aaaSAndroid Build Coastguard Worker
515*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
516*c2e18aaaSAndroid Build Coastguard Worker      '--aggregate-metric-filter',
517*c2e18aaaSAndroid Build Coastguard Worker      action='append',
518*c2e18aaaSAndroid Build Coastguard Worker      help=(
519*c2e18aaaSAndroid Build Coastguard Worker          '(For performance tests) Regular expression that will be used for'
520*c2e18aaaSAndroid Build Coastguard Worker          ' filtering the aggregated metrics.'
521*c2e18aaaSAndroid Build Coastguard Worker      ),
522*c2e18aaaSAndroid Build Coastguard Worker  )
523*c2e18aaaSAndroid Build Coastguard Worker
524*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
525*c2e18aaaSAndroid Build Coastguard Worker      '--perf-itr-metrics',
526*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
527*c2e18aaaSAndroid Build Coastguard Worker      help='(For performance tests) Print individual performance metric.',
528*c2e18aaaSAndroid Build Coastguard Worker  )
529*c2e18aaaSAndroid Build Coastguard Worker
530*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
531*c2e18aaaSAndroid Build Coastguard Worker      '--no-checking-device',
532*c2e18aaaSAndroid Build Coastguard Worker      action='store_true',
533*c2e18aaaSAndroid Build Coastguard Worker      help='Do NOT check device availability. (even it is a device test)',
534*c2e18aaaSAndroid Build Coastguard Worker  )
535*c2e18aaaSAndroid Build Coastguard Worker
536*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
537*c2e18aaaSAndroid Build Coastguard Worker      '-j',
538*c2e18aaaSAndroid Build Coastguard Worker      '--build-j',
539*c2e18aaaSAndroid Build Coastguard Worker      nargs='?',
540*c2e18aaaSAndroid Build Coastguard Worker      type=int,
541*c2e18aaaSAndroid Build Coastguard Worker      help='Number of build run processes.',
542*c2e18aaaSAndroid Build Coastguard Worker  )
543*c2e18aaaSAndroid Build Coastguard Worker  # Flag to use atest_local_min.xml as the TF base templates, this is added
544*c2e18aaaSAndroid Build Coastguard Worker  # to roll out the change that uses separate templates for device/deviceless
545*c2e18aaaSAndroid Build Coastguard Worker  # tests and should be removed once that feature is stable.
546*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
547*c2e18aaaSAndroid Build Coastguard Worker      '--use-tf-min-base-template',
548*c2e18aaaSAndroid Build Coastguard Worker      dest='use_tf_min_base_template',
549*c2e18aaaSAndroid Build Coastguard Worker      action=argparse.BooleanOptionalAction,
550*c2e18aaaSAndroid Build Coastguard Worker      default=False,
551*c2e18aaaSAndroid Build Coastguard Worker      help='Run tests using atest_local_min.xml as the TF base templates.',
552*c2e18aaaSAndroid Build Coastguard Worker  )
553*c2e18aaaSAndroid Build Coastguard Worker
554*c2e18aaaSAndroid Build Coastguard Worker  # This arg actually doesn't consume anything, it's primarily used for
555*c2e18aaaSAndroid Build Coastguard Worker  # the help description and creating custom_args in the NameSpace object.
556*c2e18aaaSAndroid Build Coastguard Worker  parser.add_argument(
557*c2e18aaaSAndroid Build Coastguard Worker      '--',
558*c2e18aaaSAndroid Build Coastguard Worker      dest='custom_args',
559*c2e18aaaSAndroid Build Coastguard Worker      nargs='*',
560*c2e18aaaSAndroid Build Coastguard Worker      help=(
561*c2e18aaaSAndroid Build Coastguard Worker          'Specify custom args for the test runners. Everything after -- will'
562*c2e18aaaSAndroid Build Coastguard Worker          ' be consumed as custom args.'
563*c2e18aaaSAndroid Build Coastguard Worker      ),
564*c2e18aaaSAndroid Build Coastguard Worker  )
565*c2e18aaaSAndroid Build Coastguard Worker
566*c2e18aaaSAndroid Build Coastguard Worker  return parser
567*c2e18aaaSAndroid Build Coastguard Worker
568*c2e18aaaSAndroid Build Coastguard Worker
569*c2e18aaaSAndroid Build Coastguard Worker_HELP_DESCRIPTION = """NAME
570*c2e18aaaSAndroid Build Coastguard Worker        atest - A command line tool that allows users to build, install, and run Android tests locally, greatly speeding test re-runs without requiring knowledge of Trade Federation test harness command line options.
571*c2e18aaaSAndroid Build Coastguard Worker
572*c2e18aaaSAndroid Build Coastguard Worker
573*c2e18aaaSAndroid Build Coastguard WorkerSYNOPSIS
574*c2e18aaaSAndroid Build Coastguard Worker        atest [OPTION]... [TEST_TARGET]... -- [CUSTOM_ARGS]...
575*c2e18aaaSAndroid Build Coastguard Worker
576*c2e18aaaSAndroid Build Coastguard Worker
577*c2e18aaaSAndroid Build Coastguard WorkerOPTIONS
578*c2e18aaaSAndroid Build Coastguard Worker        The below arguments are categorized by feature and purpose. Arguments marked with an implicit default will apply even when the user doesn't pass them explicitly.
579*c2e18aaaSAndroid Build Coastguard Worker
580*c2e18aaaSAndroid Build Coastguard Worker        *NOTE* Atest reads ~/.atest/config that supports all optional arguments to help users reduce repeating options they often use.
581*c2e18aaaSAndroid Build Coastguard Worker        E.g. Assume "--all-abi" and "--verbose" are frequently used and have been defined line-by-line in ~/.atest/config, issuing
582*c2e18aaaSAndroid Build Coastguard Worker
583*c2e18aaaSAndroid Build Coastguard Worker            atest hello_world_test -v -- --test-arg xxx
584*c2e18aaaSAndroid Build Coastguard Worker
585*c2e18aaaSAndroid Build Coastguard Worker        is equivalent to
586*c2e18aaaSAndroid Build Coastguard Worker
587*c2e18aaaSAndroid Build Coastguard Worker            atest hello_world_test -v --all-abi --verbose -- --test-arg xxx
588*c2e18aaaSAndroid Build Coastguard Worker
589*c2e18aaaSAndroid Build Coastguard Worker        If you only need to run tests for a specific abi, please use:
590*c2e18aaaSAndroid Build Coastguard Worker            atest <test> -- --abi arm64-v8a   # ARM 64-bit
591*c2e18aaaSAndroid Build Coastguard Worker            atest <test> -- --abi armeabi-v7a # ARM 32-bit
592*c2e18aaaSAndroid Build Coastguard Worker
593*c2e18aaaSAndroid Build Coastguard Worker        Also, to avoid confusing Atest from testing TEST_MAPPING file and implicit test names from ~/.atest/config, any test names defined in the config file
594*c2e18aaaSAndroid Build Coastguard Worker        will be ignored without any hints.
595*c2e18aaaSAndroid Build Coastguard Worker
596*c2e18aaaSAndroid Build Coastguard Worker
597*c2e18aaaSAndroid Build Coastguard WorkerEXAMPLES
598*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - -
599*c2e18aaaSAndroid Build Coastguard Worker    IDENTIFYING TESTS
600*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - -
601*c2e18aaaSAndroid Build Coastguard Worker
602*c2e18aaaSAndroid Build Coastguard Worker    The positional argument <tests> should be a reference to one or more of the tests you'd like to run. Multiple tests can be run in one command by separating test references with spaces.
603*c2e18aaaSAndroid Build Coastguard Worker
604*c2e18aaaSAndroid Build Coastguard Worker    Usage template: atest <reference_to_test_1> <reference_to_test_2>
605*c2e18aaaSAndroid Build Coastguard Worker
606*c2e18aaaSAndroid Build Coastguard Worker    A <reference_to_test> can be satisfied by the test's MODULE NAME, MODULE:CLASS, CLASS NAME, TF INTEGRATION TEST, FILE PATH or PACKAGE NAME. Explanations and examples of each follow.
607*c2e18aaaSAndroid Build Coastguard Worker
608*c2e18aaaSAndroid Build Coastguard Worker
609*c2e18aaaSAndroid Build Coastguard Worker    < MODULE NAME >
610*c2e18aaaSAndroid Build Coastguard Worker
611*c2e18aaaSAndroid Build Coastguard Worker        Identifying a test by its module name will run the entire module. Input the name as it appears in the LOCAL_MODULE or LOCAL_PACKAGE_NAME variables in that test's Android.mk or Android.bp file.
612*c2e18aaaSAndroid Build Coastguard Worker
613*c2e18aaaSAndroid Build Coastguard Worker        Note: Use < TF INTEGRATION TEST > to run non-module tests integrated directly into TradeFed.
614*c2e18aaaSAndroid Build Coastguard Worker
615*c2e18aaaSAndroid Build Coastguard Worker        Examples:
616*c2e18aaaSAndroid Build Coastguard Worker            atest FrameworksServicesTests
617*c2e18aaaSAndroid Build Coastguard Worker            atest CtsJankDeviceTestCases
618*c2e18aaaSAndroid Build Coastguard Worker
619*c2e18aaaSAndroid Build Coastguard Worker
620*c2e18aaaSAndroid Build Coastguard Worker    < MODULE:CLASS >
621*c2e18aaaSAndroid Build Coastguard Worker
622*c2e18aaaSAndroid Build Coastguard Worker        Identifying a test by its class name will run just the tests in that class and not the whole module. MODULE:CLASS is the preferred way to run a single class. MODULE is the same as described above. CLASS is the name of the test class in the .java file. It can either be the fully qualified class name or just the basic name.
623*c2e18aaaSAndroid Build Coastguard Worker
624*c2e18aaaSAndroid Build Coastguard Worker        Examples:
625*c2e18aaaSAndroid Build Coastguard Worker            atest FrameworksServicesTests:ScreenDecorWindowTests
626*c2e18aaaSAndroid Build Coastguard Worker            atest FrameworksServicesTests:com.android.server.wm.ScreenDecorWindowTests
627*c2e18aaaSAndroid Build Coastguard Worker            atest CtsJankDeviceTestCases:CtsDeviceJankUi
628*c2e18aaaSAndroid Build Coastguard Worker
629*c2e18aaaSAndroid Build Coastguard Worker
630*c2e18aaaSAndroid Build Coastguard Worker    < CLASS NAME >
631*c2e18aaaSAndroid Build Coastguard Worker
632*c2e18aaaSAndroid Build Coastguard Worker        A single class can also be run by referencing the class name without the module name.
633*c2e18aaaSAndroid Build Coastguard Worker
634*c2e18aaaSAndroid Build Coastguard Worker        Examples:
635*c2e18aaaSAndroid Build Coastguard Worker            atest ScreenDecorWindowTests
636*c2e18aaaSAndroid Build Coastguard Worker            atest CtsDeviceJankUi
637*c2e18aaaSAndroid Build Coastguard Worker
638*c2e18aaaSAndroid Build Coastguard Worker        However, this will take more time than the equivalent MODULE:CLASS reference, so we suggest using a MODULE:CLASS reference whenever possible. Examples below are ordered by performance from the fastest to the slowest:
639*c2e18aaaSAndroid Build Coastguard Worker
640*c2e18aaaSAndroid Build Coastguard Worker        Examples:
641*c2e18aaaSAndroid Build Coastguard Worker            atest FrameworksServicesTests:com.android.server.wm.ScreenDecorWindowTests
642*c2e18aaaSAndroid Build Coastguard Worker            atest FrameworksServicesTests:ScreenDecorWindowTests
643*c2e18aaaSAndroid Build Coastguard Worker            atest ScreenDecorWindowTests
644*c2e18aaaSAndroid Build Coastguard Worker
645*c2e18aaaSAndroid Build Coastguard Worker    < TF INTEGRATION TEST >
646*c2e18aaaSAndroid Build Coastguard Worker
647*c2e18aaaSAndroid Build Coastguard Worker        To run tests that are integrated directly into TradeFed (non-modules), input the name as it appears in the output of the "tradefed.sh list configs" cmd.
648*c2e18aaaSAndroid Build Coastguard Worker
649*c2e18aaaSAndroid Build Coastguard Worker        Examples:
650*c2e18aaaSAndroid Build Coastguard Worker           atest example/reboot
651*c2e18aaaSAndroid Build Coastguard Worker           atest native-benchmark
652*c2e18aaaSAndroid Build Coastguard Worker
653*c2e18aaaSAndroid Build Coastguard Worker
654*c2e18aaaSAndroid Build Coastguard Worker    < FILE PATH >
655*c2e18aaaSAndroid Build Coastguard Worker
656*c2e18aaaSAndroid Build Coastguard Worker        Both module-based tests and integration-based tests can be run by inputting the path to their test file or dir as appropriate. A single class can also be run by inputting the path to the class's java file.
657*c2e18aaaSAndroid Build Coastguard Worker
658*c2e18aaaSAndroid Build Coastguard Worker        Both relative and absolute paths are supported.
659*c2e18aaaSAndroid Build Coastguard Worker
660*c2e18aaaSAndroid Build Coastguard Worker        Example - 2 ways to run the `CtsJankDeviceTestCases` module via path:
661*c2e18aaaSAndroid Build Coastguard Worker        1. run module from android <repo root>:
662*c2e18aaaSAndroid Build Coastguard Worker            atest cts/tests/jank/jank
663*c2e18aaaSAndroid Build Coastguard Worker
664*c2e18aaaSAndroid Build Coastguard Worker        2. from <android root>/cts/tests/jank:
665*c2e18aaaSAndroid Build Coastguard Worker            atest .
666*c2e18aaaSAndroid Build Coastguard Worker
667*c2e18aaaSAndroid Build Coastguard Worker        Example - run a specific class within CtsJankDeviceTestCases module from <android repo> root via path:
668*c2e18aaaSAndroid Build Coastguard Worker           atest cts/tests/jank/src/android/jank/cts/ui/CtsDeviceJankUi.java
669*c2e18aaaSAndroid Build Coastguard Worker
670*c2e18aaaSAndroid Build Coastguard Worker        Example - run an integration test from <android repo> root via path:
671*c2e18aaaSAndroid Build Coastguard Worker           atest tools/tradefederation/contrib/res/config/example/reboot.xml
672*c2e18aaaSAndroid Build Coastguard Worker
673*c2e18aaaSAndroid Build Coastguard Worker
674*c2e18aaaSAndroid Build Coastguard Worker    < PACKAGE NAME >
675*c2e18aaaSAndroid Build Coastguard Worker
676*c2e18aaaSAndroid Build Coastguard Worker        Atest supports searching tests from package name as well.
677*c2e18aaaSAndroid Build Coastguard Worker
678*c2e18aaaSAndroid Build Coastguard Worker        Examples:
679*c2e18aaaSAndroid Build Coastguard Worker           atest com.android.server.wm
680*c2e18aaaSAndroid Build Coastguard Worker           atest android.jank.cts
681*c2e18aaaSAndroid Build Coastguard Worker
682*c2e18aaaSAndroid Build Coastguard Worker
683*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - - - - - - - - - - - - - - -
684*c2e18aaaSAndroid Build Coastguard Worker    SPECIFYING INDIVIDUAL STEPS: BUILD, INSTALL OR RUN
685*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - - - - - - - - - - - - - - -
686*c2e18aaaSAndroid Build Coastguard Worker
687*c2e18aaaSAndroid Build Coastguard Worker    The -b, -i and -t options allow you to specify which steps you want to run. If none of those options are given, then all steps are run. If any of these options are provided then only the listed steps are run.
688*c2e18aaaSAndroid Build Coastguard Worker
689*c2e18aaaSAndroid Build Coastguard Worker    Note: -i alone is not currently support and can only be included with -t.
690*c2e18aaaSAndroid Build Coastguard Worker    Both -b and -t can be run alone.
691*c2e18aaaSAndroid Build Coastguard Worker
692*c2e18aaaSAndroid Build Coastguard Worker    Examples:
693*c2e18aaaSAndroid Build Coastguard Worker        atest -b <test>    (just build targets)
694*c2e18aaaSAndroid Build Coastguard Worker        atest -t <test>    (run tests only)
695*c2e18aaaSAndroid Build Coastguard Worker        atest -it <test>   (install apk and run tests)
696*c2e18aaaSAndroid Build Coastguard Worker        atest -bt <test>   (build targets, run tests, but skip installing apk)
697*c2e18aaaSAndroid Build Coastguard Worker
698*c2e18aaaSAndroid Build Coastguard Worker
699*c2e18aaaSAndroid Build Coastguard Worker    Atest now has the ability to force a test to skip its cleanup/teardown step. Many tests, e.g. CTS, cleanup the device after the test is run, so trying to rerun your test with -t will fail without having the --disable-teardown parameter. Use -d before -t to skip the test clean up step and test iteratively.
700*c2e18aaaSAndroid Build Coastguard Worker
701*c2e18aaaSAndroid Build Coastguard Worker        atest -d <test>    (disable installing apk and cleaning up device)
702*c2e18aaaSAndroid Build Coastguard Worker        atest -t <test>
703*c2e18aaaSAndroid Build Coastguard Worker
704*c2e18aaaSAndroid Build Coastguard Worker    Note that -t disables both setup/install and teardown/cleanup of the device. So you can continue to rerun your test with just
705*c2e18aaaSAndroid Build Coastguard Worker
706*c2e18aaaSAndroid Build Coastguard Worker        atest -t <test>
707*c2e18aaaSAndroid Build Coastguard Worker
708*c2e18aaaSAndroid Build Coastguard Worker    as many times as you want.
709*c2e18aaaSAndroid Build Coastguard Worker
710*c2e18aaaSAndroid Build Coastguard Worker
711*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - -
712*c2e18aaaSAndroid Build Coastguard Worker    RUNNING SPECIFIC METHODS
713*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - -
714*c2e18aaaSAndroid Build Coastguard Worker
715*c2e18aaaSAndroid Build Coastguard Worker    It is possible to run only specific methods within a test class. To run only specific methods, identify the class in any of the ways supported for identifying a class (MODULE:CLASS, FILE PATH, etc) and then append the name of the method or method using the following template:
716*c2e18aaaSAndroid Build Coastguard Worker
717*c2e18aaaSAndroid Build Coastguard Worker      <reference_to_class>#<method1>
718*c2e18aaaSAndroid Build Coastguard Worker
719*c2e18aaaSAndroid Build Coastguard Worker    Multiple methods can be specified with commas:
720*c2e18aaaSAndroid Build Coastguard Worker
721*c2e18aaaSAndroid Build Coastguard Worker      <reference_to_class>#<method1>,<method2>,<method3>...
722*c2e18aaaSAndroid Build Coastguard Worker
723*c2e18aaaSAndroid Build Coastguard Worker    Examples:
724*c2e18aaaSAndroid Build Coastguard Worker      atest com.android.server.wm.ScreenDecorWindowTests#testMultipleDecors
725*c2e18aaaSAndroid Build Coastguard Worker
726*c2e18aaaSAndroid Build Coastguard Worker      atest FrameworksServicesTests:ScreenDecorWindowTests#testFlagChange,testRemoval
727*c2e18aaaSAndroid Build Coastguard Worker
728*c2e18aaaSAndroid Build Coastguard Worker
729*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - -
730*c2e18aaaSAndroid Build Coastguard Worker    FILTERING TESTS
731*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - -
732*c2e18aaaSAndroid Build Coastguard Worker    It is possible to run only the tests that are specified by a custom filter, although not all test types support filtering by wildcard.
733*c2e18aaaSAndroid Build Coastguard Worker
734*c2e18aaaSAndroid Build Coastguard Worker    Usage format:
735*c2e18aaaSAndroid Build Coastguard Worker      atest <TestModuleName> --test-filter <test.package.name>.<TestClass>#<testMethod>
736*c2e18aaaSAndroid Build Coastguard Worker
737*c2e18aaaSAndroid Build Coastguard Worker    Example:
738*c2e18aaaSAndroid Build Coastguard Worker      atest  ParameterizedHelloWorldTests --test-filter '.*HelloWorldTest#testHa.*'
739*c2e18aaaSAndroid Build Coastguard Worker
740*c2e18aaaSAndroid Build Coastguard Worker    Note: parametrized JarHostTests can only be filtered by a specific method if parameters are also provided TODO(b/326457393). Wildcard filtering is not supported TODO(b/326141263):
741*c2e18aaaSAndroid Build Coastguard Worker      atest <TestModuleName> --test-filter <test.package.name>.<ParameterizedTestClass>#<testMethod>[<param1>=<value>,<param2>=<value>]
742*c2e18aaaSAndroid Build Coastguard Worker
743*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - -
744*c2e18aaaSAndroid Build Coastguard Worker    RUNNING MULTIPLE CLASSES
745*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - -
746*c2e18aaaSAndroid Build Coastguard Worker
747*c2e18aaaSAndroid Build Coastguard Worker    To run multiple classes, deliminate them with spaces just like you would when running multiple tests.  Atest will handle building and running classes in the most efficient way possible, so specifying a subset of classes in a module will improve performance over running the whole module.
748*c2e18aaaSAndroid Build Coastguard Worker
749*c2e18aaaSAndroid Build Coastguard Worker
750*c2e18aaaSAndroid Build Coastguard Worker    Examples:
751*c2e18aaaSAndroid Build Coastguard Worker    - two classes in same module:
752*c2e18aaaSAndroid Build Coastguard Worker      atest FrameworksServicesTests:ScreenDecorWindowTests FrameworksServicesTests:DimmerTests
753*c2e18aaaSAndroid Build Coastguard Worker
754*c2e18aaaSAndroid Build Coastguard Worker    - two classes, different modules:
755*c2e18aaaSAndroid Build Coastguard Worker      atest FrameworksServicesTests:ScreenDecorWindowTests CtsJankDeviceTestCases:CtsDeviceJankUi
756*c2e18aaaSAndroid Build Coastguard Worker
757*c2e18aaaSAndroid Build Coastguard Worker
758*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - -
759*c2e18aaaSAndroid Build Coastguard Worker    RUNNING NATIVE TESTS
760*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - -
761*c2e18aaaSAndroid Build Coastguard Worker
762*c2e18aaaSAndroid Build Coastguard Worker    Atest can run native test.
763*c2e18aaaSAndroid Build Coastguard Worker
764*c2e18aaaSAndroid Build Coastguard Worker    Example:
765*c2e18aaaSAndroid Build Coastguard Worker    - Input tests:
766*c2e18aaaSAndroid Build Coastguard Worker      atest -a libinput_tests inputflinger_tests
767*c2e18aaaSAndroid Build Coastguard Worker
768*c2e18aaaSAndroid Build Coastguard Worker    Use -a|--all-abi to run the tests for all available device architectures, which in this example is armeabi-v7a (ARM 32-bit) and arm64-v8a (ARM 64-bit).
769*c2e18aaaSAndroid Build Coastguard Worker
770*c2e18aaaSAndroid Build Coastguard Worker    To select a specific native test to run, use colon (:) to specify the test name and hashtag (#) to further specify an individual method. For example, for the following test definition:
771*c2e18aaaSAndroid Build Coastguard Worker
772*c2e18aaaSAndroid Build Coastguard Worker        TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents)
773*c2e18aaaSAndroid Build Coastguard Worker
774*c2e18aaaSAndroid Build Coastguard Worker    You can run the entire test using:
775*c2e18aaaSAndroid Build Coastguard Worker
776*c2e18aaaSAndroid Build Coastguard Worker        atest inputflinger_tests:InputDispatcherTest
777*c2e18aaaSAndroid Build Coastguard Worker
778*c2e18aaaSAndroid Build Coastguard Worker    or an individual test method using:
779*c2e18aaaSAndroid Build Coastguard Worker
780*c2e18aaaSAndroid Build Coastguard Worker        atest inputflinger_tests:InputDispatcherTest#InjectInputEvent_ValidatesKeyEvents
781*c2e18aaaSAndroid Build Coastguard Worker
782*c2e18aaaSAndroid Build Coastguard Worker
783*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - - -
784*c2e18aaaSAndroid Build Coastguard Worker    RUNNING TESTS IN ITERATION
785*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - - -
786*c2e18aaaSAndroid Build Coastguard Worker
787*c2e18aaaSAndroid Build Coastguard Worker    To run tests in iterations, simply pass --iterations argument. No matter pass or fail, atest won't stop testing until the max iteration is reached.
788*c2e18aaaSAndroid Build Coastguard Worker
789*c2e18aaaSAndroid Build Coastguard Worker    Example:
790*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --iterations    # 10 iterations(by default).
791*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --iterations 5  # run <test> 5 times.
792*c2e18aaaSAndroid Build Coastguard Worker
793*c2e18aaaSAndroid Build Coastguard Worker    Two approaches that assist users to detect flaky tests:
794*c2e18aaaSAndroid Build Coastguard Worker
795*c2e18aaaSAndroid Build Coastguard Worker    1) Run all tests until a failure occurs or the max iteration is reached.
796*c2e18aaaSAndroid Build Coastguard Worker
797*c2e18aaaSAndroid Build Coastguard Worker    Example:
798*c2e18aaaSAndroid Build Coastguard Worker        - 10 iterations(by default).
799*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --rerun-until-failure
800*c2e18aaaSAndroid Build Coastguard Worker        - stop when failed or reached the 20th run.
801*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --rerun-until-failure 20
802*c2e18aaaSAndroid Build Coastguard Worker
803*c2e18aaaSAndroid Build Coastguard Worker    2) Run failed tests until passed or the max iteration is reached.
804*c2e18aaaSAndroid Build Coastguard Worker
805*c2e18aaaSAndroid Build Coastguard Worker    Example:
806*c2e18aaaSAndroid Build Coastguard Worker        - 10 iterations(by default).
807*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --retry-any-failure
808*c2e18aaaSAndroid Build Coastguard Worker        - stop when passed or reached the 20th run.
809*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --retry-any-failure 20
810*c2e18aaaSAndroid Build Coastguard Worker
811*c2e18aaaSAndroid Build Coastguard Worker
812*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - -
813*c2e18aaaSAndroid Build Coastguard Worker    RUNNING TESTS ON AVD(s)
814*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - -
815*c2e18aaaSAndroid Build Coastguard Worker
816*c2e18aaaSAndroid Build Coastguard Worker    Atest is able to run tests with the newly created AVD. Atest can build and 'acloud create' simultaneously, and run tests after the AVD has been created successfully.
817*c2e18aaaSAndroid Build Coastguard Worker
818*c2e18aaaSAndroid Build Coastguard Worker    Examples:
819*c2e18aaaSAndroid Build Coastguard Worker    - Start an AVD before running tests on that newly created device.
820*c2e18aaaSAndroid Build Coastguard Worker
821*c2e18aaaSAndroid Build Coastguard Worker        acloud create && atest <test>
822*c2e18aaaSAndroid Build Coastguard Worker
823*c2e18aaaSAndroid Build Coastguard Worker    can be simplified by:
824*c2e18aaaSAndroid Build Coastguard Worker
825*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --start-avd
826*c2e18aaaSAndroid Build Coastguard Worker
827*c2e18aaaSAndroid Build Coastguard Worker    - Start AVD(s) by specifying 'acloud create' arguments and run tests on that newly created device.
828*c2e18aaaSAndroid Build Coastguard Worker
829*c2e18aaaSAndroid Build Coastguard Worker        atest <test> --acloud-create "--build-id 6509363 --build-target aosp_cf_x86_phone-userdebug --branch aosp_master"
830*c2e18aaaSAndroid Build Coastguard Worker
831*c2e18aaaSAndroid Build Coastguard Worker    To know detail about the argument, please run 'acloud create --help'.
832*c2e18aaaSAndroid Build Coastguard Worker
833*c2e18aaaSAndroid Build Coastguard Worker    [WARNING]
834*c2e18aaaSAndroid Build Coastguard Worker    * --acloud-create must be the LAST optional argument: the remainder args will be consumed as its positional args.
835*c2e18aaaSAndroid Build Coastguard Worker    * --acloud-create/--start-avd do not delete newly created AVDs. The users will be deleting them manually.
836*c2e18aaaSAndroid Build Coastguard Worker
837*c2e18aaaSAndroid Build Coastguard Worker
838*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - -
839*c2e18aaaSAndroid Build Coastguard Worker    TESTS IN TEST MAPPING
840*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - -
841*c2e18aaaSAndroid Build Coastguard Worker
842*c2e18aaaSAndroid Build Coastguard Worker    Atest can run tests in TEST_MAPPING files:
843*c2e18aaaSAndroid Build Coastguard Worker
844*c2e18aaaSAndroid Build Coastguard Worker    1) Run presubmit tests in TEST_MAPPING files in current and parent
845*c2e18aaaSAndroid Build Coastguard Worker       directories. You can also specify a target directory.
846*c2e18aaaSAndroid Build Coastguard Worker
847*c2e18aaaSAndroid Build Coastguard Worker    Example:
848*c2e18aaaSAndroid Build Coastguard Worker        atest  (run presubmit tests in TEST_MAPPING files and host unit tests in current and parent directories)
849*c2e18aaaSAndroid Build Coastguard Worker        atest --test-mapping </path/to/project>
850*c2e18aaaSAndroid Build Coastguard Worker               (run presubmit tests in TEST_MAPPING files in </path/to/project> and its parent directories)
851*c2e18aaaSAndroid Build Coastguard Worker
852*c2e18aaaSAndroid Build Coastguard Worker    2) Run a specified test group in TEST_MAPPING files.
853*c2e18aaaSAndroid Build Coastguard Worker
854*c2e18aaaSAndroid Build Coastguard Worker    Example:
855*c2e18aaaSAndroid Build Coastguard Worker        atest :postsubmit
856*c2e18aaaSAndroid Build Coastguard Worker              (run postsubmit tests in TEST_MAPPING files in current and parent directories)
857*c2e18aaaSAndroid Build Coastguard Worker        atest :all
858*c2e18aaaSAndroid Build Coastguard Worker              (Run tests from all groups in TEST_MAPPING files)
859*c2e18aaaSAndroid Build Coastguard Worker        atest --test-mapping </path/to/project>:postsubmit
860*c2e18aaaSAndroid Build Coastguard Worker              (run postsubmit tests in TEST_MAPPING files in </path/to/project> and its parent directories)
861*c2e18aaaSAndroid Build Coastguard Worker        atest --test-mapping </path/to/project>:mainline-presubmit
862*c2e18aaaSAndroid Build Coastguard Worker              (run mainline tests in TEST_MAPPING files in </path/to/project> and its parent directories)
863*c2e18aaaSAndroid Build Coastguard Worker
864*c2e18aaaSAndroid Build Coastguard Worker    3) Run tests in TEST_MAPPING files including sub directories
865*c2e18aaaSAndroid Build Coastguard Worker
866*c2e18aaaSAndroid Build Coastguard Worker    By default, atest will only search for tests in TEST_MAPPING files in current (or given directory) and its parent directories. If you want to run tests in TEST_MAPPING files in the sub-directories, you can use option --include-subdirs to force atest to include those tests too.
867*c2e18aaaSAndroid Build Coastguard Worker
868*c2e18aaaSAndroid Build Coastguard Worker    Example:
869*c2e18aaaSAndroid Build Coastguard Worker        atest --include-subdirs [optional </path/to/project>:<test_group_name>]
870*c2e18aaaSAndroid Build Coastguard Worker              (run presubmit tests in TEST_MAPPING files in current, sub and parent directories)
871*c2e18aaaSAndroid Build Coastguard Worker    A path can be provided optionally if you want to search for tests in a given directory, with optional test group name. By default, the test group is presubmit.
872*c2e18aaaSAndroid Build Coastguard Worker
873*c2e18aaaSAndroid Build Coastguard Worker
874*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - - -
875*c2e18aaaSAndroid Build Coastguard Worker    ADDITIONAL ARGS TO TRADEFED
876*c2e18aaaSAndroid Build Coastguard Worker    - - - - - - - - - - - - - -
877*c2e18aaaSAndroid Build Coastguard Worker
878*c2e18aaaSAndroid Build Coastguard Worker    When trying to pass custom arguments for the test runners, everything after '--'
879*c2e18aaaSAndroid Build Coastguard Worker    will be consumed as custom args.
880*c2e18aaaSAndroid Build Coastguard Worker
881*c2e18aaaSAndroid Build Coastguard Worker    Example:
882*c2e18aaaSAndroid Build Coastguard Worker        atest -v <test> -- <custom_args1> <custom_args2>
883*c2e18aaaSAndroid Build Coastguard Worker
884*c2e18aaaSAndroid Build Coastguard Worker    Examples of passing options to the modules:
885*c2e18aaaSAndroid Build Coastguard Worker        atest <test> -- --module-arg <module-name>:<option-name>:<option-value>
886*c2e18aaaSAndroid Build Coastguard Worker        atest GtsPermissionTestCases -- --module-arg GtsPermissionTestCases:ignore-business-logic-failure:true
887*c2e18aaaSAndroid Build Coastguard Worker
888*c2e18aaaSAndroid Build Coastguard Worker    Examples of passing options to the runner type or class:
889*c2e18aaaSAndroid Build Coastguard Worker        atest <test> -- --test-arg <test-class>:<option-name>:<option-value>
890*c2e18aaaSAndroid Build Coastguard Worker        atest CtsVideoTestCases -- --test-arg com.android.tradefed.testtype.JarHosttest:collect-tests-only:true
891*c2e18aaaSAndroid Build Coastguard Worker
892*c2e18aaaSAndroid Build Coastguard Worker
893*c2e18aaaSAndroid Build Coastguard Worker                                                     2022-03-25
894*c2e18aaaSAndroid Build Coastguard Worker"""
895