blob: d71c6492abadb183c37e444974a48def6773ec0b [file] [log] [blame] [view]
Roland Levillain9d6864f2020-11-11 13:29:28 +00001# Running ART Tests with Atest / Trade Federation
2
3ART Testing has early support for execution in the [Trade
4Federation](https://source.android.com/devices/tech/test_infra/tradefed)
5("TradeFed") test harness, in particular via the
6[Atest](https://source.android.com/compatibility/tests/development/atest)
7command line tool.
8
9Atest conveniently takes care of building tests and their dependencies (using
10Soong, the Android build system) and executing them using Trade Federation.
11
12See also [README.md](README.md) for a general introduction to ART run-tests and
13gtests.
14
15## ART run-tests
16
17### Running ART run-tests on device
18
19ART run-tests are defined in sub-directories of `test/` starting with a number
20(e.g. `test/001-HelloWorld`). Each ART run-test is identified in the build
21system by a Soong module name following the `art-run-test-`*`<test-directory>`*
22format (e.g. `art-run-test-001-HelloWorld`).
23
24You can run a specific ART run-test on device by passing its Soong module name
25to Atest:
26```bash
27atest art-run-test-001-HelloWorld
28```
29
30To run all ART run-tests in a single command, the currently recommended way is
31to use [test mapping](#test-mapping) (see below).
32
33## ART gtests
34
35### Running ART gtests on device
36
37Because of current build- and link-related limitations, ART gtests can only run
38as part of the Testing ART APEX (`com.android.art.testing.apex`) on device,
39i.e. they have to be part of the ART APEX package itself to be able to build and
40run properly. This means that it is not possible to test the ART APEX presently
41residing on a device (either the original one, located in the "system"
42partition, or an updated package, present in the "data" partition).
43
44There are two ways to run ART gtests on device:
45* by installing the Testing ART APEX (i.e. manually "updating" the ART APEX on
46 device); or
47* by setting up a `chroot` environment on the device, and "activating" the
48 Testing ART APEX in that environment.
49
50### Running ART gtests on device by installing the Testing ART APEX
51
52You can run ART gtests on device with the ART APEX installation strategy by
53using the following `atest` command:
54
55```bash
56atest ArtGtestsTargetInstallApex
57```
58
59This command:
601. builds the Testing ART APEX from the Android source tree (including the ART
61 gtests);
622. installs the Testing ART APEX using `adb install`;
633. reboots the device;
644. runs the tests; and
655. uninstalls the module.
66
67You can run the tests of a single ART gtest C++ class using the
68`ArtGtestsTargetInstallApex:`*`<art-gtest-c++-class>`* syntax, e.g.:
69```bash
70atest ArtGtestsTargetInstallApex:JniInternalTest
71```
72
73This syntax also supports the use of wildcards, e.g.:
74```bash
75atest ArtGtestsTargetInstallApex:*Test*
76```
77
78You can also use Trade Federation options to run a subset of ART gtests, e.g.:
79```bash
80atest ArtGtestsTargetInstallApex -- \
81 --module ArtGtestsTargetInstallApex --test '*JniInternalTest*'
82```
83
84You can also pass option `--gtest_filter` to the gtest binary to achieve a
85similar effect:
86```bash
87atest ArtGtestsTargetInstallApex -- \
88 --test-arg com.android.tradefed.testtype.GTest:native-test-flag:"--gtest_filter=*JniInternalTest*"
89```
90
91### Running ART gtests on device using a `chroot` environment
92
93You can run ART gtests on device with the chroot-based strategy by using the
94following `atest` command:
95
96```bash
97atest ArtGtestsTargetChroot
98```
99
100This command:
1011. builds the Testing ART APEX from the Android source tree (including the ART
102 gtests) and all the necessary dependencies for the `chroot` environment;
1032. sets up a `chroot` environment on the device;
1043. "activates" the Testing ART APEX (and other APEXes that it depends on) in the
105 `chroot` environment;
1064. runs the tests within the `chroot` environment; and
1075. cleans up the environment (deactivates the APEXes and removes the `chroot`
108 environment).
109
110## Test Mapping
111
112ART Testing supports the execution of tests via [Test
113Mapping](https://source.android.com/compatibility/tests/development/test-mapping).
114The tests declared in ART's [TEST_MAPPING](../TEST_MAPPING) file are executed
115during pre-submit testing (when an ART changelist in Gerrit is verified by
116Treehugger) and/or post-submit testing (when a given change is merged in the
117Android code base), depending on the "test group" where a test is declared.
118
119### Running tests via Test Mapping with Atest
120
121It is possible to run tests via test mapping locally using Atest.
122
123To run all the tests declared in ART's `TEST_MAPPING` file, use the following
124command from the Android source tree top-level directory:
125```bash
126atest --test-mapping art:all
127```
128In the previous command, `art` is the (relative) path to the directory
129containing the `TEST_MAPPING` file listing the tests to run, while `all` means
130that tests declared in all [test
131groups](https://source.android.com/compatibility/tests/development/test-mapping#defining_test_groups)
132shall be run.
133
134To only run tests executed during pre-submit testing, use:
135```bash
136atest --test-mapping art:presubmit
137```
138
139To only run tests executed during post-submit testing, use:
140```bash
141atest --test-mapping art:postsubmit
142```