From 01c3ce7c03f139239c2275348492ff547f1b9e80 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 5 May 2021 15:45:42 +0000 Subject: [PATCH] test-all: allow specification of one output format It's the second argument This moves the subdirectory argument to the third position. Change-Id: I91f7a8171f6de51e697a04c1407a1992b5c1c0db Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49642 Commit-Queue: David Neto Auto-Submit: David Neto Reviewed-by: Ben Clayton --- test/test-all.sh | 95 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/test/test-all.sh b/test/test-all.sh index 35ba00746d..fad05e9c4b 100755 --- a/test/test-all.sh +++ b/test/test-all.sh @@ -21,18 +21,81 @@ TEXT_GREEN="\033[0;32m" TEXT_RED="\033[0;31m" TEXT_DEFAULT="\033[0m" -TINT="$1" -SUBDIR="$2" +CHECK_WGSL=1 +CHECK_SPV=1 +CHECK_MSL=1 +CHECK_HLSL=1 -if [ ! -x "$TINT" ]; then +TINT="$1" +ONLY_FORMAT="$2" +SUBDIR="$3" + +function usage() { echo "test-all.sh compiles with tint all the .wgsl files in the tint/test" echo "directory, for each of the SPIR-V, MSL, HLSL and WGSL backends." echo "Any errors are reported as test failures." echo "" - echo "Usage: test-all.sh []" + echo "Usage: test-all.sh [ []]" + echo + echo " limits which output format is tested. The default is all." + echo " Possible values are: all, wgsl, spv, msl, hlsl" + echo + echo " specifies which directory has the sample files, relative to the script." + echo " When not specified, check the .wgsl and .spvasm files in the script directory." +} + +if [ ! -x "$TINT" ]; then + usage exit 1 fi +if [ ! -z "$ONLY_FORMAT" ]; then + case "${ONLY_FORMAT}" in + all) + ;; + wgsl) + CHECK_WGSL=1 + CHECK_SPV=0 + CHECK_MSL=0 + CHECK_HLSL=0 + ;; + spv) + CHECK_WGSL=0 + CHECK_SPV=1 + CHECK_MSL=0 + CHECK_HLSL=0 + ;; + msl) + CHECK_WGSL=0 + CHECK_SPV=0 + CHECK_MSL=1 + CHECK_HLSL=0 + ;; + hlsl) + CHECK_WGSL=0 + CHECK_SPV=0 + CHECK_MSL=0 + CHECK_HLSL=1 + ;; + *) + usage + exit 1 + esac +fi + +if [ ! -z "${SUBDIR}" ]; then + if [ ! -d "${SUBDIR}" ]; then + echo "error: ${SUBDIR} is not a directory" + exit 1 + fi +fi + +if [ ! -z "$4" ]; then + echo "error: Too many arguments" + usage + exit 1 +fi + SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" NUM_PASS=0 NUM_SKIP=0 @@ -83,7 +146,7 @@ function check() { # check_formats(TEST_FILE) function check_formats() { - local TEST_FILE="$1" + local TEST_FILE=$1 if [ -x realpath ]; then TEST_FILE=$(realpath --relative-to="$SCRIPT_DIR" "$TEST_FILE") else @@ -91,19 +154,19 @@ function check_formats() { fi echo echo "Testing ${TEST_FILE}..." - check "${TEST_FILE}" wgsl - check "${TEST_FILE}" spirv - check "${TEST_FILE}" msl - check "${TEST_FILE}" hlsl + [ ${CHECK_WGSL} -eq 0 ] || check "${TEST_FILE}" wgsl + [ ${CHECK_SPV} -eq 0 ] || check "${TEST_FILE}" spirv + [ ${CHECK_MSL} -eq 0 ] || check "${TEST_FILE}" msl + [ ${CHECK_HLSL} -eq 0 ] || check "${TEST_FILE}" hlsl } -for F in ${SCRIPT_DIR}/*.spvasm ${SCRIPT_DIR}/*.wgsl -do - check_formats "$F" -done - -if [ -d "${SUBDIR}" ]; then - for F in "${SUBDIR}"/*; +if [ -z "${SUBDIR}" ]; then + for F in ${SCRIPT_DIR}/*.spvasm ${SCRIPT_DIR}/*.wgsl + do + check_formats "$F" + done +else + for F in "${SCRIPT_DIR}/${SUBDIR}"/*; do check_formats "$F" done