2021-03-17 18:49:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Copyright 2021 The Tint Authors.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
set -e # Fail on any error.
|
|
|
|
|
|
|
|
TEXT_GREEN="\033[0;32m"
|
|
|
|
TEXT_RED="\033[0;31m"
|
|
|
|
TEXT_DEFAULT="\033[0m"
|
|
|
|
|
|
|
|
TINT=$1
|
|
|
|
|
|
|
|
if [ ! -x "$TINT" ]; then
|
|
|
|
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>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
|
|
|
|
NUM_PASS=0
|
|
|
|
NUM_FAIL=0
|
|
|
|
|
2021-04-26 10:46:55 +00:00
|
|
|
# check(TEST_FILE, FORMAT)
|
2021-03-17 18:49:03 +00:00
|
|
|
function check() {
|
2021-04-26 10:46:55 +00:00
|
|
|
TEST_FILE=$1
|
2021-03-17 18:49:03 +00:00
|
|
|
FORMAT=$2
|
|
|
|
printf "%7s: " "${FORMAT}"
|
|
|
|
set +e
|
2021-04-26 10:46:55 +00:00
|
|
|
${TINT} ${TEST_FILE} --format ${FORMAT} -o /dev/null
|
2021-03-17 18:49:03 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo -e "${TEXT_GREEN}PASS${TEXT_DEFAULT}"
|
|
|
|
NUM_PASS=$((${NUM_PASS}+1))
|
|
|
|
else
|
|
|
|
echo -e "${TEXT_RED}FAIL${TEXT_DEFAULT}"
|
|
|
|
NUM_FAIL=$((${NUM_FAIL}+1))
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:46:55 +00:00
|
|
|
for TEST_FILE in ${SCRIPT_DIR}/*.spvasm ${SCRIPT_DIR}/*.wgsl
|
2021-03-17 18:49:03 +00:00
|
|
|
do
|
|
|
|
echo
|
2021-04-26 10:46:55 +00:00
|
|
|
echo "Testing $TEST_FILE..."
|
|
|
|
check "${TEST_FILE}" wgsl
|
|
|
|
check "${TEST_FILE}" spirv
|
|
|
|
check "${TEST_FILE}" msl
|
|
|
|
check "${TEST_FILE}" hlsl
|
2021-03-17 18:49:03 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${NUM_FAIL} -ne 0 ]; then
|
|
|
|
echo
|
|
|
|
echo -e "${TEXT_RED}${NUM_FAIL} tests failed. ${TEXT_DEFAULT}${NUM_PASS} passed${TEXT_DEFAULT}"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo -e "${TEXT_GREEN}All ${NUM_PASS} tests pass${TEXT_DEFAULT}"
|
|
|
|
echo
|
|
|
|
fi
|