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 '--use-modules-in', 260 help=( 261 'Force include MODULES-IN-* as build targets. Hint: This may solve' 262 ' missing test dependencies issue.' 263 ), 264 action='store_true', 265 ) 266 parser.add_argument( 267 '-w', 268 '--wait-for-debugger', 269 action='store_true', 270 help='Wait for debugger prior to execution (Instrumentation tests only).', 271 ) 272 273 ugroup = parser.add_mutually_exclusive_group() 274 ugroup.add_argument( 275 '--request-upload-result', 276 action='store_true', 277 help=( 278 'Request permission to upload test result. This option only needs' 279 ' to set once and takes effect until --disable-upload-result is' 280 ' set.' 281 ), 282 ) 283 ugroup.add_argument( 284 '--disable-upload-result', 285 action='store_true', 286 help=( 287 'Turn off the upload of test result. This option only needs to set' 288 ' once and takes effect until --request-upload-result is set' 289 ), 290 ) 291 292 test_mapping_or_host_unit_group = parser.add_mutually_exclusive_group() 293 test_mapping_or_host_unit_group.add_argument( 294 '-p', 295 '--test-mapping', 296 action='store_true', 297 help='Run tests defined in TEST_MAPPING files.', 298 ) 299 test_mapping_or_host_unit_group.add_argument( 300 '--host-unit-test-only', 301 action='store_true', 302 help='Run all host unit tests under the current directory.', 303 ) 304 parser.add_argument( 305 '--include-subdirs', 306 action='store_true', 307 help='Search TEST_MAPPING files in subdirs as well.', 308 ) 309 # TODO(b/146980564): Remove enable-file-patterns when support 310 # file-patterns in TEST_MAPPING by default. 311 parser.add_argument( 312 '--enable-file-patterns', 313 action='store_true', 314 help='Enable FILE_PATTERNS in TEST_MAPPING.', 315 ) 316 317 group = parser.add_mutually_exclusive_group() 318 group.add_argument( 319 '--collect-tests-only', 320 action='store_true', 321 help=( 322 'Collect a list test cases of the instrumentation tests without' 323 ' testing them in real.' 324 ), 325 ) 326 group.add_argument( 327 '--dry-run', 328 action='store_true', 329 help=( 330 'Dry run atest without building, installing and running tests in' 331 ' real.' 332 ), 333 ) 334 parser.add_argument( 335 '-L', '--list-modules', help='List testable modules of the given suite.' 336 ) 337 parser.add_argument( 338 '-v', 339 '--verbose', 340 action='store_true', 341 help='Display DEBUG level logging.', 342 ) 343 parser.add_argument( 344 '-V', '--version', action='store_true', help='Display version string.' 345 ) 346 parser.add_argument( 347 '--build-output', 348 default=BuildOutputMode.STREAMED, 349 choices=BuildOutputMode, 350 type=BuildOutputMode, 351 help=( 352 'Specifies the desired build output mode. Valid values are:' 353 f' {_output_mode_msg()}' 354 ), 355 ) 356 357 agroup = parser.add_mutually_exclusive_group() 358 agroup.add_argument( 359 '--acloud-create', 360 nargs=argparse.REMAINDER, 361 type=str, 362 help='(For testing with AVDs) Create AVD(s) via acloud command.', 363 ) 364 agroup.add_argument( 365 '--start-avd', 366 action='store_true', 367 help=( 368 '(For testing with AVDs) Automatically create an AVD and run tests' 369 ' on the virtual device.' 370 ), 371 ) 372 agroup.add_argument( 373 '-s', '--serial', action='append', help='The device to run the test on.' 374 ) 375 376 parser.add_argument( 377 '--test-config-select', 378 action='store_true', 379 help=( 380 'If multiple test config belong to same test module pop out a' 381 ' selection menu on console.' 382 ), 383 ) 384 385 parser.add_argument( 386 '--instant', 387 action='store_true', 388 help=( 389 '(For module parameterization) Run the instant_app version of the' 390 " module if the module supports it. Note: Nothing's going to run if" 391 " it's not an Instant App test and '--instant' is passed." 392 ), 393 ) 394 parser.add_argument( 395 '--user-type', 396 help=( 397 '(For module parameterization) Run test with specific user type,' 398 ' e.g. atest <test> --user-type secondary_user' 399 ), 400 ) 401 parser.add_argument( 402 '--annotation-filter', 403 action='append', 404 help=( 405 '(For module parameterization) Accept keyword that will be' 406 ' translated to fully qualified annotation class name.' 407 ), 408 ) 409 410 parser.add_argument( 411 '-c', 412 '--clear-cache', 413 action='store_true', 414 help='Wipe out the test_infos cache of the test and start a new search.', 415 ) 416 parser.add_argument( 417 '-D', 418 '--tf-debug', 419 nargs='?', 420 const=10888, 421 type=_positive_int, 422 default=0, 423 help='Enable tradefed debug mode with a specified port. (default: 10888)', 424 ) 425 parser.add_argument( 426 '--tf-template', 427 action='append', 428 help=( 429 'Add extra tradefed template for ATest suite, e.g. atest <test>' 430 ' --tf-template <template_key>=<template_path>' 431 ), 432 ) 433 parser.add_argument( 434 '--test-filter', 435 nargs='?', 436 # TODO(b/326457393): JarHostTest to support running parameterized tests 437 # with base method 438 # TODO(b/326141263): TradeFed to support wildcard in include-filter for 439 # parametrized JarHostTests 440 help=( 441 'Run only the tests which are specified with this option. This value' 442 ' is passed directly to the testing framework so you should use' 443 " appropriate syntax (e.g. JUnit supports regex, while python's" 444 ' unittest supports fnmatch syntax).' 445 ), 446 ) 447 parser.add_argument( 448 '--test-timeout', 449 nargs='?', 450 type=int, 451 help=( 452 'Customize test timeout. E.g. 60000(in milliseconds) represents 1' 453 ' minute timeout. For no timeout, set to 0.' 454 ), 455 ) 456 457 iteration_group = parser.add_mutually_exclusive_group() 458 iteration_group.add_argument( 459 '--iterations', 460 nargs='?', 461 type=_positive_int, 462 const=10, 463 default=0, 464 metavar='MAX_ITERATIONS', 465 help=( 466 '(For iteration testing) Loop-run tests until the max iteration is' 467 ' reached. (default: 10)' 468 ), 469 ) 470 iteration_group.add_argument( 471 '--rerun-until-failure', 472 nargs='?', 473 type=_positive_int, 474 const=2147483647, # Java's Integer.MAX_VALUE for TradeFed. 475 default=0, 476 metavar='MAX_ITERATIONS', 477 help=( 478 '(For iteration testing) Rerun all tests until a failure occurs or' 479 ' the max iteration is reached. (default: forever!)' 480 ), 481 ) 482 iteration_group.add_argument( 483 '--retry-any-failure', 484 nargs='?', 485 type=_positive_int, 486 const=10, 487 default=0, 488 metavar='MAX_ITERATIONS', 489 help=( 490 '(For iteration testing) Rerun failed tests until passed or the max' 491 ' iteration is reached. (default: 10)' 492 ), 493 ) 494 495 history_group = parser.add_mutually_exclusive_group() 496 history_group.add_argument( 497 '--latest-result', action='store_true', help='Print latest test result.' 498 ) 499 history_group.add_argument( 500 '--history', 501 nargs='?', 502 const='99999', 503 help=( 504 'Show test results in chronological order(with specified number or' 505 ' all by default).' 506 ), 507 ) 508 509 parser.add_argument( 510 constants.NO_METRICS_ARG, 511 action='store_true', 512 help='(For metrics) Do not send metrics.', 513 ) 514 515 parser.add_argument( 516 '--aggregate-metric-filter', 517 action='append', 518 help=( 519 '(For performance tests) Regular expression that will be used for' 520 ' filtering the aggregated metrics.' 521 ), 522 ) 523 524 parser.add_argument( 525 '--perf-itr-metrics', 526 action='store_true', 527 help='(For performance tests) Print individual performance metric.', 528 ) 529 530 parser.add_argument( 531 '--no-checking-device', 532 action='store_true', 533 help='Do NOT check device availability. (even it is a device test)', 534 ) 535 536 parser.add_argument( 537 '-j', 538 '--build-j', 539 nargs='?', 540 type=int, 541 help='Number of build run processes.', 542 ) 543 # Flag to use atest_local_min.xml as the TF base templates, this is added 544 # to roll out the change that uses separate templates for device/deviceless 545 # tests and should be removed once that feature is stable. 546 parser.add_argument( 547 '--use-tf-min-base-template', 548 dest='use_tf_min_base_template', 549 action=argparse.BooleanOptionalAction, 550 default=False, 551 help='Run tests using atest_local_min.xml as the TF base templates.', 552 ) 553 554 # This arg actually doesn't consume anything, it's primarily used for 555 # the help description and creating custom_args in the NameSpace object. 556 parser.add_argument( 557 '--', 558 dest='custom_args', 559 nargs='*', 560 help=( 561 'Specify custom args for the test runners. Everything after -- will' 562 ' be consumed as custom args.' 563 ), 564 ) 565 566 return parser 567 568 569_HELP_DESCRIPTION = """NAME 570 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 572 573SYNOPSIS 574 atest [OPTION]... [TEST_TARGET]... -- [CUSTOM_ARGS]... 575 576 577OPTIONS 578 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 580 *NOTE* Atest reads ~/.atest/config that supports all optional arguments to help users reduce repeating options they often use. 581 E.g. Assume "--all-abi" and "--verbose" are frequently used and have been defined line-by-line in ~/.atest/config, issuing 582 583 atest hello_world_test -v -- --test-arg xxx 584 585 is equivalent to 586 587 atest hello_world_test -v --all-abi --verbose -- --test-arg xxx 588 589 If you only need to run tests for a specific abi, please use: 590 atest <test> -- --abi arm64-v8a # ARM 64-bit 591 atest <test> -- --abi armeabi-v7a # ARM 32-bit 592 593 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 will be ignored without any hints. 595 596 597EXAMPLES 598 - - - - - - - - - 599 IDENTIFYING TESTS 600 - - - - - - - - - 601 602 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 604 Usage template: atest <reference_to_test_1> <reference_to_test_2> 605 606 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 608 609 < MODULE NAME > 610 611 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 613 Note: Use < TF INTEGRATION TEST > to run non-module tests integrated directly into TradeFed. 614 615 Examples: 616 atest FrameworksServicesTests 617 atest CtsJankDeviceTestCases 618 619 620 < MODULE:CLASS > 621 622 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 624 Examples: 625 atest FrameworksServicesTests:ScreenDecorWindowTests 626 atest FrameworksServicesTests:com.android.server.wm.ScreenDecorWindowTests 627 atest CtsJankDeviceTestCases:CtsDeviceJankUi 628 629 630 < CLASS NAME > 631 632 A single class can also be run by referencing the class name without the module name. 633 634 Examples: 635 atest ScreenDecorWindowTests 636 atest CtsDeviceJankUi 637 638 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 640 Examples: 641 atest FrameworksServicesTests:com.android.server.wm.ScreenDecorWindowTests 642 atest FrameworksServicesTests:ScreenDecorWindowTests 643 atest ScreenDecorWindowTests 644 645 < TF INTEGRATION TEST > 646 647 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 649 Examples: 650 atest example/reboot 651 atest native-benchmark 652 653 654 < FILE PATH > 655 656 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 658 Both relative and absolute paths are supported. 659 660 Example - 2 ways to run the `CtsJankDeviceTestCases` module via path: 661 1. run module from android <repo root>: 662 atest cts/tests/jank/jank 663 664 2. from <android root>/cts/tests/jank: 665 atest . 666 667 Example - run a specific class within CtsJankDeviceTestCases module from <android repo> root via path: 668 atest cts/tests/jank/src/android/jank/cts/ui/CtsDeviceJankUi.java 669 670 Example - run an integration test from <android repo> root via path: 671 atest tools/tradefederation/contrib/res/config/example/reboot.xml 672 673 674 < PACKAGE NAME > 675 676 Atest supports searching tests from package name as well. 677 678 Examples: 679 atest com.android.server.wm 680 atest android.jank.cts 681 682 683 - - - - - - - - - - - - - - - - - - - - - - - - - - 684 SPECIFYING INDIVIDUAL STEPS: BUILD, INSTALL OR RUN 685 - - - - - - - - - - - - - - - - - - - - - - - - - - 686 687 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 689 Note: -i alone is not currently support and can only be included with -t. 690 Both -b and -t can be run alone. 691 692 Examples: 693 atest -b <test> (just build targets) 694 atest -t <test> (run tests only) 695 atest -it <test> (install apk and run tests) 696 atest -bt <test> (build targets, run tests, but skip installing apk) 697 698 699 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 701 atest -d <test> (disable installing apk and cleaning up device) 702 atest -t <test> 703 704 Note that -t disables both setup/install and teardown/cleanup of the device. So you can continue to rerun your test with just 705 706 atest -t <test> 707 708 as many times as you want. 709 710 711 - - - - - - - - - - - - - 712 RUNNING SPECIFIC METHODS 713 - - - - - - - - - - - - - 714 715 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 717 <reference_to_class>#<method1> 718 719 Multiple methods can be specified with commas: 720 721 <reference_to_class>#<method1>,<method2>,<method3>... 722 723 Examples: 724 atest com.android.server.wm.ScreenDecorWindowTests#testMultipleDecors 725 726 atest FrameworksServicesTests:ScreenDecorWindowTests#testFlagChange,testRemoval 727 728 729 - - - - - - - - - - - - - 730 FILTERING TESTS 731 - - - - - - - - - - - - - 732 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 734 Usage format: 735 atest <TestModuleName> --test-filter <test.package.name>.<TestClass>#<testMethod> 736 737 Example: 738 atest ParameterizedHelloWorldTests --test-filter '.*HelloWorldTest#testHa.*' 739 740 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 atest <TestModuleName> --test-filter <test.package.name>.<ParameterizedTestClass>#<testMethod>[<param1>=<value>,<param2>=<value>] 742 743 - - - - - - - - - - - - - 744 RUNNING MULTIPLE CLASSES 745 - - - - - - - - - - - - - 746 747 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 749 750 Examples: 751 - two classes in same module: 752 atest FrameworksServicesTests:ScreenDecorWindowTests FrameworksServicesTests:DimmerTests 753 754 - two classes, different modules: 755 atest FrameworksServicesTests:ScreenDecorWindowTests CtsJankDeviceTestCases:CtsDeviceJankUi 756 757 758 - - - - - - - - - - - 759 RUNNING NATIVE TESTS 760 - - - - - - - - - - - 761 762 Atest can run native test. 763 764 Example: 765 - Input tests: 766 atest -a libinput_tests inputflinger_tests 767 768 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 770 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 772 TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) 773 774 You can run the entire test using: 775 776 atest inputflinger_tests:InputDispatcherTest 777 778 or an individual test method using: 779 780 atest inputflinger_tests:InputDispatcherTest#InjectInputEvent_ValidatesKeyEvents 781 782 783 - - - - - - - - - - - - - - 784 RUNNING TESTS IN ITERATION 785 - - - - - - - - - - - - - - 786 787 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 789 Example: 790 atest <test> --iterations # 10 iterations(by default). 791 atest <test> --iterations 5 # run <test> 5 times. 792 793 Two approaches that assist users to detect flaky tests: 794 795 1) Run all tests until a failure occurs or the max iteration is reached. 796 797 Example: 798 - 10 iterations(by default). 799 atest <test> --rerun-until-failure 800 - stop when failed or reached the 20th run. 801 atest <test> --rerun-until-failure 20 802 803 2) Run failed tests until passed or the max iteration is reached. 804 805 Example: 806 - 10 iterations(by default). 807 atest <test> --retry-any-failure 808 - stop when passed or reached the 20th run. 809 atest <test> --retry-any-failure 20 810 811 812 - - - - - - - - - - - - 813 RUNNING TESTS ON AVD(s) 814 - - - - - - - - - - - - 815 816 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 818 Examples: 819 - Start an AVD before running tests on that newly created device. 820 821 acloud create && atest <test> 822 823 can be simplified by: 824 825 atest <test> --start-avd 826 827 - Start AVD(s) by specifying 'acloud create' arguments and run tests on that newly created device. 828 829 atest <test> --acloud-create "--build-id 6509363 --build-target aosp_cf_x86_phone-userdebug --branch aosp_master" 830 831 To know detail about the argument, please run 'acloud create --help'. 832 833 [WARNING] 834 * --acloud-create must be the LAST optional argument: the remainder args will be consumed as its positional args. 835 * --acloud-create/--start-avd do not delete newly created AVDs. The users will be deleting them manually. 836 837 838 - - - - - - - - - - - - 839 TESTS IN TEST MAPPING 840 - - - - - - - - - - - - 841 842 Atest can run tests in TEST_MAPPING files: 843 844 1) Run presubmit tests in TEST_MAPPING files in current and parent 845 directories. You can also specify a target directory. 846 847 Example: 848 atest (run presubmit tests in TEST_MAPPING files and host unit tests in current and parent directories) 849 atest --test-mapping </path/to/project> 850 (run presubmit tests in TEST_MAPPING files in </path/to/project> and its parent directories) 851 852 2) Run a specified test group in TEST_MAPPING files. 853 854 Example: 855 atest :postsubmit 856 (run postsubmit tests in TEST_MAPPING files in current and parent directories) 857 atest :all 858 (Run tests from all groups in TEST_MAPPING files) 859 atest --test-mapping </path/to/project>:postsubmit 860 (run postsubmit tests in TEST_MAPPING files in </path/to/project> and its parent directories) 861 atest --test-mapping </path/to/project>:mainline-presubmit 862 (run mainline tests in TEST_MAPPING files in </path/to/project> and its parent directories) 863 864 3) Run tests in TEST_MAPPING files including sub directories 865 866 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 868 Example: 869 atest --include-subdirs [optional </path/to/project>:<test_group_name>] 870 (run presubmit tests in TEST_MAPPING files in current, sub and parent directories) 871 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 873 874 - - - - - - - - - - - - - - 875 ADDITIONAL ARGS TO TRADEFED 876 - - - - - - - - - - - - - - 877 878 When trying to pass custom arguments for the test runners, everything after '--' 879 will be consumed as custom args. 880 881 Example: 882 atest -v <test> -- <custom_args1> <custom_args2> 883 884 Examples of passing options to the modules: 885 atest <test> -- --module-arg <module-name>:<option-name>:<option-value> 886 atest GtsPermissionTestCases -- --module-arg GtsPermissionTestCases:ignore-business-logic-failure:true 887 888 Examples of passing options to the runner type or class: 889 atest <test> -- --test-arg <test-class>:<option-name>:<option-value> 890 atest CtsVideoTestCases -- --test-arg com.android.tradefed.testtype.JarHosttest:collect-tests-only:true 891 892 893 2022-03-25 894""" 895