blob: da9a1f1f9083ab2b07c636be04e6526bafddbf71 [file] [log] [blame] [view]
Roland Levillainf1bb75a2019-08-12 15:03:55 +01001# ART Testing
Orion Hodson42f16582017-07-12 11:55:22 +01002
Roland Levillainc3590fe2019-10-10 14:56:55 +01003There are two suites of tests in the Android Runtime (ART):
4* _ART run-tests_: Tests of the ART runtime using Dex bytecode (mostly written
5 in Java).
6* _ART gtests_: C++ tests exercising various aspects of ART.
Orion Hodson42f16582017-07-12 11:55:22 +01007
Roland Levillainf1bb75a2019-08-12 15:03:55 +01008## ART run-tests
Orion Hodson42f16582017-07-12 11:55:22 +01009
Roland Levillainf1bb75a2019-08-12 15:03:55 +010010ART run-tests are tests exercising the runtime using Dex bytecode. They are
11written in Java and/or [Smali](https://github.com/JesusFreke/smali)
12(compiled/assembled as Dex bytecode) and sometimes native code (written as C/C++
13testing libraries). Some tests also make use of the
14[Jasmin](http://jasmin.sourceforge.net/) assembler or the
15[ASM](https://asm.ow2.io/) bytecode manipulation tool. Run-tests are
16executed on the ART runtime (`dalvikvm`), possibly preceded by a
17pre-optimization of the Dex code (using `dex2oat`).
Orion Hodson42f16582017-07-12 11:55:22 +010018
Roland Levillainf1bb75a2019-08-12 15:03:55 +010019The run-tests are identified by directories in this `test` directory, named with
20a numeric prefix and containing an `info.txt` file. For most run tests, the
21sources are in the `src` subdirectory. Sources found in the `src2` directory are
22compiled separately but to the same output directory; this can be used to
23exercise "API mismatch" situations by replacing class files created in the first
24pass. The `src-ex` directory is built separately, and is intended for exercising
25class loaders. Resources can be stored in the `res` directory, which is
26distributed together with the executable files.
27
28The run-tests logic lives in the `test/run-test` Bash script. The execution of a
29run-test has three main parts: building the test, running the test, and checking
30the test's output. By default, these three steps are implemented by three Bash
31scripts located in the `test/etc` directory (`default-build`, `default-run`, and
32`default-check`). These scripts rely on environment variables set by
33`test/run-test`.
34
35The default logic for all of these these steps (build, run, check) is overridden
36if the test's directory contains a Bash script named after the step
37(i.e. `build`, `run`, or `check`). Note that the default logic of the "run" step
38is actually implemented in the "JAR runner" (`test/etc/run-test-jar`), invoked
39by `test/etc/default-run`.
40
41After the execution of a run-test, the check step's default behavior
Roland Levillain5464fc62020-11-10 15:54:58 +000042(implemented in `test/etc/default-check`) is to respectively compare its
43standard output and standard error with the contents of the
44`expected-stdout.txt` and `expected-stderr.txt` files contained in the test's
45directory; any mismatch triggers a test failure.
Roland Levillainf1bb75a2019-08-12 15:03:55 +010046
47The `test/run-test` script handles the execution of a single run-test in a given
48configuration. The Python script `test/testrunner/testrunner.py` is a convenient
49script handling the construction and execution of multiple tests in one
50configuration or more.
51
52To see the invocation options supported by `run-test` and `testrunner.py`, run
53these commands from the Android source top-level directory:
54```sh
55art/test/run-test --help
56```
57```sh
58art/test/testrunner/testrunner.py --help
59```
60
Roland Levillaind6576ef2021-09-07 14:51:24 +010061### Checker tests
62
63Some ART run-tests, known as "Checker tests", perform additional checks on ART's
64compiler. They are identified by their name, which match the
65`^[0-9]+-checker-.*` regular expression (e.g. `004-checker-UnsafeTest18`).
66
67Checker assertions are annotations in a run-test's (Java and Smali) source files
68verifying the behavior of the ART compiler when compiling the corresponding Dex
69code. They are checked by the `checker` tool (see [directory
70`art/tools/checker`](https://cs.android.com/android/platform/superproject/+/master:art/tools/checker/))
71against a c1visualizer-style (`.cfg`) file emitted by `dex2oat`, containing
72control-flow graphs (CFGs) for compiled methods at each step (pass) in the
73compiler's pipeline, as well as the emitted assembly code.
74
Roland Levillainf1bb75a2019-08-12 15:03:55 +010075## ART gtests
76
77ART gtests are written in C++ using the [Google
78Test](https://github.com/google/googletest) framework. These tests exercise
79various aspects of the runtime (the logic in `libart`, `libart-compiler`, etc.)
80and its binaries (`dalvikvm`, `dex2oat`, `oatdump`, etc.). Some of them are used
81as unit tests to verify a particular construct in ART. These tests may depend on
82some test Dex files and core images.
83
84ART gtests are defined in various directories within the ART project (usually in
85the same directory as the code they exercise). Their source files usually end
Roland Levillainc3590fe2019-10-10 14:56:55 +010086with the suffix `_test.cc`. The construction logic of these tests is implemented
87in ART's build system (`Android.bp` and `Android*.mk` files). On host, these
88gtests can be run by executing `m test-art-host-gtest`. On device, the
89recommended approach is to run these tests in a chroot environment (see
Roland Levillainf1bb75a2019-08-12 15:03:55 +010090`README.chroot.md` in this directory).
91
92
93# Test execution
94
95All tests in either suite can be run using the `art/test.py`
96script. Additionally, run-tests can be run individually. All of the tests can be
97run on the build host, on a USB-attached device, or using the build host
98"reference implementation".
99
100ART also supports running target (device) tests in a chroot environment (see
101`README.chroot.md` in this directory). This is currently the recommended way to
102run tests on target (rather than using `art/test.py --target`).
Orion Hodson42f16582017-07-12 11:55:22 +0100103
104To see command flags run:
105
106```sh
107$ art/test.py -h
108```
109
Alex Light8b2f7e62020-10-26 20:45:49 +0000110## Building tests
111
112In general all tests require some dependencies to be built before they can be run.
113In general you can pass the `--build-dependencies` flag (also available as short
114option -b) to `art/test.py` program to automatically build required dependencies.
115One can also directly use the various `test-art-...-dependencies` targets listed
116below.
117
Orion Hodson42f16582017-07-12 11:55:22 +0100118## Running all tests on the build host
119
120```sh
Alex Light8b2f7e62020-10-26 20:45:49 +0000121$ # Build test files
122$ m test-art-host-run-test-dependencies
123$ # Run the tests
Orion Hodson42f16582017-07-12 11:55:22 +0100124$ art/test.py --host
125```
126
Alex Light8b2f7e62020-10-26 20:45:49 +0000127Or:
128
129```
130$ art/test.py -b --host
131```
132
Orion Hodson42f16582017-07-12 11:55:22 +0100133## Running all tests on the target device
134
135```sh
Alex Light8b2f7e62020-10-26 20:45:49 +0000136$ # Build test files
137$ m test-art-target-run-test-dependencies
138$ # Run the tests
Orion Hodson42f16582017-07-12 11:55:22 +0100139$ art/test.py --target
140```
141
Alex Light8b2f7e62020-10-26 20:45:49 +0000142Or:
143
144```
145$ art/test.py -b --target
146```
147
Orion Hodson42f16582017-07-12 11:55:22 +0100148## Running all gtests on the build host
149
150```sh
151$ art/test.py --host -g
152```
153
154## Running all gtests on the target device
155
156```sh
157$ art/test.py --target -g
158```
159
160## Running all run-tests on the build host
161
162```sh
Alex Light8b2f7e62020-10-26 20:45:49 +0000163$ # Build test files
164$ m test-art-host-run-test-dependencies
Orion Hodson42f16582017-07-12 11:55:22 +0100165$ art/test.py --host -r
166```
167
Alex Light8b2f7e62020-10-26 20:45:49 +0000168Or:
169
170```
171$ art/test.py -b --host -r
172```
173
Orion Hodson42f16582017-07-12 11:55:22 +0100174## Running all run-tests on the target device
175
176```sh
177$ art/test.py --target -r
178```
179
180## Running one run-test on the build host
181
182```sh
Alex Light8b2f7e62020-10-26 20:45:49 +0000183$ # Build test files
184$ m test-art-host-run-test-dependencies
185$ # Run the tests
Orion Hodson42f16582017-07-12 11:55:22 +0100186$ art/test.py --host -r -t 001-HelloWorld
187```
188
Alex Light8b2f7e62020-10-26 20:45:49 +0000189Or:
190
191```
192$ art/test.py -b --host -r -t 001-HelloWorld
193```
194
Orion Hodson42f16582017-07-12 11:55:22 +0100195## Running one run-test on the target device
196
197```sh
198$ art/test.py --target -r -t 001-HelloWorld
199```
Roland Levillainf1bb75a2019-08-12 15:03:55 +0100200
David Srbecky7400a542020-07-09 13:40:57 +0100201## Running one gtest on the build host
202
203```sh
204$ find out/host/ -type f -name art_runtime_tests # Find the path of the test.
205$ out/host/linux-x86/nativetest/art_runtime_tests/art_runtime_tests
206```
207
208Add "--no_isolate" to run the tests one by one in single process (disable forking).
209Add "--gtest_filter=..." to select specific sub-test(s) to run.
210Prefix by "gdb --args " to run the test in gdb.
Roland Levillainf1bb75a2019-08-12 15:03:55 +0100211
212# ART Continuous Integration
213
214Both ART run-tests and gtests are run continuously as part of [ART's continuous
215integration](https://ci.chromium.org/p/art/g/luci/console). In addition, two
216other test suites are run continuously on this service: Libcore tests and JDWP
217tests.