1#! /bin/bash 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 17set -e 18 19. "$(dirname $0)/buildbot-utils.sh" 20 21if [[ $1 = -h ]]; then 22 cat <<EOF 23Usage: $0 [<gtest>...] [--] [<gtest-option>...] 24 25Script 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. 29 30Options after \`--\` are passed verbatim to each gtest binary. 31EOF 32 exit 33fi 34 35if [[ -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 40adb="${ADB:-adb}" 41 42android_i18n_root=/apex/com.android.i18n 43android_art_root=/apex/com.android.art 44android_tzdata_root=/apex/com.android.tzdata 45 46if [[ $1 = -j* ]]; then 47 # TODO(b/129930445): Implement support for parallel execution. 48 shift 49fi 50 51tests=() 52 53while [[ $# -gt 0 ]]; do 54 if [[ "$1" == "--" ]]; then 55 shift 56 break 57 fi 58 tests+=("$1") 59 shift 60done 61 62options="$@" 63 64run_in_chroot() { 65 if [ -n "$ART_TEST_ON_VM" ]; then 66 $ART_SSH_CMD $ART_CHROOT_CMD env ANDROID_ROOT=/system $@ 67 else 68 "$adb" shell chroot "$ART_TEST_CHROOT" $@ 69 fi 70} 71 72if [[ ${#tests[@]} -eq 0 ]]; then 73 # Search for executables under the `bin/art` directory of the ART APEX. 74 readarray -t tests <<<$(run_in_chroot \ 75 find "$android_art_root/bin/art" -type f -perm /ugo+x | sort) 76fi 77 78maybe_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 96failing_tests=() 97 98for t in ${tests[@]}; do 99 echo "$t" 100 run_in_chroot \ 101 env ANDROID_ART_ROOT="$android_art_root" \ 102 ANDROID_I18N_ROOT="$android_i18n_root" \ 103 ANDROID_TZDATA_ROOT="$android_tzdata_root" \ 104 ART_TEST_ON_VM="$ART_TEST_ON_VM" \ 105 $(maybe_get_fake_dex2oatbootclasspath) \ 106 $t $options \ 107 || failing_tests+=("$t") 108done 109 110if [[ -n "$failing_tests" ]]; then 111 for t in "${failing_tests[@]}"; do 112 echo "Failed test: $t" 113 done 114 exit 1 115fi 116