blob: 5d03c7820dde413166e515d069ef8ca298136a78 [file] [log] [blame] [view]
Roland Levillain450b27a2019-07-24 14:06:56 +01001# ART Chroot-Based On-Device Testing
2
3This file documents the use of a chroot environment in on-device testing of the
4Android Runtime (ART). Using a chroot allows tests to run a standalone ART from
5a locally built source tree on a device running (almost any) system image and
6does not interfere with the Runtime installed in the device's system partition.
7
8## Introduction
9
10The Android Runtime (ART) supports testing in a chroot-based environment, by
11setting up a chroot directory in a `ART_TEST_CHROOT` directory located under
12`/data/local` (e.g. `ART_TEST_CHROOT=/data/local/art-test-chroot`) on a device,
13installing ART and all other required artifacts there, and having tests use `adb
14shell chroot $ART_TEST_CHROOT <command>` to execute commands on the device
15within this environment.
16
17This way to run tests using a "standalone ART" ("guest system") only affects
18files in the data partition (the system partition and other partitions are left
19untouched) and is as independent as possible from the Android system ("host
20system") running on the device. This has some benefits:
21
22* no need to build and flash a whole device to do ART testing (or "overwriting"
Roland Levillainc3590fe2019-10-10 14:56:55 +010023 an existing ART by syncing the system partition);
24* the possibility to use a smaller AOSP Android manifest
25 ([`master-art`](https://android.googlesource.com/platform/manifest/+/refs/heads/master-art/default.xml))
26 to build ART and the required dependencies for testing;
Roland Levillain450b27a2019-07-24 14:06:56 +010027* no instability due to updating/replacing ART on the system partition (a
28 functional Android Runtime is necessary to properly boot a device);
29* the possibility to have several standalone ART instances (one per directory,
30 e.g. `/data/local/art-test-chroot1`, `/data/local/art-test-chroot2`, etc.).
31
32Note that using this chroot-based approach requires root access to the device
33(i.e. be able to run `adb root` successfully).
34
35## Quick User Guide
36
370. Unset variables which are not used with the chroot-based approach (if they
38 were set previously):
39 ```bash
40 unset ART_TEST_ANDROID_ROOT
41 unset CUSTOM_TARGET_LINKER
Martin Stjernholme58624f2019-09-20 15:53:40 +010042 unset ART_TEST_ANDROID_ART_ROOT
Roland Levillain450b27a2019-07-24 14:06:56 +010043 unset ART_TEST_ANDROID_RUNTIME_ROOT
Victor Chang1ba7fec2019-09-24 14:59:00 +010044 unset ART_TEST_ANDROID_I18N_ROOT
Roland Levillain450b27a2019-07-24 14:06:56 +010045 unset ART_TEST_ANDROID_TZDATA_ROOT
46 ```
471. Set the chroot directory in `ART_TEST_CHROOT`:
48 ```bash
49 export ART_TEST_CHROOT=/data/local/art-test-chroot
50 ```
512. Set lunch target and ADB:
52 * With a minimal `aosp/master-art` tree:
53 ```bash
54 export SOONG_ALLOW_MISSING_DEPENDENCIES=true
55 . ./build/envsetup.sh
56 lunch armv8-eng # or arm_krait-eng for 32-bit ARM
57 export PATH="$(pwd)/prebuilts/runtime:$PATH"
58 export ADB="$ANDROID_BUILD_TOP/prebuilts/runtime/adb"
59 ```
60 * With a full Android (AOSP) `aosp/master` tree:
61 ```bash
Roland Levillainbd5fb282019-10-04 14:26:03 +010062 export OVERRIDE_TARGET_FLATTEN_APEX=true
Roland Levillain450b27a2019-07-24 14:06:56 +010063 . ./build/envsetup.sh
64 lunch aosp_arm64-eng # or aosp_arm-eng for 32-bit ARM
Roland Levillaine47933a2019-08-09 14:06:02 +010065 m adb
Roland Levillain450b27a2019-07-24 14:06:56 +010066 ```
673. Build ART and required dependencies:
68 ```bash
Roland Levillain34848e72019-10-03 14:54:26 +010069 art/tools/buildbot-build.sh --target
Roland Levillain450b27a2019-07-24 14:06:56 +010070 ```
714. Clean up the device:
72 ```bash
Orion Hodson1c5b1ea2020-01-22 15:34:33 +000073 art/tools/buildbot-cleanup-device.sh
Roland Levillain450b27a2019-07-24 14:06:56 +010074 ```
Roland Levillainde54ddd2021-07-28 20:02:04 +0100755. Setup the device (including setting up mount points and files in the chroot
76 directory):
Roland Levillain450b27a2019-07-24 14:06:56 +010077 ```bash
Orion Hodson1c5b1ea2020-01-22 15:34:33 +000078 art/tools/buildbot-setup-device.sh
Roland Levillain450b27a2019-07-24 14:06:56 +010079 ```
806. Populate the chroot tree on the device (including "activating" APEX packages
81 in the chroot environment):
82 ```bash
83 art/tools/buildbot-sync.sh
84 ```
857. Run ART gtests:
86 ```bash
87 art/tools/run-gtests.sh -j4
88 ```
Roland Levillainde54ddd2021-07-28 20:02:04 +010089 * Specific tests to run can be passed on the command line, specified by
90 their absolute paths beginning with `/apex/`:
91 ```bash
92 art/tools/run-gtests.sh \
93 /apex/com.android.art/bin/art/arm64/art_cmdline_tests \
94 /apex/com.android.art/bin/art/arm64/art_dexdump_tests
95 ```
96 * Gtest options can be passed to each gtest by passing them after `--`; see
97 the following examples.
98 * To print the list of all test cases of a given gtest, use option
99 `--gtest_list_tests`:
100 ```bash
101 art/tools/run-gtests.sh \
102 /apex/com.android.art/bin/art/arm64/art_cmdline_tests \
103 -- --gtest_list_tests
104 ```
105 * To filter the test cases to execute, use option `--gtest_filter`:
106 ```bash
107 art/tools/run-gtests.sh \
108 /apex/com.android.art/bin/art/arm64/art_cmdline_tests \
109 -- --gtest_filter="*TestJdwp*"
110 ```
111 * To see all the options supported by a gtest, use option `--help`:
112 ```bash
113 art/tools/run-gtests.sh \
114 /apex/com.android.art/bin/art/arm64/art_cmdline_tests \
115 -- --help
116 ```
117 * Note: Some test cases of `art_runtime_tests` defined in
118 `art/runtime/gc/space/image_space_test.cc` may fail when using the full AOSP
Roland Levillain450b27a2019-07-24 14:06:56 +0100119 tree (b/119815008).
Roland Levillaine47933a2019-08-09 14:06:02 +0100120 * Workaround: Run `m clean-oat-host` before the build step
Roland Levillain34848e72019-10-03 14:54:26 +0100121 (`art/tools/buildbot-build.sh --target`) above.
Roland Levillainde54ddd2021-07-28 20:02:04 +0100122 * Note: The `-j` option of script `art/tools/run-gtests.sh` is not honored
123 yet (b/129930445). However, gtests themselves support parallel execution,
124 which can be specified via the gtest option `-j`:
125 ```bash
126 art/tools/run-gtests.sh -- -j4
127 ```
Roland Levillain450b27a2019-07-24 14:06:56 +01001288. Run ART run-tests:
129 * On a 64-bit target:
130 ```bash
131 art/test/testrunner/testrunner.py --target --64
132 ```
133 * On a 32-bit target:
134 ```bash
135 art/test/testrunner/testrunner.py --target --32
136 ```
1379. Run Libcore tests:
138 * On a 64-bit target:
139 ```bash
140 art/tools/run-libcore-tests.sh --mode=device --variant=X64
141 ```
142 * On a 32-bit target:
143 ```bash
144 art/tools/run-libcore-tests.sh --mode=device --variant=X32
145 ```
14610. Run JDWP tests:
147 * On a 64-bit target:
148 ```bash
Roland Levillain09c23c62020-02-24 13:08:24 +0000149 art/tools/run-libjdwp-tests.sh --mode=device --variant=X64
Roland Levillain450b27a2019-07-24 14:06:56 +0100150 ```
151 * On a 32-bit target:
152 ```bash
Roland Levillain09c23c62020-02-24 13:08:24 +0000153 art/tools/run-libjdwp-tests.sh --mode=device --variant=X32
Roland Levillain450b27a2019-07-24 14:06:56 +0100154 ```
15511. Tear down device setup:
156 ```bash
Orion Hodson1c5b1ea2020-01-22 15:34:33 +0000157 art/tools/buildbot-teardown-device.sh
Roland Levillain450b27a2019-07-24 14:06:56 +0100158 ```
15912. Clean up the device:
160 ```bash
Orion Hodson1c5b1ea2020-01-22 15:34:33 +0000161 art/tools/buildbot-cleanup-device.sh
Roland Levillain450b27a2019-07-24 14:06:56 +0100162 ```