test-all.sh: Rework use of directory argument

If a directory is specified, then check shader source files there.
Otherwise, use shader source files in the same directory as the test
script.

Enhance error checking and messages.

Change-Id: I6ea40e2a44128ba3ce103faaad5326b89bbf4ed7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49841
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
David Neto 2021-05-07 17:42:34 +00:00 committed by Commit Bot service account
parent 593c87b414
commit 7e55817552
1 changed files with 40 additions and 37 deletions

View File

@ -28,28 +28,35 @@ CHECK_HLSL=1
TINT="$1"
ONLY_FORMAT="$2"
SUBDIR="$3"
TARGETDIR="$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 <path-to-tint-executable> [<only-format> [<subdir-with-more-samples>]]"
echo "test-all.sh uses tint to compile .wgsl and .spvasm files, reporting errors as test failures."
echo
echo "<only-format> limits which output format is tested. The default is all."
echo " Possible values are: all, wgsl, spv, msl, hlsl"
echo "Usage: test-all.sh <path-to-tint-executable> [<only-format> [directory]]"
echo
echo "<subdir-with-more-samples> 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."
echo "<only-format> specifies which output format is tested."
echo " Possible values are: all, wgsl, spv, msl, hlsl."
echo " The default is 'all'."
echo
echo "[directory] specifies which directory holds the source files"
echo " The default is to use the script directory."
}
if [ -z "$TINT" ]; then
echo "error: missing argument: location of the 'tint' executable"
echo
usage
exit 1
fi
if [ ! -x "$TINT" ]; then
echo "error: invalid argument: location of the 'tint' executable"
echo
usage
exit 1
fi
if [ ! -z "$ONLY_FORMAT" ]; then
if [ -n "$ONLY_FORMAT" ]; then
case "${ONLY_FORMAT}" in
all)
;;
@ -78,25 +85,32 @@ if [ ! -z "$ONLY_FORMAT" ]; then
CHECK_HLSL=1
;;
*)
echo "error: invalid format argument: $ONLY_FORMAT"
echo
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
if [ -n "$4" ]; then
echo "error: Too many arguments"
echo
usage
exit 1
fi
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
# If no subdirectory was specified, look in the script directory.
if [ -z "${TARGETDIR}" ]; then
TARGETDIR="${SCRIPT_DIR}"
fi
if [ ! -d "${TARGETDIR}" ]; then
echo "error: ${TARGETDIR} is not a directory"
exit 1
fi
NUM_PASS=0
NUM_SKIP=0
NUM_FAIL=0
@ -122,7 +136,8 @@ function check() {
local FORMAT=$2
SKIP=
if [[ $SKIPPED == *"${FORMAT}:${TEST_FILE}"* ]]; then
TEST_FILE_WITHOUT_DIR=$(basename ${TEST_FILE})
if [[ $SKIPPED == *"${FORMAT}:${TEST_FILE_WITHOUT_DIR}"* ]]; then
SKIP=1
fi
@ -133,7 +148,7 @@ function check() {
return
fi
set +e
"${TINT}" ${SCRIPT_DIR}/${TEST_FILE} --format ${FORMAT} -o /dev/null
"${TINT}" ${TEST_FILE} --format ${FORMAT} -o /dev/null
if [ $? -eq 0 ]; then
echo -e "${TEXT_GREEN}PASS${TEXT_DEFAULT}"
NUM_PASS=$((${NUM_PASS}+1))
@ -147,11 +162,6 @@ function check() {
# check_formats(TEST_FILE)
function check_formats() {
local TEST_FILE=$1
if [ -x realpath ]; then
TEST_FILE=$(realpath --relative-to="$SCRIPT_DIR" "$TEST_FILE")
else
TEST_FILE=$(echo -n "$TEST_FILE"| sed -e "s'${SCRIPT_DIR}/*''")
fi
echo
echo "Testing ${TEST_FILE}..."
[ ${CHECK_WGSL} -eq 0 ] || check "${TEST_FILE}" wgsl
@ -160,17 +170,10 @@ function check_formats() {
[ ${CHECK_HLSL} -eq 0 ] || check "${TEST_FILE}" hlsl
}
if [ -z "${SUBDIR}" ]; then
for F in ${SCRIPT_DIR}/*.spvasm ${SCRIPT_DIR}/*.wgsl
do
for F in "${TARGETDIR}"/*.spvasm "${TARGETDIR}"/*.wgsl
do
check_formats "$F"
done
else
for F in "${SCRIPT_DIR}/${SUBDIR}"/*;
do
check_formats "$F"
done
fi
done
if [ ${NUM_FAIL} -ne 0 ]; then
echo