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