| Roland Levillain | 450b27a | 2019-07-24 14:06:56 +0100 | [diff] [blame] | 1 | # ART Chroot-Based On-Device Testing |
| 2 | |
| 3 | This file documents the use of a chroot environment in on-device testing of the |
| 4 | Android Runtime (ART). Using a chroot allows tests to run a standalone ART from |
| 5 | a locally built source tree on a device running (almost any) system image and |
| 6 | does not interfere with the Runtime installed in the device's system partition. |
| 7 | |
| 8 | ## Introduction |
| 9 | |
| 10 | The Android Runtime (ART) supports testing in a chroot-based environment, by |
| 11 | setting 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, |
| 13 | installing ART and all other required artifacts there, and having tests use `adb |
| 14 | shell chroot $ART_TEST_CHROOT <command>` to execute commands on the device |
| 15 | within this environment. |
| 16 | |
| 17 | This way to run tests using a "standalone ART" ("guest system") only affects |
| 18 | files in the data partition (the system partition and other partitions are left |
| 19 | untouched) and is as independent as possible from the Android system ("host |
| 20 | system") 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" |
| 23 | and existing ART by syncing the system partition); |
| 24 | * the possibility to use a smaller AOSP Android manifest (`master-art`) to build |
| 25 | ART and the required dependencies for testing; |
| 26 | * no instability due to updating/replacing ART on the system partition (a |
| 27 | functional Android Runtime is necessary to properly boot a device); |
| 28 | * the possibility to have several standalone ART instances (one per directory, |
| 29 | e.g. `/data/local/art-test-chroot1`, `/data/local/art-test-chroot2`, etc.). |
| 30 | |
| 31 | Note that using this chroot-based approach requires root access to the device |
| 32 | (i.e. be able to run `adb root` successfully). |
| 33 | |
| 34 | ## Quick User Guide |
| 35 | |
| 36 | 0. Unset variables which are not used with the chroot-based approach (if they |
| 37 | were set previously): |
| 38 | ```bash |
| 39 | unset ART_TEST_ANDROID_ROOT |
| 40 | unset CUSTOM_TARGET_LINKER |
| 41 | unset ART_TEST_ANDROID_RUNTIME_ROOT |
| 42 | unset ART_TEST_ANDROID_TZDATA_ROOT |
| 43 | ``` |
| 44 | 1. Set the chroot directory in `ART_TEST_CHROOT`: |
| 45 | ```bash |
| 46 | export ART_TEST_CHROOT=/data/local/art-test-chroot |
| 47 | ``` |
| 48 | 2. Set lunch target and ADB: |
| 49 | * With a minimal `aosp/master-art` tree: |
| 50 | ```bash |
| 51 | export SOONG_ALLOW_MISSING_DEPENDENCIES=true |
| 52 | . ./build/envsetup.sh |
| 53 | lunch armv8-eng # or arm_krait-eng for 32-bit ARM |
| 54 | export PATH="$(pwd)/prebuilts/runtime:$PATH" |
| 55 | export ADB="$ANDROID_BUILD_TOP/prebuilts/runtime/adb" |
| 56 | ``` |
| 57 | * With a full Android (AOSP) `aosp/master` tree: |
| 58 | ```bash |
| 59 | . ./build/envsetup.sh |
| 60 | lunch aosp_arm64-eng # or aosp_arm-eng for 32-bit ARM |
| Roland Levillain | e47933a | 2019-08-09 14:06:02 +0100 | [diff] [blame] | 61 | m adb |
| Roland Levillain | 450b27a | 2019-07-24 14:06:56 +0100 | [diff] [blame] | 62 | ``` |
| 63 | 3. Build ART and required dependencies: |
| 64 | ```bash |
| 65 | art/tools/buildbot-build.sh --target -j40 |
| 66 | ``` |
| 67 | 4. Clean up the device: |
| 68 | ```bash |
| 69 | art/tools/cleanup-buildbot-device.sh |
| 70 | ``` |
| 71 | 5. Setup the device (including setting up mount points and files in the chroot directory): |
| 72 | ```bash |
| 73 | art/tools/setup-buildbot-device.sh |
| 74 | ``` |
| 75 | 6. Populate the chroot tree on the device (including "activating" APEX packages |
| 76 | in the chroot environment): |
| 77 | ```bash |
| 78 | art/tools/buildbot-sync.sh |
| 79 | ``` |
| 80 | 7. Run ART gtests: |
| 81 | ```bash |
| 82 | art/tools/run-gtests.sh -j4 |
| 83 | ``` |
| 84 | * Note: This currently fails on test |
| 85 | `test-art-target-gtest-image_space_test{32,64}` when using the full AOSP |
| 86 | tree (b/119815008). |
| Roland Levillain | e47933a | 2019-08-09 14:06:02 +0100 | [diff] [blame] | 87 | * Workaround: Run `m clean-oat-host` before the build step |
| Roland Levillain | 450b27a | 2019-07-24 14:06:56 +0100 | [diff] [blame] | 88 | (`art/tools/buildbot-build.sh --target -j40`) above. |
| 89 | * Note: The `-j` option is not honored yet (b/129930445). |
| Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 90 | * Specific tests to run can be passed on the command line, specified by |
| 91 | their absolute paths beginning with "/apex/". |
| Roland Levillain | 450b27a | 2019-07-24 14:06:56 +0100 | [diff] [blame] | 92 | 8. Run ART run-tests: |
| 93 | * On a 64-bit target: |
| 94 | ```bash |
| 95 | art/test/testrunner/testrunner.py --target --64 |
| 96 | ``` |
| 97 | * On a 32-bit target: |
| 98 | ```bash |
| 99 | art/test/testrunner/testrunner.py --target --32 |
| 100 | ``` |
| 101 | 9. Run Libcore tests: |
| 102 | * On a 64-bit target: |
| 103 | ```bash |
| 104 | art/tools/run-libcore-tests.sh --mode=device --variant=X64 |
| 105 | ``` |
| 106 | * On a 32-bit target: |
| 107 | ```bash |
| 108 | art/tools/run-libcore-tests.sh --mode=device --variant=X32 |
| 109 | ``` |
| 110 | 10. Run JDWP tests: |
| 111 | * On a 64-bit target: |
| 112 | ```bash |
| 113 | art/tools/run-jdwp-tests.sh --mode=device --variant=X64 |
| 114 | ``` |
| 115 | * On a 32-bit target: |
| 116 | ```bash |
| 117 | art/tools/run-jdwp-tests.sh --mode=device --variant=X32 |
| 118 | ``` |
| 119 | 11. Tear down device setup: |
| 120 | ```bash |
| 121 | art/tools/teardown-buildbot-device.sh |
| 122 | ``` |
| 123 | 12. Clean up the device: |
| 124 | ```bash |
| 125 | art/tools/cleanup-buildbot-device.sh |
| 126 | ``` |