Add --dump-spirv option to tint_unittests

The --dump-spirv option tells tint_unittests to output the
SPIR-V assembly text for a module which did not make the SPIR-V reader
fail.  This lets us get extract a corpus of SPIR-V modules, and
lets us more easily verify that the test shaders are valid in the first
place.

Also:
- Add test/extract-spvasm.py to split that output to separate SPIR-V
  assembly files
- Add optional second argument test/test-all.sh to specify a directory
  look for input files.
- BUILD.gn:  Add dependency from //test:tint_unittests_main to
  //test:tint_unittests_config to pick up source dependency on
  the internal header of the SPIRV-Tools optimizer, needed by
  the indirection through src/reader/spirv/parser_impl_test_helper.h

This is useful for bulk testing

Fixed: tint:756
Change-Id: I4fe232ac736003f7d9be35544328302d652381ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49605
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
David Neto
2021-05-05 09:46:31 +00:00
committed by Commit Bot service account
parent 02ebf0dcae
commit 58a3624935
8 changed files with 166 additions and 13 deletions

View File

@@ -88,10 +88,12 @@ source_set("tint_unittests_main") {
sources = [ "//gpu/tint_unittests_main.cc" ]
} else {
sources = [ "../src/test_main.cc" ]
configs += [ ":tint_unittests_config" ]
deps += [
":tint_test_helpers",
":tint_unittests_hlsl_writer_src",
":tint_unittests_msl_writer_src",
":tint_unittests_spv_reader_src",
"${tint_root_dir}/src:libtint",
]
}
@@ -343,6 +345,8 @@ tint_unittests_source_set("tint_unittests_spv_reader_src") {
"../src/reader/spirv/parser_impl_module_var_test.cc",
"../src/reader/spirv/parser_impl_named_types_test.cc",
"../src/reader/spirv/parser_impl_test.cc",
"../src/reader/spirv/parser_impl_test_helper.cc",
"../src/reader/spirv/parser_impl_test_helper.h",
"../src/reader/spirv/parser_impl_user_name_test.cc",
"../src/reader/spirv/parser_test.cc",
"../src/reader/spirv/spirv_tools_helpers_test.cc",

62
test/extract-spvasm.py Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/env python3
# 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.
# Extract SPIR-V assembly dumps from the output of
# tint_unittests --dump-spirv
# Writes each module to a distinct filename, which is a sanitized
# form of the test name, and with a ".spvasm" suffix.
#
# Usage:
# tint_unittests --dump-spirv | python3 extract-spvasm.py
import sys
import re
def extract():
test_name = ''
in_spirv = False
parts = []
for line in sys.stdin:
run_match = re.match('\[ RUN\s+\]\s+(\S+)', line)
if run_match:
test_name = run_match.group(1)
test_name = re.sub('[^0-9a-zA-Z]', '_', test_name) + '.spvasm'
elif re.match('BEGIN ConvertedOk', line):
parts = []
in_spirv = True
elif re.match('END ConvertedOk', line):
with open(test_name, 'w') as f:
f.write('; Test: ' + test_name + '\n')
for l in parts:
f.write(l)
f.close()
elif in_spirv:
parts.append(line)
def main(argv):
if '--help' in argv or '-h' in argv:
print('Extract SPIR-V from the output of tint_unittests --dump-spirv\n')
print('Usage:\n tint_unittests --dump-spirv | python3 extract-spvasm.py\n')
print('Writes each module to a distinct filename, which is a sanitized')
print('form of the test name, and with a ".spvasm" suffix.')
return 1
else:
extract()
return 0
if __name__ == '__main__':
exit(main(sys.argv[1:]))

View File

@@ -21,14 +21,15 @@ TEXT_GREEN="\033[0;32m"
TEXT_RED="\033[0;31m"
TEXT_DEFAULT="\033[0m"
TINT=$1
TINT="$1"
SUBDIR="$2"
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>"
echo "Usage: test-all.sh <path-to-tint-executable> [<subdir-with-more-samples>]"
exit 1
fi
@@ -54,7 +55,7 @@ function should_skip() {
# check(TEST_FILE, FORMAT)
function check() {
local TEST_FILE=$1
local TEST_FILE="$1"
local FORMAT=$2
SKIP=
@@ -69,7 +70,7 @@ function check() {
return
fi
set +e
${TINT} ${SCRIPT_DIR}/${TEST_FILE} --format ${FORMAT} -o /dev/null
"${TINT}" ${SCRIPT_DIR}/${TEST_FILE} --format ${FORMAT} -o /dev/null
if [ $? -eq 0 ]; then
echo -e "${TEXT_GREEN}PASS${TEXT_DEFAULT}"
NUM_PASS=$((${NUM_PASS}+1))
@@ -80,21 +81,34 @@ function check() {
set -e
}
for TEST_FILE in ${SCRIPT_DIR}/*.spvasm ${SCRIPT_DIR}/*.wgsl
do
# 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..."
echo "Testing ${TEST_FILE}..."
check "${TEST_FILE}" wgsl
check "${TEST_FILE}" spirv
check "${TEST_FILE}" msl
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}"/*;
do
check_formats "$F"
done
fi
if [ ${NUM_FAIL} -ne 0 ]; then
echo
echo -e "${TEXT_RED}${NUM_FAIL} tests failed. ${TEXT_DEFAULT}${NUM_SKIP} skipped. ${NUM_PASS} passed.${TEXT_DEFAULT}"