|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2018 The GraphicsFuzz Project Authors |
| 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 | +# https://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 | +HERE=`dirname ${BASH_SOURCE[0]}` |
| 18 | +OS=`uname` |
| 19 | +BIN="${HERE}/../../bin/${OS}" |
| 20 | + |
| 21 | +temp="_tmp" |
| 22 | + |
| 23 | +usage() { |
| 24 | + echo "Usage: `basename $0` shader.frag.spv" |
| 25 | + echo "Arguments:" |
| 26 | + echo " shader.frag.spv: textual SPIR-V file" |
| 27 | + echo " Expected: the companion shader.json" |
| 28 | + echo " Optional: the companion shader.vert.spv" |
| 29 | + echo "Results: shader.{log,adb.log,ppm,png}" |
| 30 | + echo "Warning: this script works on temporary files named: ${temp}*" |
| 31 | + exit 1 |
| 32 | +} |
| 33 | + |
| 34 | +frag=$1 |
| 35 | + |
| 36 | +if test -z ${frag} |
| 37 | +then |
| 38 | + echo "Error: please provide argument" |
| 39 | + usage |
| 40 | +fi |
| 41 | + |
| 42 | +wd=`dirname $frag` |
| 43 | +base=`basename $frag .frag.spv` |
| 44 | + |
| 45 | +if test ! -f ${wd}/${frag} |
| 46 | +then |
| 47 | + echo "Error: cannot find file: $frag" |
| 48 | + usage |
| 49 | +fi |
| 50 | + |
| 51 | +set -e |
| 52 | +set -u |
| 53 | + |
| 54 | +# Prepare vertex |
| 55 | +if test ! -f ${wd}/${base}.vert.spv |
| 56 | +then |
| 57 | + ( |
| 58 | + cat << EOF |
| 59 | +#version 310 es |
| 60 | +
|
| 61 | +layout(location=0) in highp vec4 a_position; |
| 62 | +void main (void) { |
| 63 | + gl_Position = a_position; |
| 64 | +} |
| 65 | +EOF |
| 66 | + ) | ${BIN}/glslangValidator --stdin -V -S vert -o ${temp}.vert.spv |
| 67 | +else |
| 68 | + ${BIN}/spirv-as ${wd}/${base}.vert.spv -o ${temp}.vert.spv |
| 69 | +fi |
| 70 | + |
| 71 | +# Assemble fragment |
| 72 | +${BIN}/spirv-as ${frag} -o ${temp}.frag.spv |
| 73 | + |
| 74 | +# Make sure the app can read/write on /sdcard/ |
| 75 | +adb shell pm grant vulkan.samples.vulkan_worker android.permission.READ_EXTERNAL_STORAGE |
| 76 | +adb shell pm grant vulkan.samples.vulkan_worker android.permission.WRITE_EXTERNAL_STORAGE |
| 77 | + |
| 78 | +# Clean up |
| 79 | +adb shell rm -rf /sdcard/graphicsfuzz |
| 80 | +adb shell mkdir -p /sdcard/graphicsfuzz |
| 81 | + |
| 82 | +# Put files |
| 83 | +adb push ${temp}.frag.spv /sdcard/graphicsfuzz/test.frag.spv > /dev/null |
| 84 | +adb push ${temp}.vert.spv /sdcard/graphicsfuzz/test.vert.spv > /dev/null |
| 85 | +adb push ${wd}/${base}.json /sdcard/graphicsfuzz/test.json > /dev/null |
| 86 | + |
| 87 | +# Clean temporary files |
| 88 | +rm -f ${temp}.* |
| 89 | + |
| 90 | +# Clear ADB logcat |
| 91 | +adb logcat -b all -c || printf "Fail to clean all adb logs, continue\n" |
| 92 | + |
| 93 | +# Run the app |
| 94 | +adb shell am start -n vulkan.samples.vulkan_worker/android.app.NativeActivity |
| 95 | + |
| 96 | +# Busy wait for DONE file to be written, or timeout |
| 97 | +echo "Wait for app to terminate" |
| 98 | +loop_iter=10 |
| 99 | +until adb shell test -f /sdcard/graphicsfuzz/DONE |
| 100 | +do |
| 101 | + sleep 0.5 |
| 102 | + loop_iter=$(($loop_iter - 1)) |
| 103 | + if test $loop_iter -le 0 |
| 104 | + then |
| 105 | + break |
| 106 | + fi |
| 107 | + echo -n "." |
| 108 | +done |
| 109 | +echo "" |
| 110 | + |
| 111 | +# Retrieve log |
| 112 | +adb pull /sdcard/graphicsfuzz/log.txt ${base}.log > /dev/null |
| 113 | +adb logcat -b crash -b system -b main -b events -d > ${base}.adb.log |
| 114 | + |
| 115 | +if adb shell test -f /sdcard/graphicsfuzz/image.ppm |
| 116 | +then |
| 117 | + # Retrieve image |
| 118 | + adb pull /sdcard/graphicsfuzz/image.ppm ${base}.ppm > /dev/null || printf "Failed to pull PPM image\n" |
| 119 | + convert ${base}.ppm ${base}.png || printf "Conversion from PPM to PNG failed\n" |
| 120 | +fi |
| 121 | + |
| 122 | +printf "See results in:\n%s\n%s\n" ${base}.log ${base}.adb.log |
| 123 | +if test -f ${base}.png |
| 124 | +then |
| 125 | + printf "%s\n" ${base}.png |
| 126 | +elif test -f ${base}.ppm |
| 127 | +then |
| 128 | + printf "%s\n" ${base}.ppm |
| 129 | +fi |
0 commit comments