1#!/bin/bash
2
3# Copyright (C) 2021 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
17# launcher script for cts-root-tradefed harness
18# can be used from an Android build environment, or a standalone cts-root zip
19
20UTILS_SCRIPT="$(dirname $(realpath $0))/test-utils-script"
21
22if [ ! -f "${UTILS_SCRIPT}" ]
23then
24  UTILS_SCRIPT="${ANDROID_BUILD_TOP}/platform_testing/scripts/test-utils-script"
25fi
26
27if [ ! -f "${UTILS_SCRIPT}" ]
28then
29  echo -e "Cannot find test-utils-script in the same location as this script" \
30          "and ANDROID_BUILD_TOP is not defined."
31  exit 1
32fi
33
34source ${UTILS_SCRIPT}
35
36checkPath adb
37checkPath java
38checkJavaVersion java
39
40RDBG_FLAG=$(getRemoteDbgFlag)
41
42# get OS
43HOST=`uname`
44if [ "$HOST" == "Linux" ]; then
45    OS="linux-x86"
46elif [ "$HOST" == "Darwin" ]; then
47    OS="darwin-x86"
48else
49    echo "Unrecognized OS"
50    exit
51fi
52
53# check if in Android build env
54if [ ! -z "${ANDROID_BUILD_TOP}" ]; then
55    if [ ! -z "${ANDROID_HOST_OUT}" ]; then
56      CTS_ROOT_ROOT=${ANDROID_HOST_OUT}/cts_root
57    else
58      CTS_ROOT_ROOT=${ANDROID_BUILD_TOP}/${OUT_DIR:-out}/host/${OS}/cts_root
59    fi
60    if [ ! -d ${CTS_ROOT_ROOT} ]; then
61        echo "Could not find $CTS_ROOT_ROOT in Android build environment. Try 'make cts_root'"
62        exit
63    fi;
64fi;
65
66if [ -z ${CTS_ROOT_ROOT} ]; then
67    # assume we're in an extracted cts-root install
68    CTS_ROOT_ROOT="$(dirname $0)/../.."
69fi;
70
71JAR_DIR=${CTS_ROOT_ROOT}/android-cts_root/tools
72
73for JAR in ${JAR_DIR}/*.jar; do
74    JAR_PATH=${JAR_PATH}:${JAR}
75done
76
77LIB_DIR=${CTS_ROOT_ROOT}/android-cts_root/lib
78loadSharedLibraries "$HOST" "$LIB_DIR"
79
80# include any host-side test jars
81for j in ${CTS_ROOT_ROOT}/android-cts_root/testcases/*.jar; do
82    JAR_PATH=${JAR_PATH}:$j
83done
84
85java $RDBG_FLAG -cp ${JAR_PATH} -DCTS_ROOT_ROOT=${CTS_ROOT_ROOT} com.android.compatibility.common.tradefed.command.CompatibilityConsole "$@"
86