Home | History | Annotate | Download | only in build-android
      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 
     21 function 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 
     31 if [[ $(($# % 2)) -ne 0 ]]
     32 then
     33     echo Parameters must be provided in pairs.
     34     echo parameter count = $#
     35     echo
     36     printUsage
     37     exit 1
     38 fi
     39 
     40 while [[ $# -gt 0 ]]
     41 do
     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
     63 done
     64 
     65 if [[ $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
     74 else
     75     echo Using device $(adb get-serialno)
     76 fi
     77 
     78 if [[ -z $platform ]]
     79 then
     80     echo No platform specified.
     81     platform="UnspecifiedPlatform"
     82 fi
     83 
     84 if [[ -z $filter ]]
     85 then
     86     echo No filter specified, running all tests.
     87     filter="*"
     88 fi
     89 
     90 if [[ $platform ]]; then echo platform = "${platform}"; fi
     91 if [[ $filter ]]; then echo filter = "${filter}"; fi
     92 if [[ $serial ]]; then echo serial = "${serial}"; fi
     93 
     94 set -ev
     95 
     96 #
     97 # Start up
     98 #
     99 
    100 # Wake up the device
    101 adb $serialFlag shell input keyevent "KEYCODE_MENU"
    102 adb $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
    108 lock_seconds=1200                                # Duration in seconds.
    109 lock_end_time=$(( $(date +%s) + lock_seconds ))  # Calculate end time.
    110 
    111 until mkdir /var/tmp/VkLayerValidationTests.$serial.lock
    112 do
    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
    122 done
    123 
    124 # Clean up our lock on any exit condition
    125 function finish {
    126    rm -r /var/tmp/VkLayerValidationTests.$serial.lock
    127 }
    128 trap finish EXIT
    129 
    130 # Clear the log
    131 adb $serialFlag logcat -c
    132 
    133 # Ensure any previous activity has stopped, otherwise it won't run tests
    134 adb $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
    138 set +e
    139 adb $serialFlag shell pm list packages | grep com.example.VulkanLayerValidationTests
    140 if [ $? -eq 0 ]
    141 then
    142     adb $serialFlag uninstall com.example.VulkanLayerValidationTests
    143 fi
    144 # Re-enable exit on error
    145 set -e
    146 
    147 # Install the current build
    148 adb $serialFlag install -r bin/VulkanLayerValidationTests.apk
    149 
    150 # Kick off the tests with known expection list
    151 adb $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
    158 seconds=1200                          # Duration in seconds.
    159 endTime=$(( $(date +%s) + seconds ))  # Calculate end time.
    160 
    161 exitCode=-1;
    162 
    163 # Disable exit on error, we expect grep to fail multiple times in this loop
    164 set +e
    165 
    166 while [ $(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 
    197 done
    198 
    199 # Re-enable exit on error
    200 set -e
    201 
    202 if [ $exitCode -eq -1 ]
    203 then
    204     echo "VulkanLayerValidationTests hasn't completed in $seconds seconds. Script exiting."
    205 fi
    206 
    207 #
    208 # Cleanup
    209 #
    210 
    211 # Return to home screen to clear any error pop-ups
    212 adb $serialFlag shell input keyevent "KEYCODE_HOME"
    213 
    214 # Stop the activity
    215 adb $serialFlag shell am force-stop com.example.VulkanLayerValidationTests
    216 
    217 today=$(date +%Y-%m-%d.%H:%M:%S)
    218 outFile="VulkanLayerValidationTests.$platform.$today.out.txt"
    219 errFile="VulkanLayerValidationTests.$platform.$today.err.txt"
    220 adb $serialFlag pull /sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt VulkanLayerValidationTests.$platform.$today.out.txt
    221 adb $serialFlag pull /sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt VulkanLayerValidationTests.$platform.$today.err.txt
    222 
    223 if [ -f $outFile ]; then
    224     echo $outFile size $(wc -c < $outFile)
    225 fi
    226 
    227 if [ -f $errFile ]; then
    228     echo $errFile size $(wc -c < $errFile)
    229 fi
    230 
    231 echo
    232 echo ===== Dumping logcat of VulkanLayerValidationTests =====
    233 echo If the test is crashing, be sure to inspect full log for complete stack trace.
    234 echo "adb $serialFlag logcat -d | grep VulkanLayerValidationTests"
    235 echo ========================================================
    236 echo
    237 adb $serialFlag logcat -d | grep VulkanLayerValidationTests
    238 
    239 exit $exitCode
    240