Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1 | #! /bin/bash |
Nicolas Geoffray | 5b93aef | 2019-01-21 13:44:58 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2019 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 17 | set -e |
| 18 | |
Ulya Trofimovich | 7b74ddc | 2024-09-25 19:16:27 +0000 | [diff] [blame] | 19 | . "$(dirname $0)/buildbot-utils.sh" |
| 20 | |
Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 21 | if [[ $1 = -h ]]; then |
| 22 | cat <<EOF |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 23 | Usage: $0 [<gtest>...] [--] [<gtest-option>...] |
| 24 | |
Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 25 | Script to run gtests located in the ART (Testing) APEX. |
| 26 | |
| 27 | If called with arguments, only those tests are run, as specified by their |
| 28 | absolute paths (starting with /apex). All gtests are run otherwise. |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 29 | |
| 30 | Options after \`--\` are passed verbatim to each gtest binary. |
Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 31 | EOF |
| 32 | exit |
| 33 | fi |
Nicolas Geoffray | 5b93aef | 2019-01-21 13:44:58 +0000 | [diff] [blame] | 34 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 35 | if [[ -z "$ART_TEST_CHROOT" ]]; then |
| 36 | echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.' |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
Roland Levillain | 70b93ff | 2019-07-02 19:48:50 +0100 | [diff] [blame] | 40 | adb="${ADB:-adb}" |
| 41 | |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 42 | android_i18n_root=/apex/com.android.i18n |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 43 | android_art_root=/apex/com.android.art |
Roland Levillain | 70b93ff | 2019-07-02 19:48:50 +0100 | [diff] [blame] | 44 | android_tzdata_root=/apex/com.android.tzdata |
| 45 | |
Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 46 | if [[ $1 = -j* ]]; then |
| 47 | # TODO(b/129930445): Implement support for parallel execution. |
| 48 | shift |
| 49 | fi |
| 50 | |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 51 | tests=() |
| 52 | |
| 53 | while [[ $# -gt 0 ]]; do |
| 54 | if [[ "$1" == "--" ]]; then |
| 55 | shift |
| 56 | break |
| 57 | fi |
| 58 | tests+=("$1") |
| 59 | shift |
| 60 | done |
| 61 | |
| 62 | options="$@" |
| 63 | |
Ulya Trafimovich | 513801a | 2023-01-19 18:26:43 +0000 | [diff] [blame] | 64 | run_in_chroot() { |
Vladimir Marko | 98103b0 | 2023-02-27 18:24:00 +0100 | [diff] [blame] | 65 | if [ -n "$ART_TEST_ON_VM" ]; then |
Ulya Trafimovich | 01e6b56 | 2023-01-17 13:13:55 +0000 | [diff] [blame] | 66 | $ART_SSH_CMD $ART_CHROOT_CMD env ANDROID_ROOT=/system $@ |
Ulya Trafimovich | 513801a | 2023-01-19 18:26:43 +0000 | [diff] [blame] | 67 | else |
| 68 | "$adb" shell chroot "$ART_TEST_CHROOT" $@ |
| 69 | fi |
| 70 | } |
| 71 | |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 72 | if [[ ${#tests[@]} -eq 0 ]]; then |
Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 73 | # Search for executables under the `bin/art` directory of the ART APEX. |
Ulya Trafimovich | 513801a | 2023-01-19 18:26:43 +0000 | [diff] [blame] | 74 | readarray -t tests <<<$(run_in_chroot \ |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 75 | find "$android_art_root/bin/art" -type f -perm /ugo+x | sort) |
Martin Stjernholm | 05b0086 | 2019-08-14 17:47:23 +0100 | [diff] [blame] | 76 | fi |
Roland Levillain | 70b93ff | 2019-07-02 19:48:50 +0100 | [diff] [blame] | 77 | |
Jiakai Zhang | e1ac4dc | 2023-03-03 10:38:34 +0000 | [diff] [blame] | 78 | maybe_get_fake_dex2oatbootclasspath() { |
| 79 | if [ -n "$ART_TEST_ON_VM" ]; then |
| 80 | return |
| 81 | fi |
| 82 | dex2oatbootclasspath=$("$adb" shell echo \$DEX2OATBOOTCLASSPATH) |
| 83 | if [ -n "$dex2oatbootclasspath" ]; then |
| 84 | # The device has a real DEX2OATBOOTCLASSPATH. |
| 85 | # This is the usual case. |
| 86 | return |
| 87 | fi |
| 88 | bootclasspath=$("$adb" shell echo \$BOOTCLASSPATH) |
| 89 | # Construct a fake DEX2OATBOOTCLASSPATH from the elements in BOOTCLASSPATH except the last one. |
| 90 | # BOOTCLASSPATH cannot be used by the runtime in chroot anyway, so it doesn't hurt to construct a |
| 91 | # fake DEX2OATBOOTCLASSPATH just to make the runtime happy. |
| 92 | # This is only needed on old Android platforms such as Android P. |
| 93 | echo "DEX2OATBOOTCLASSPATH=${bootclasspath%:*}" |
| 94 | } |
| 95 | |
Nicolas Geoffray | 5b93aef | 2019-01-21 13:44:58 +0000 | [diff] [blame] | 96 | failing_tests=() |
| 97 | |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 98 | for t in ${tests[@]}; do |
Roland Levillain | 70b93ff | 2019-07-02 19:48:50 +0100 | [diff] [blame] | 99 | echo "$t" |
Ulya Trafimovich | 513801a | 2023-01-19 18:26:43 +0000 | [diff] [blame] | 100 | run_in_chroot \ |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 101 | env ANDROID_ART_ROOT="$android_art_root" \ |
| 102 | ANDROID_I18N_ROOT="$android_i18n_root" \ |
| 103 | ANDROID_TZDATA_ROOT="$android_tzdata_root" \ |
Ulya Trofimovich | 8d24de7 | 2024-10-03 08:15:33 +0000 | [diff] [blame] | 104 | ART_TEST_ON_VM="$ART_TEST_ON_VM" \ |
Jiakai Zhang | e1ac4dc | 2023-03-03 10:38:34 +0000 | [diff] [blame] | 105 | $(maybe_get_fake_dex2oatbootclasspath) \ |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 106 | $t $options \ |
Roland Levillain | 70b93ff | 2019-07-02 19:48:50 +0100 | [diff] [blame] | 107 | || failing_tests+=("$t") |
Nicolas Geoffray | 5b93aef | 2019-01-21 13:44:58 +0000 | [diff] [blame] | 108 | done |
| 109 | |
Roland Levillain | de54ddd | 2021-07-28 20:02:04 +0100 | [diff] [blame] | 110 | if [[ -n "$failing_tests" ]]; then |
Roland Levillain | 70b93ff | 2019-07-02 19:48:50 +0100 | [diff] [blame] | 111 | for t in "${failing_tests[@]}"; do |
| 112 | echo "Failed test: $t" |
Nicolas Geoffray | 5b93aef | 2019-01-21 13:44:58 +0000 | [diff] [blame] | 113 | done |
| 114 | exit 1 |
| 115 | fi |