1#!/bin/bash 2# Copyright 2017 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# A script that runs media-compat-test between different versions. 17# 18# Preconditions: 19# - Exactly one test device should be connected. 20# 21# TODO: 22# - Support simultaneous multiple device connection 23 24# Usage './runtest.sh <version_combination_number> [option]' 25 26CLIENT_MODULE_NAME_BASE="support-media-compat-test-client" 27SERVICE_MODULE_NAME_BASE="support-media-compat-test-service" 28CLIENT_VERSION="" 29SERVICE_VERSION="" 30OPTION_TEST_TARGET="" 31 32function printRunTestUsage() { 33 echo "Usage: ./runtest.sh <version_combination_number> [option]" 34 echo "" 35 echo "Version combination number:" 36 echo " 1. Client-ToT / Service-ToT" 37 echo " 2. Client-ToT / Service-Latest release" 38 echo " 3. Client-Latest release / Service-ToT" 39 echo " 4. Run all of the above" 40 echo "" 41 echo "Option:" 42 echo " -t <class/method>: Only run the specific test class/method." 43} 44 45function runTest() { 46 echo "Running test: Client-$CLIENT_VERSION / Service-$SERVICE_VERSION" 47 48 local CLIENT_MODULE_NAME="$CLIENT_MODULE_NAME_BASE$([ "$CLIENT_VERSION" = "tot" ] || echo "-previous")" 49 local SERVICE_MODULE_NAME="$SERVICE_MODULE_NAME_BASE$([ "$SERVICE_VERSION" = "tot" ] || echo "-previous")" 50 51 # Build test apks 52 ./gradlew $CLIENT_MODULE_NAME:assembleDebugAndroidTest || { echo "Build failed. Aborting."; exit 1; } 53 ./gradlew $SERVICE_MODULE_NAME:assembleDebugAndroidTest || { echo "Build failed. Aborting."; exit 1; } 54 55 # Install the apks 56 adb install -r -d "../../out/dist/$CLIENT_MODULE_NAME.apk" || { echo "Apk installation failed. Aborting."; exit 1; } 57 adb install -r -d "../../out/dist/$SERVICE_MODULE_NAME.apk" || { echo "Apk installation failed. Aborting."; exit 1; } 58 59 # Run the tests 60 local test_command="adb shell am instrument -w -e debug false -e client_version $CLIENT_VERSION -e service_version $SERVICE_VERSION" 61 local client_test_runner="android.support.mediacompat.client.test/android.support.test.runner.AndroidJUnitRunner" 62 local service_test_runner="android.support.mediacompat.service.test/android.support.test.runner.AndroidJUnitRunner" 63 64 echo ">>>>>>>>>>>>>>>>>>>>>>>> Test Started: Client-$CLIENT_VERSION & Service-$SERVICE_VERSION <<<<<<<<<<<<<<<<<<<<<<<<" 65 66 if [[ $OPTION_TEST_TARGET == *"client"* ]]; then 67 ${test_command} $OPTION_TEST_TARGET ${client_test_runner} 68 elif [[ $OPTION_TEST_TARGET == *"service"* ]]; then 69 ${test_command} $OPTION_TEST_TARGET ${service_test_runner} 70 else 71 ${test_command} ${client_test_runner} 72 ${test_command} ${service_test_runner} 73 fi 74 75 echo ">>>>>>>>>>>>>>>>>>>>>>>> Test Ended: Client-$CLIENT_VERSION & Service-$SERVICE_VERSION <<<<<<<<<<<<<<<<<<<<<<<<<<" 76} 77 78 79OLD_PWD=$(pwd) 80 81if ! cd "$(echo $OLD_PWD | awk -F'frameworks/support' '{print $1}')"/frameworks/support &> /dev/null 82then 83 echo "Current working directory is $OLD_PWD" 84 echo "Please re-run this script in any folder under frameworks/support." 85 exit 1; 86fi 87 88if [[ $# -eq 0 || $1 -le 0 || $1 -gt 4 ]] 89then 90 printRunTestUsage 91 exit 1; 92fi 93 94if [[ ${2} == "-t" ]]; then 95 if [[ ${3} == *"client"* || ${3} == *"service"* ]]; then 96 OPTION_TEST_TARGET="-e class ${3}" 97 else 98 echo "Wrong test class/method name. Aborting." 99 echo "It should be in the form of \"<FULL_CLASS_NAME>[#METHOD_NAME]\"." 100 exit 1; 101 fi 102fi 103 104case ${1} in 105 1) 106 CLIENT_VERSION="tot" 107 SERVICE_VERSION="tot" 108 runTest 109 ;; 110 2) 111 CLIENT_VERSION="tot" 112 SERVICE_VERSION="previous" 113 runTest 114 ;; 115 3) 116 CLIENT_VERSION="previous" 117 SERVICE_VERSION="tot" 118 runTest 119 ;; 120 4) 121 CLIENT_VERSION="tot" 122 SERVICE_VERSION="tot" 123 runTest 124 125 CLIENT_VERSION="tot" 126 SERVICE_VERSION="previous" 127 runTest 128 129 CLIENT_VERSION="previous" 130 SERVICE_VERSION="tot" 131 runTest 132 ;; 133esac 134