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