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
17if [[ $1 = -h ]]; then
18  cat <<EOF
19Script to run gtests located in the ART (Testing) APEX.
20
21If called with arguments, only those tests are run, as specified by their
22absolute paths (starting with /apex). All gtests are run otherwise.
23EOF
24  exit
25fi
26
27if [[ -z "$ART_TEST_CHROOT" ]]; then
28  echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.'
29  exit 1
30fi
31
32adb="${ADB:-adb}"
33
34android_i18n_root=/apex/com.android.i18n
35android_art_root=/apex/com.android.art
36android_tzdata_root=/apex/com.android.tzdata
37
38if [[ $1 = -j* ]]; then
39  # TODO(b/129930445): Implement support for parallel execution.
40  shift
41fi
42
43if [ $# -gt 0 ]; then
44  tests="$@"
45else
46  # Search for executables under the `bin/art` directory of the ART APEX.
47  tests=$("$adb" shell chroot "$ART_TEST_CHROOT" \
48    find "$android_art_root/bin/art" -type f -perm /ugo+x | sort)
49fi
50
51failing_tests=()
52
53for t in $tests; do
54  echo "$t"
55  "$adb" shell chroot "$ART_TEST_CHROOT" \
56    env ANDROID_ART_ROOT="$android_art_root" \
57        ANDROID_I18N_ROOT="$android_i18n_root" \
58        ANDROID_TZDATA_ROOT="$android_tzdata_root" \
59        $t \
60    || failing_tests+=("$t")
61done
62
63if [ -n "$failing_tests" ]; then
64  for t in "${failing_tests[@]}"; do
65    echo "Failed test: $t"
66  done
67  exit 1
68fi
69