1#!/bin/bash 2 3# Copyright 2017 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# 18# Parse parameters 19# 20 21function printUsage { 22 echo "Supported parameters are:" 23 echo " -p|--platform <platform> (optional)" 24 echo " -f|--filter <gtest filter list> (optional)" 25 echo " -s|--serial <target device serial number> (optional)" 26 echo 27 echo "i.e. ${0##*/} -p <platform> -f <test filter> -s <serial number>" 28 exit 1 29} 30 31if [[ $(($# % 2)) -ne 0 ]] 32then 33 echo Parameters must be provided in pairs. 34 echo parameter count = $# 35 echo 36 printUsage 37 exit 1 38fi 39 40while [[ $# -gt 0 ]] 41do 42 case $1 in 43 -p|--platform) 44 platform="$2" 45 shift 2 46 ;; 47 -f|--filter) 48 filter="$2" 49 shift 2 50 ;; 51 -s|--serial) 52 serial="$2" 53 shift 2 54 ;; 55 -*) 56 # unknown option 57 echo Unknown option: $1 58 echo 59 printUsage 60 exit 1 61 ;; 62 esac 63done 64 65if [[ $serial ]]; then 66 serialFlag="-s $serial" 67 if [[ $(adb devices) != *"$serial"* ]] 68 then 69 echo Device not found: "${serial}" 70 echo 71 printUsage 72 exit 1 73 fi 74else 75 echo Using device $(adb get-serialno) 76fi 77 78if [[ -z $platform ]] 79then 80 echo No platform specified. 81 platform="UnspecifiedPlatform" 82fi 83 84if [[ -z $filter ]] 85then 86 echo No filter specified, running all tests. 87 filter="*" 88fi 89 90if [[ $platform ]]; then echo platform = "${platform}"; fi 91if [[ $filter ]]; then echo filter = "${filter}"; fi 92if [[ $serial ]]; then echo serial = "${serial}"; fi 93 94set -ev 95 96# 97# Start up 98# 99 100# Wake up the device 101adb $serialFlag shell input keyevent "KEYCODE_MENU" 102adb $serialFlag shell input keyevent "KEYCODE_HOME" 103 104# Grab our Android test mutex 105# Wait for any existing test runs on the devices 106 107# Blow away the lock if tests run too long, avoiding infinite loop 108lock_seconds=1200 # Duration in seconds. 109lock_end_time=$(( $(date +%s) + lock_seconds )) # Calculate end time. 110 111until mkdir /var/tmp/VkLayerValidationTests.$serial.lock 112do 113 sleep 5 114 echo "Waiting for existing Android test to complete on $serial" 115 116 if [ $(date +%s) -gt $lock_end_time ] 117 then 118 echo "Lock timeout reached: $lock_seconds seconds" 119 echo "Deleting /var/tmp/VkLayerValidationTests.$serial.lock" 120 rm -r /var/tmp/VkLayerValidationTests.$serial.lock 121 fi 122done 123 124# Clean up our lock on any exit condition 125function finish { 126 rm -r /var/tmp/VkLayerValidationTests.$serial.lock 127} 128trap finish EXIT 129 130# Clear the log 131adb $serialFlag logcat -c 132 133# Ensure any previous activity has stopped, otherwise it won't run tests 134adb $serialFlag shell am force-stop com.example.VulkanLayerValidationTests 135 136# Remove any existing APK that may have been installed from another host 137# Disable exit on error in case the APK is not present 138set +e 139adb $serialFlag shell pm list packages | grep com.example.VulkanLayerValidationTests 140if [ $? -eq 0 ] 141then 142 adb $serialFlag uninstall com.example.VulkanLayerValidationTests 143fi 144# Re-enable exit on error 145set -e 146 147# Install the current build 148adb $serialFlag install -r bin/VulkanLayerValidationTests.apk 149 150# Kick off the tests with known expection list 151adb $serialFlag shell am start -a android.intent.action.MAIN -c android-intent.category.LAUNCH -n com.example.VulkanLayerValidationTests/android.app.NativeActivity --es args --gtest_filter="${filter}" 152 153# 154# Scrape the log until we get pass/fail/crash 155# 156 157# The following loop will give tests 20 minutes to pass/fail/crash 158seconds=1200 # Duration in seconds. 159endTime=$(( $(date +%s) + seconds )) # Calculate end time. 160 161exitCode=-1; 162 163# Disable exit on error, we expect grep to fail multiple times in this loop 164set +e 165 166while [ $(date +%s) -lt $endTime ]; do # Loop until interval has elapsed. 167 168 # The following line is printed from android_main on success 169 adb $serialFlag logcat -d | grep "==== Tests PASSED ====" 170 if [ $? -eq 0 ] 171 then 172 echo VulkanLayerValidationTests PASSED! 173 exitCode=0 174 break 175 fi 176 177 # The following line is printed from android_main on failure 178 adb $serialFlag logcat -d | grep "==== Tests FAILED ====" 179 if [ $? -eq 0 ] 180 then 181 echo VulkanLayerValidationTests FAILED! 182 exitCode=1 183 break 184 fi 185 186 # developer.android.com recommends searching for the following string to detect native crash 187 adb $serialFlag logcat -d | grep "\*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\*" 188 if [ $? -eq 0 ] 189 then 190 exitCode=2 191 echo VulkanLayerValidationTests CRASHED! 192 break 193 fi 194 195 sleep 5 196 197done 198 199# Re-enable exit on error 200set -e 201 202if [ $exitCode -eq -1 ] 203then 204 echo "VulkanLayerValidationTests hasn't completed in $seconds seconds. Script exiting." 205fi 206 207# 208# Cleanup 209# 210 211# Return to home screen to clear any error pop-ups 212adb $serialFlag shell input keyevent "KEYCODE_HOME" 213 214# Stop the activity 215adb $serialFlag shell am force-stop com.example.VulkanLayerValidationTests 216 217today=$(date +%Y-%m-%d.%H:%M:%S) 218outFile="VulkanLayerValidationTests.$platform.$today.out.txt" 219errFile="VulkanLayerValidationTests.$platform.$today.err.txt" 220adb $serialFlag pull /sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt VulkanLayerValidationTests.$platform.$today.out.txt 221adb $serialFlag pull /sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt VulkanLayerValidationTests.$platform.$today.err.txt 222 223if [ -f $outFile ]; then 224 echo $outFile size $(wc -c < $outFile) 225fi 226 227if [ -f $errFile ]; then 228 echo $errFile size $(wc -c < $errFile) 229fi 230 231echo 232echo ===== Dumping logcat of VulkanLayerValidationTests ===== 233echo If the test is crashing, be sure to inspect full log for complete stack trace. 234echo "adb $serialFlag logcat -d | grep VulkanLayerValidationTests" 235echo ======================================================== 236echo 237adb $serialFlag logcat -d | grep VulkanLayerValidationTests 238 239exit $exitCode 240