blob: acc5c8a2ed8eb108b0abf3b83b069f5ed0e5a7a2 [file] [log] [blame]
Roland Levillain72f67742019-03-06 15:48:08 +00001#! /bin/bash
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +00002#
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 Levillainde54ddd2021-07-28 20:02:04 +010017set -e
18
Ulya Trofimovich7b74ddc2024-09-25 19:16:27 +000019. "$(dirname $0)/buildbot-utils.sh"
20
Martin Stjernholm05b00862019-08-14 17:47:23 +010021if [[ $1 = -h ]]; then
22 cat <<EOF
Roland Levillainde54ddd2021-07-28 20:02:04 +010023Usage: $0 [<gtest>...] [--] [<gtest-option>...]
24
Martin Stjernholm05b00862019-08-14 17:47:23 +010025Script to run gtests located in the ART (Testing) APEX.
26
27If called with arguments, only those tests are run, as specified by their
28absolute paths (starting with /apex). All gtests are run otherwise.
Roland Levillainde54ddd2021-07-28 20:02:04 +010029
30Options after \`--\` are passed verbatim to each gtest binary.
Martin Stjernholm05b00862019-08-14 17:47:23 +010031EOF
32 exit
33fi
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +000034
Roland Levillain72f67742019-03-06 15:48:08 +000035if [[ -z "$ART_TEST_CHROOT" ]]; then
36 echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.'
37 exit 1
38fi
39
Roland Levillain70b93ff2019-07-02 19:48:50 +010040adb="${ADB:-adb}"
41
Victor Chang64611242019-07-05 16:32:41 +010042android_i18n_root=/apex/com.android.i18n
Martin Stjernholme58624f2019-09-20 15:53:40 +010043android_art_root=/apex/com.android.art
Roland Levillain70b93ff2019-07-02 19:48:50 +010044android_tzdata_root=/apex/com.android.tzdata
45
Martin Stjernholm05b00862019-08-14 17:47:23 +010046if [[ $1 = -j* ]]; then
47 # TODO(b/129930445): Implement support for parallel execution.
48 shift
49fi
50
Roland Levillainde54ddd2021-07-28 20:02:04 +010051tests=()
52
53while [[ $# -gt 0 ]]; do
54 if [[ "$1" == "--" ]]; then
55 shift
56 break
57 fi
58 tests+=("$1")
59 shift
60done
61
62options="$@"
63
Ulya Trafimovich513801a2023-01-19 18:26:43 +000064run_in_chroot() {
Vladimir Marko98103b02023-02-27 18:24:00 +010065 if [ -n "$ART_TEST_ON_VM" ]; then
Ulya Trafimovich01e6b562023-01-17 13:13:55 +000066 $ART_SSH_CMD $ART_CHROOT_CMD env ANDROID_ROOT=/system $@
Ulya Trafimovich513801a2023-01-19 18:26:43 +000067 else
68 "$adb" shell chroot "$ART_TEST_CHROOT" $@
69 fi
70}
71
Roland Levillainde54ddd2021-07-28 20:02:04 +010072if [[ ${#tests[@]} -eq 0 ]]; then
Martin Stjernholm05b00862019-08-14 17:47:23 +010073 # Search for executables under the `bin/art` directory of the ART APEX.
Ulya Trafimovich513801a2023-01-19 18:26:43 +000074 readarray -t tests <<<$(run_in_chroot \
Martin Stjernholme58624f2019-09-20 15:53:40 +010075 find "$android_art_root/bin/art" -type f -perm /ugo+x | sort)
Martin Stjernholm05b00862019-08-14 17:47:23 +010076fi
Roland Levillain70b93ff2019-07-02 19:48:50 +010077
Jiakai Zhange1ac4dc2023-03-03 10:38:34 +000078maybe_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 Geoffray5b93aef2019-01-21 13:44:58 +000096failing_tests=()
97
Roland Levillainde54ddd2021-07-28 20:02:04 +010098for t in ${tests[@]}; do
Roland Levillain70b93ff2019-07-02 19:48:50 +010099 echo "$t"
Ulya Trafimovich513801a2023-01-19 18:26:43 +0000100 run_in_chroot \
Martin Stjernholme58624f2019-09-20 15:53:40 +0100101 env ANDROID_ART_ROOT="$android_art_root" \
102 ANDROID_I18N_ROOT="$android_i18n_root" \
103 ANDROID_TZDATA_ROOT="$android_tzdata_root" \
Ulya Trofimovich8d24de72024-10-03 08:15:33 +0000104 ART_TEST_ON_VM="$ART_TEST_ON_VM" \
Jiakai Zhange1ac4dc2023-03-03 10:38:34 +0000105 $(maybe_get_fake_dex2oatbootclasspath) \
Roland Levillainde54ddd2021-07-28 20:02:04 +0100106 $t $options \
Roland Levillain70b93ff2019-07-02 19:48:50 +0100107 || failing_tests+=("$t")
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +0000108done
109
Roland Levillainde54ddd2021-07-28 20:02:04 +0100110if [[ -n "$failing_tests" ]]; then
Roland Levillain70b93ff2019-07-02 19:48:50 +0100111 for t in "${failing_tests[@]}"; do
112 echo "Failed test: $t"
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +0000113 done
114 exit 1
115fi