blob: 21064c1739a6ca98cb5a52d670bc3e2e8721b213 [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
Martin Stjernholm05b00862019-08-14 17:47:23 +010019if [[ $1 = -h ]]; then
20 cat <<EOF
Roland Levillainde54ddd2021-07-28 20:02:04 +010021Usage: $0 [<gtest>...] [--] [<gtest-option>...]
22
Martin Stjernholm05b00862019-08-14 17:47:23 +010023Script to run gtests located in the ART (Testing) APEX.
24
25If called with arguments, only those tests are run, as specified by their
26absolute paths (starting with /apex). All gtests are run otherwise.
Roland Levillainde54ddd2021-07-28 20:02:04 +010027
28Options after \`--\` are passed verbatim to each gtest binary.
Martin Stjernholm05b00862019-08-14 17:47:23 +010029EOF
30 exit
31fi
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +000032
Roland Levillain72f67742019-03-06 15:48:08 +000033if [[ -z "$ART_TEST_CHROOT" ]]; then
34 echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.'
35 exit 1
36fi
37
Roland Levillain70b93ff2019-07-02 19:48:50 +010038adb="${ADB:-adb}"
39
Victor Chang64611242019-07-05 16:32:41 +010040android_i18n_root=/apex/com.android.i18n
Martin Stjernholme58624f2019-09-20 15:53:40 +010041android_art_root=/apex/com.android.art
Roland Levillain70b93ff2019-07-02 19:48:50 +010042android_tzdata_root=/apex/com.android.tzdata
43
Martin Stjernholm05b00862019-08-14 17:47:23 +010044if [[ $1 = -j* ]]; then
45 # TODO(b/129930445): Implement support for parallel execution.
46 shift
47fi
48
Roland Levillainde54ddd2021-07-28 20:02:04 +010049tests=()
50
51while [[ $# -gt 0 ]]; do
52 if [[ "$1" == "--" ]]; then
53 shift
54 break
55 fi
56 tests+=("$1")
57 shift
58done
59
60options="$@"
61
62if [[ ${#tests[@]} -eq 0 ]]; then
Martin Stjernholm05b00862019-08-14 17:47:23 +010063 # Search for executables under the `bin/art` directory of the ART APEX.
Roland Levillainde54ddd2021-07-28 20:02:04 +010064 readarray -t tests <<<$("$adb" shell chroot "$ART_TEST_CHROOT" \
Martin Stjernholme58624f2019-09-20 15:53:40 +010065 find "$android_art_root/bin/art" -type f -perm /ugo+x | sort)
Martin Stjernholm05b00862019-08-14 17:47:23 +010066fi
Roland Levillain70b93ff2019-07-02 19:48:50 +010067
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +000068failing_tests=()
69
Roland Levillainde54ddd2021-07-28 20:02:04 +010070for t in ${tests[@]}; do
Roland Levillain70b93ff2019-07-02 19:48:50 +010071 echo "$t"
72 "$adb" shell chroot "$ART_TEST_CHROOT" \
Martin Stjernholme58624f2019-09-20 15:53:40 +010073 env ANDROID_ART_ROOT="$android_art_root" \
74 ANDROID_I18N_ROOT="$android_i18n_root" \
75 ANDROID_TZDATA_ROOT="$android_tzdata_root" \
Roland Levillainde54ddd2021-07-28 20:02:04 +010076 $t $options \
Roland Levillain70b93ff2019-07-02 19:48:50 +010077 || failing_tests+=("$t")
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +000078done
79
Roland Levillainde54ddd2021-07-28 20:02:04 +010080if [[ -n "$failing_tests" ]]; then
Roland Levillain70b93ff2019-07-02 19:48:50 +010081 for t in "${failing_tests[@]}"; do
82 echo "Failed test: $t"
Nicolas Geoffray5b93aef2019-01-21 13:44:58 +000083 done
84 exit 1
85fi