Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 1 | # ART Testing |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 2 | |
Roland Levillain | c3590fe | 2019-10-10 14:56:55 +0100 | [diff] [blame] | 3 | There 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 Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 7 | |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 8 | ## ART run-tests |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 9 | |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 10 | ART run-tests are tests exercising the runtime using Dex bytecode. They are |
| 11 | written in Java and/or [Smali](https://github.com/JesusFreke/smali) |
| 12 | (compiled/assembled as Dex bytecode) and sometimes native code (written as C/C++ |
| 13 | testing 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 |
| 16 | executed on the ART runtime (`dalvikvm`), possibly preceded by a |
| 17 | pre-optimization of the Dex code (using `dex2oat`). |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 18 | |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 19 | The run-tests are identified by directories in this `test` directory, named with |
| 20 | a numeric prefix and containing an `info.txt` file. For most run tests, the |
| 21 | sources are in the `src` subdirectory. Sources found in the `src2` directory are |
| 22 | compiled separately but to the same output directory; this can be used to |
| 23 | exercise "API mismatch" situations by replacing class files created in the first |
| 24 | pass. The `src-ex` directory is built separately, and is intended for exercising |
| 25 | class loaders. Resources can be stored in the `res` directory, which is |
| 26 | distributed together with the executable files. |
| 27 | |
| 28 | The run-tests logic lives in the `test/run-test` Bash script. The execution of a |
| 29 | run-test has three main parts: building the test, running the test, and checking |
| 30 | the test's output. By default, these three steps are implemented by three Bash |
| 31 | scripts 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 | |
| 35 | The default logic for all of these these steps (build, run, check) is overridden |
| 36 | if 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 |
| 38 | is actually implemented in the "JAR runner" (`test/etc/run-test-jar`), invoked |
| 39 | by `test/etc/default-run`. |
| 40 | |
| 41 | After the execution of a run-test, the check step's default behavior |
Roland Levillain | 5464fc6 | 2020-11-10 15:54:58 +0000 | [diff] [blame] | 42 | (implemented in `test/etc/default-check`) is to respectively compare its |
| 43 | standard output and standard error with the contents of the |
| 44 | `expected-stdout.txt` and `expected-stderr.txt` files contained in the test's |
| 45 | directory; any mismatch triggers a test failure. |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 46 | |
| 47 | The `test/run-test` script handles the execution of a single run-test in a given |
| 48 | configuration. The Python script `test/testrunner/testrunner.py` is a convenient |
| 49 | script handling the construction and execution of multiple tests in one |
| 50 | configuration or more. |
| 51 | |
| 52 | To see the invocation options supported by `run-test` and `testrunner.py`, run |
| 53 | these commands from the Android source top-level directory: |
| 54 | ```sh |
| 55 | art/test/run-test --help |
| 56 | ``` |
| 57 | ```sh |
| 58 | art/test/testrunner/testrunner.py --help |
| 59 | ``` |
| 60 | |
| 61 | ## ART gtests |
| 62 | |
| 63 | ART gtests are written in C++ using the [Google |
| 64 | Test](https://github.com/google/googletest) framework. These tests exercise |
| 65 | various aspects of the runtime (the logic in `libart`, `libart-compiler`, etc.) |
| 66 | and its binaries (`dalvikvm`, `dex2oat`, `oatdump`, etc.). Some of them are used |
| 67 | as unit tests to verify a particular construct in ART. These tests may depend on |
| 68 | some test Dex files and core images. |
| 69 | |
| 70 | ART gtests are defined in various directories within the ART project (usually in |
| 71 | the same directory as the code they exercise). Their source files usually end |
Roland Levillain | c3590fe | 2019-10-10 14:56:55 +0100 | [diff] [blame] | 72 | with the suffix `_test.cc`. The construction logic of these tests is implemented |
| 73 | in ART's build system (`Android.bp` and `Android*.mk` files). On host, these |
| 74 | gtests can be run by executing `m test-art-host-gtest`. On device, the |
| 75 | recommended approach is to run these tests in a chroot environment (see |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 76 | `README.chroot.md` in this directory). |
| 77 | |
| 78 | |
| 79 | # Test execution |
| 80 | |
| 81 | All tests in either suite can be run using the `art/test.py` |
| 82 | script. Additionally, run-tests can be run individually. All of the tests can be |
| 83 | run on the build host, on a USB-attached device, or using the build host |
| 84 | "reference implementation". |
| 85 | |
| 86 | ART also supports running target (device) tests in a chroot environment (see |
| 87 | `README.chroot.md` in this directory). This is currently the recommended way to |
| 88 | run tests on target (rather than using `art/test.py --target`). |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 89 | |
| 90 | To see command flags run: |
| 91 | |
| 92 | ```sh |
| 93 | $ art/test.py -h |
| 94 | ``` |
| 95 | |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 96 | ## Building tests |
| 97 | |
| 98 | In general all tests require some dependencies to be built before they can be run. |
| 99 | In general you can pass the `--build-dependencies` flag (also available as short |
| 100 | option -b) to `art/test.py` program to automatically build required dependencies. |
| 101 | One can also directly use the various `test-art-...-dependencies` targets listed |
| 102 | below. |
| 103 | |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 104 | ## Running all tests on the build host |
| 105 | |
| 106 | ```sh |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 107 | $ # Build test files |
| 108 | $ m test-art-host-run-test-dependencies |
| 109 | $ # Run the tests |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 110 | $ art/test.py --host |
| 111 | ``` |
| 112 | |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 113 | Or: |
| 114 | |
| 115 | ``` |
| 116 | $ art/test.py -b --host |
| 117 | ``` |
| 118 | |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 119 | ## Running all tests on the target device |
| 120 | |
| 121 | ```sh |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 122 | $ # Build test files |
| 123 | $ m test-art-target-run-test-dependencies |
| 124 | $ # Run the tests |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 125 | $ art/test.py --target |
| 126 | ``` |
| 127 | |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 128 | Or: |
| 129 | |
| 130 | ``` |
| 131 | $ art/test.py -b --target |
| 132 | ``` |
| 133 | |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 134 | ## Running all gtests on the build host |
| 135 | |
| 136 | ```sh |
| 137 | $ art/test.py --host -g |
| 138 | ``` |
| 139 | |
| 140 | ## Running all gtests on the target device |
| 141 | |
| 142 | ```sh |
| 143 | $ art/test.py --target -g |
| 144 | ``` |
| 145 | |
| 146 | ## Running all run-tests on the build host |
| 147 | |
| 148 | ```sh |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 149 | $ # Build test files |
| 150 | $ m test-art-host-run-test-dependencies |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 151 | $ art/test.py --host -r |
| 152 | ``` |
| 153 | |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 154 | Or: |
| 155 | |
| 156 | ``` |
| 157 | $ art/test.py -b --host -r |
| 158 | ``` |
| 159 | |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 160 | ## Running all run-tests on the target device |
| 161 | |
| 162 | ```sh |
| 163 | $ art/test.py --target -r |
| 164 | ``` |
| 165 | |
| 166 | ## Running one run-test on the build host |
| 167 | |
| 168 | ```sh |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 169 | $ # Build test files |
| 170 | $ m test-art-host-run-test-dependencies |
| 171 | $ # Run the tests |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 172 | $ art/test.py --host -r -t 001-HelloWorld |
| 173 | ``` |
| 174 | |
Alex Light | 8b2f7e6 | 2020-10-26 20:45:49 +0000 | [diff] [blame] | 175 | Or: |
| 176 | |
| 177 | ``` |
| 178 | $ art/test.py -b --host -r -t 001-HelloWorld |
| 179 | ``` |
| 180 | |
Orion Hodson | 42f1658 | 2017-07-12 11:55:22 +0100 | [diff] [blame] | 181 | ## Running one run-test on the target device |
| 182 | |
| 183 | ```sh |
| 184 | $ art/test.py --target -r -t 001-HelloWorld |
| 185 | ``` |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 186 | |
David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 187 | ## Running one gtest on the build host |
| 188 | |
| 189 | ```sh |
| 190 | $ find out/host/ -type f -name art_runtime_tests # Find the path of the test. |
| 191 | $ out/host/linux-x86/nativetest/art_runtime_tests/art_runtime_tests |
| 192 | ``` |
| 193 | |
| 194 | Add "--no_isolate" to run the tests one by one in single process (disable forking). |
| 195 | Add "--gtest_filter=..." to select specific sub-test(s) to run. |
| 196 | Prefix by "gdb --args " to run the test in gdb. |
Roland Levillain | f1bb75a | 2019-08-12 15:03:55 +0100 | [diff] [blame] | 197 | |
| 198 | # ART Continuous Integration |
| 199 | |
| 200 | Both ART run-tests and gtests are run continuously as part of [ART's continuous |
| 201 | integration](https://ci.chromium.org/p/art/g/luci/console). In addition, two |
| 202 | other test suites are run continuously on this service: Libcore tests and JDWP |
| 203 | tests. |