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