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 17# launcher script for mts-tradefed harness 18# can be used from an Android build environment, or a standalone mts zip 19 20checkFile() { 21 if [ ! -f "$1" ]; then 22 echo "Unable to locate $1" 23 exit 24 fi; 25} 26 27checkPath() { 28 if ! type -P $1 &> /dev/null; then 29 echo "Unable to find $1 in path." 30 exit 31 fi; 32} 33 34checkPath adb 35checkPath java 36 37# check java version 38JAVA_VERSION=$(java -version 2>&1 | head -n 1 | grep 'version [ "]\(1\.8\|9\|11\).*[ "]') 39if [ "${JAVA_VERSION}" == "" ]; then 40 echo "Wrong java version. 1.8, 9, or 11 is required." 41 exit 42fi 43 44# check debug flag and set up remote debugging 45if [ -n "${TF_DEBUG}" ]; then 46 if [ -z "${TF_DEBUG_PORT}" ]; then 47 TF_DEBUG_PORT=10088 48 fi 49 RDBG_FLAG=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${TF_DEBUG_PORT} 50fi 51 52# get OS 53HOST=`uname` 54if [ "$HOST" == "Linux" ]; then 55 OS="linux-x86" 56elif [ "$HOST" == "Darwin" ]; then 57 OS="darwin-x86" 58else 59 echo "Unrecognized OS" 60 exit 61fi 62 63# check if in Android build env 64if [ ! -z "${ANDROID_BUILD_TOP}" ]; then 65 if [ ! -z "${ANDROID_HOST_OUT}" ]; then 66 MTS_ROOT=${ANDROID_HOST_OUT}/mts 67 else 68 MTS_ROOT=${ANDROID_BUILD_TOP}/${OUT_DIR:-out}/host/${OS}/mts 69 fi 70 if [ ! -d ${MTS_ROOT} ]; then 71 echo "Could not find $MTS_ROOT in Android build environment. Try 'make mts'" 72 exit 73 fi; 74fi; 75 76if [ -z ${MTS_ROOT} ]; then 77 # assume we're in an extracted mts install 78 MTS_ROOT="$(dirname $0)/../.." 79fi; 80 81JAR_DIR=${MTS_ROOT}/android-mts/tools 82 83TRADEFED_JAR="tradefed" 84 85JARS="tradefed 86 loganalysis 87 hosttestlib 88 compatibility-host-util 89 mts-tradefed 90 mts-tradefed-tests" 91 92for JAR in $JARS; do 93 checkFile ${JAR_DIR}/${JAR}.jar 94 JAR_PATH=${JAR_PATH}:${JAR_DIR}/${JAR}.jar 95done 96 97OPTIONAL_JARS=" 98 google-tradefed 99 google-tradefed-tests 100 google-tf-prod-tests" 101 102for JAR in $OPTIONAL_JARS; do 103 if [ -f "$JAR.jar" ]; then 104 JAR_PATH=${JAR_PATH}:${JAR_DIR}/${JAR}.jar 105 fi; 106done 107 108# check if APE_API_KEY is set in the env by user. 109if [ ! -n "${APE_API_KEY}" ]; then 110 GTS_GOOGLE_SERVICE_ACCOUNT=${ANDROID_BUILD_TOP}/vendor/xts/tools/gts-google-service-account/gts-google-service-account.json 111 # set KEY only for google if APE_API_KEY isn't set and GTS_GOOGLE_SERVICE_ACCOUNT exists in the soure tree. 112 if [ -f "$GTS_GOOGLE_SERVICE_ACCOUNT" ]; then 113 APE_API_KEY=${GTS_GOOGLE_SERVICE_ACCOUNT} 114 export APE_API_KEY 115 else 116 echo "APE_API_KEY not set, GTS tests may fail without authentication." 117 fi; 118fi; 119echo "APE_API_KEY: $APE_API_KEY" 120 121# load any shared libraries for host-side executables 122LIB_DIR=${MTS_ROOT}/android-mts/lib 123if [ "$HOST" == "Linux" ]; then 124 LD_LIBRARY_PATH=${LIB_DIR}:${LIB_DIR}64:${LD_LIBRARY_PATH} 125 export LD_LIBRARY_PATH 126elif [ "$HOST" == "Darwin" ]; then 127 DYLD_LIBRARY_PATH=${LIB_DIR}:${LIB_DIR}64:${DYLD_LIBRARY_PATH} 128 export DYLD_LIBRARY_PATH 129fi 130 131# include any host-side test jars 132for j in ${MTS_ROOT}/android-mts/testcases/*.jar; do 133 JAR_PATH=${JAR_PATH}:$j 134done 135 136java $RDBG_FLAG -cp ${JAR_PATH} -DMTS_ROOT=${MTS_ROOT} com.android.compatibility.common.tradefed.command.CompatibilityConsole "$@" 137 138 139