xref: /aosp_15_r20/art/test/README.atest.md (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker# Running ART Tests with Atest / Trade Federation
2*795d594fSAndroid Build Coastguard Worker
3*795d594fSAndroid Build Coastguard WorkerART Testing has early support for execution in the [Trade
4*795d594fSAndroid Build Coastguard WorkerFederation](https://source.android.com/devices/tech/test_infra/tradefed)
5*795d594fSAndroid Build Coastguard Worker("TradeFed") test harness, in particular via the
6*795d594fSAndroid Build Coastguard Worker[Atest](https://source.android.com/compatibility/tests/development/atest)
7*795d594fSAndroid Build Coastguard Workercommand line tool.
8*795d594fSAndroid Build Coastguard Worker
9*795d594fSAndroid Build Coastguard WorkerAtest conveniently takes care of building tests and their dependencies (using
10*795d594fSAndroid Build Coastguard WorkerSoong, the Android build system) and executing them using Trade Federation.
11*795d594fSAndroid Build Coastguard Worker
12*795d594fSAndroid Build Coastguard WorkerSee also [README.md](README.md) for a general introduction to ART run-tests and
13*795d594fSAndroid Build Coastguard Workergtests.
14*795d594fSAndroid Build Coastguard Worker
15*795d594fSAndroid Build Coastguard Worker## ART run-tests
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker### Running ART run-tests on device
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard WorkerART run-tests are defined in sub-directories of `test/` starting with a number
20*795d594fSAndroid Build Coastguard Worker(e.g. `test/001-HelloWorld`). Each ART run-test is identified in the build
21*795d594fSAndroid Build Coastguard Workersystem by a Soong module name following the `art-run-test-`*`<test-directory>`*
22*795d594fSAndroid Build Coastguard Workerformat (e.g. `art-run-test-001-HelloWorld`).
23*795d594fSAndroid Build Coastguard Worker
24*795d594fSAndroid Build Coastguard WorkerYou can run a specific ART run-test on device by passing its Soong module name
25*795d594fSAndroid Build Coastguard Workerto Atest:
26*795d594fSAndroid Build Coastguard Worker```bash
27*795d594fSAndroid Build Coastguard Workeratest art-run-test-001-HelloWorld
28*795d594fSAndroid Build Coastguard Worker```
29*795d594fSAndroid Build Coastguard Worker
30*795d594fSAndroid Build Coastguard WorkerTo run all ART run-tests in a single command, the currently recommended way is
31*795d594fSAndroid Build Coastguard Workerto use [test mapping](#test-mapping) (see below).
32*795d594fSAndroid Build Coastguard Worker
33*795d594fSAndroid Build Coastguard WorkerYou can nonetheless run all supported ART run-tests with a single Atest command,
34*795d594fSAndroid Build Coastguard Workerusing its support for wildcards:
35*795d594fSAndroid Build Coastguard Worker```bash
36*795d594fSAndroid Build Coastguard Workeratest art-run-test-\*
37*795d594fSAndroid Build Coastguard Worker```
38*795d594fSAndroid Build Coastguard Worker
39*795d594fSAndroid Build Coastguard WorkerNote: Many ART run-tests are failing with the TradeFed harness as of March 2021,
40*795d594fSAndroid Build Coastguard Workerso the above Atest command will likely report many tests failures. The ART team
41*795d594fSAndroid Build Coastguard Workeris actively working on this issue.
42*795d594fSAndroid Build Coastguard Worker
43*795d594fSAndroid Build Coastguard Worker## ART gtests
44*795d594fSAndroid Build Coastguard Worker
45*795d594fSAndroid Build Coastguard Worker### Running ART gtests on device
46*795d594fSAndroid Build Coastguard Worker
47*795d594fSAndroid Build Coastguard WorkerThere are three ways to run ART gtests on device:
48*795d594fSAndroid Build Coastguard Worker1. by building "standalone" ART gtests and running them against the active ART
49*795d594fSAndroid Build Coastguard Worker   APEX on the device;
50*795d594fSAndroid Build Coastguard Worker2. by installing the Testing ART APEX (i.e. manually "updating" the ART APEX on
51*795d594fSAndroid Build Coastguard Worker   device); or
52*795d594fSAndroid Build Coastguard Worker3. by setting up a `chroot` environment on the device, and "activating" the
53*795d594fSAndroid Build Coastguard Worker   Testing ART APEX in that environment.
54*795d594fSAndroid Build Coastguard Worker
55*795d594fSAndroid Build Coastguard WorkerThe first approach can be used to test the ART APEX presently residing on a
56*795d594fSAndroid Build Coastguard Workerdevice (either the original one, located in the "system" partition, or an
57*795d594fSAndroid Build Coastguard Workerupdated package, present in the "data" partition).
58*795d594fSAndroid Build Coastguard Worker
59*795d594fSAndroid Build Coastguard WorkerThe second and third approaches make use of the Testing ART APEX
60*795d594fSAndroid Build Coastguard Worker(`com.android.art.testing.apex`), and were previously the only options to run
61*795d594fSAndroid Build Coastguard WorkerART gtests on device, because of build- and link-related limitations (the ART
62*795d594fSAndroid Build Coastguard Workergtests had to be part of the ART APEX package itself to be able to build and run
63*795d594fSAndroid Build Coastguard Workerproperly).
64*795d594fSAndroid Build Coastguard Worker
65*795d594fSAndroid Build Coastguard Worker### Running standalone ART gtests on device
66*795d594fSAndroid Build Coastguard Worker
67*795d594fSAndroid Build Coastguard WorkerStandalone ART gtests are defined as Soong modules `art_standalone_*_tests`. You
68*795d594fSAndroid Build Coastguard Workercan run them individually with Atest, e.g:
69*795d594fSAndroid Build Coastguard Worker
70*795d594fSAndroid Build Coastguard Worker```bash
71*795d594fSAndroid Build Coastguard Workeratest art_standalone_cmdline_tests
72*795d594fSAndroid Build Coastguard Worker```
73*795d594fSAndroid Build Coastguard Worker
74*795d594fSAndroid Build Coastguard WorkerYou can also run all of them with a single Atest command, using its support for
75*795d594fSAndroid Build Coastguard Workerwildcards:
76*795d594fSAndroid Build Coastguard Worker
77*795d594fSAndroid Build Coastguard Worker```bash
78*795d594fSAndroid Build Coastguard Workeratest art_standalone_\*_tests
79*795d594fSAndroid Build Coastguard Worker```
80*795d594fSAndroid Build Coastguard Worker
81*795d594fSAndroid Build Coastguard WorkerThe previous commands build the corresponding ART gtests and their dependencies,
82*795d594fSAndroid Build Coastguard Workerdynamically link them against local ART APEX libraries (in the source tree), and
83*795d594fSAndroid Build Coastguard Workerrun them on device against the active ART APEX.
84*795d594fSAndroid Build Coastguard Worker
85*795d594fSAndroid Build Coastguard Worker### Running ART gtests on device by installing the Testing ART APEX
86*795d594fSAndroid Build Coastguard Worker
87*795d594fSAndroid Build Coastguard WorkerYou can run ART gtests on device with the ART APEX installation strategy by
88*795d594fSAndroid Build Coastguard Workerusing the following `atest` command:
89*795d594fSAndroid Build Coastguard Worker
90*795d594fSAndroid Build Coastguard Worker```bash
91*795d594fSAndroid Build Coastguard Workeratest ArtGtestsTargetInstallApex
92*795d594fSAndroid Build Coastguard Worker```
93*795d594fSAndroid Build Coastguard Worker
94*795d594fSAndroid Build Coastguard WorkerThis command:
95*795d594fSAndroid Build Coastguard Worker1. builds the Testing ART APEX from the Android source tree (including the ART
96*795d594fSAndroid Build Coastguard Worker   gtests);
97*795d594fSAndroid Build Coastguard Worker2. installs the Testing ART APEX using `adb install`;
98*795d594fSAndroid Build Coastguard Worker3. reboots the device;
99*795d594fSAndroid Build Coastguard Worker4. runs the tests; and
100*795d594fSAndroid Build Coastguard Worker5. uninstalls the module.
101*795d594fSAndroid Build Coastguard Worker
102*795d594fSAndroid Build Coastguard WorkerYou can run the tests of a single ART gtest C++ class using the
103*795d594fSAndroid Build Coastguard Worker`ArtGtestsTargetInstallApex:`*`<art-gtest-c++-class>`* syntax, e.g.:
104*795d594fSAndroid Build Coastguard Worker```bash
105*795d594fSAndroid Build Coastguard Workeratest ArtGtestsTargetInstallApex:JniInternalTest
106*795d594fSAndroid Build Coastguard Worker```
107*795d594fSAndroid Build Coastguard Worker
108*795d594fSAndroid Build Coastguard WorkerThis syntax also supports the use of wildcards, e.g.:
109*795d594fSAndroid Build Coastguard Worker```bash
110*795d594fSAndroid Build Coastguard Workeratest ArtGtestsTargetInstallApex:*Test*
111*795d594fSAndroid Build Coastguard Worker```
112*795d594fSAndroid Build Coastguard Worker
113*795d594fSAndroid Build Coastguard WorkerYou can also use Trade Federation options to run a subset of ART gtests, e.g.:
114*795d594fSAndroid Build Coastguard Worker```bash
115*795d594fSAndroid Build Coastguard Workeratest ArtGtestsTargetInstallApex -- \
116*795d594fSAndroid Build Coastguard Worker  --module ArtGtestsTargetInstallApex --test '*JniInternalTest*'
117*795d594fSAndroid Build Coastguard Worker```
118*795d594fSAndroid Build Coastguard Worker
119*795d594fSAndroid Build Coastguard WorkerYou can also pass option `--gtest_filter` to the gtest binary to achieve a
120*795d594fSAndroid Build Coastguard Workersimilar effect:
121*795d594fSAndroid Build Coastguard Worker```bash
122*795d594fSAndroid Build Coastguard Workeratest ArtGtestsTargetInstallApex -- \
123*795d594fSAndroid Build Coastguard Worker  --test-arg com.android.tradefed.testtype.GTest:native-test-flag:"--gtest_filter=*JniInternalTest*"
124*795d594fSAndroid Build Coastguard Worker```
125*795d594fSAndroid Build Coastguard Worker
126*795d594fSAndroid Build Coastguard Worker### Running ART gtests on device using a `chroot` environment
127*795d594fSAndroid Build Coastguard Worker
128*795d594fSAndroid Build Coastguard WorkerYou can run ART gtests on device with the chroot-based strategy by using the
129*795d594fSAndroid Build Coastguard Workerfollowing command:
130*795d594fSAndroid Build Coastguard Worker
131*795d594fSAndroid Build Coastguard Worker```bash
132*795d594fSAndroid Build Coastguard Workeratest ArtGtestsTargetChroot
133*795d594fSAndroid Build Coastguard Worker```
134*795d594fSAndroid Build Coastguard Worker
135*795d594fSAndroid Build Coastguard WorkerThis sequence:
136*795d594fSAndroid Build Coastguard Worker1. builds the Testing ART APEX from the Android source tree (including the ART
137*795d594fSAndroid Build Coastguard Worker   gtests) and all the necessary dependencies for the `chroot` environment;
138*795d594fSAndroid Build Coastguard Worker2. sets up a `chroot` environment on the device;
139*795d594fSAndroid Build Coastguard Worker3. "activates" the Testing ART APEX (and other APEXes that it depends on) in the
140*795d594fSAndroid Build Coastguard Worker   `chroot` environment;
141*795d594fSAndroid Build Coastguard Worker4. runs the tests within the `chroot` environment; and
142*795d594fSAndroid Build Coastguard Worker5. cleans up the environment (deactivates the APEXes and removes the `chroot`
143*795d594fSAndroid Build Coastguard Worker   environment).
144*795d594fSAndroid Build Coastguard Worker
145*795d594fSAndroid Build Coastguard Worker### Running ART gtests on host
146*795d594fSAndroid Build Coastguard Worker
147*795d594fSAndroid Build Coastguard WorkerYou first need to build the boot classpath and boot image on host:
148*795d594fSAndroid Build Coastguard Worker
149*795d594fSAndroid Build Coastguard Worker```bash
150*795d594fSAndroid Build Coastguard Workerm art-host-tests
151*795d594fSAndroid Build Coastguard Worker```
152*795d594fSAndroid Build Coastguard Worker
153*795d594fSAndroid Build Coastguard WorkerThen you can use `atest --host` to run host gtests, e.g:
154*795d594fSAndroid Build Coastguard Worker
155*795d594fSAndroid Build Coastguard Worker```bash
156*795d594fSAndroid Build Coastguard Workeratest --host art_runtime_tests
157*795d594fSAndroid Build Coastguard Worker```
158*795d594fSAndroid Build Coastguard Worker
159*795d594fSAndroid Build Coastguard Worker## Test Mapping
160*795d594fSAndroid Build Coastguard Worker
161*795d594fSAndroid Build Coastguard WorkerART Testing supports the execution of tests via [Test
162*795d594fSAndroid Build Coastguard WorkerMapping](https://source.android.com/compatibility/tests/development/test-mapping).
163*795d594fSAndroid Build Coastguard WorkerThe tests declared in ART's [TEST_MAPPING](../TEST_MAPPING) file are executed
164*795d594fSAndroid Build Coastguard Workerduring pre-submit testing (when an ART changelist in Gerrit is verified by
165*795d594fSAndroid Build Coastguard WorkerTreehugger) and/or post-submit testing (when a given change is merged in the
166*795d594fSAndroid Build Coastguard WorkerAndroid code base), depending on the "test group" where a test is declared.
167*795d594fSAndroid Build Coastguard Worker
168*795d594fSAndroid Build Coastguard Worker### Running tests via Test Mapping with Atest
169*795d594fSAndroid Build Coastguard Worker
170*795d594fSAndroid Build Coastguard WorkerIt is possible to run tests via test mapping locally using Atest.
171*795d594fSAndroid Build Coastguard Worker
172*795d594fSAndroid Build Coastguard WorkerTo run all the tests declared in ART's `TEST_MAPPING` file, use the following
173*795d594fSAndroid Build Coastguard Workercommand from the Android source tree top-level directory:
174*795d594fSAndroid Build Coastguard Worker```bash
175*795d594fSAndroid Build Coastguard Workeratest --test-mapping art:all
176*795d594fSAndroid Build Coastguard Worker```
177*795d594fSAndroid Build Coastguard WorkerIn the previous command, `art` is the (relative) path to the directory
178*795d594fSAndroid Build Coastguard Workercontaining the `TEST_MAPPING` file listing the tests to run, while `all` means
179*795d594fSAndroid Build Coastguard Workerthat tests declared in all [test
180*795d594fSAndroid Build Coastguard Workergroups](https://source.android.com/compatibility/tests/development/test-mapping#defining_test_groups)
181*795d594fSAndroid Build Coastguard Workershall be run.
182*795d594fSAndroid Build Coastguard Worker
183*795d594fSAndroid Build Coastguard WorkerTo only run tests executed during pre-submit testing, use:
184*795d594fSAndroid Build Coastguard Worker```bash
185*795d594fSAndroid Build Coastguard Workeratest --test-mapping art:presubmit
186*795d594fSAndroid Build Coastguard Worker```
187