From e6ea63cdfdadc6981af18b868b77015de79029e7 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 5 Dec 2017 10:25:04 +0100 Subject: [PATCH] Add some convenience scripts for running tests. --- .gitignore | 1 + README.md | 34 +++++++++++++++++--- checkout_glslang_spirv_tools.sh | 57 +++++++++++++++++++++++++++++++++ test_shaders.sh | 15 +++++++++ update_test_shaders.sh | 15 +++++++++ 5 files changed, 117 insertions(+), 5 deletions(-) create mode 100755 checkout_glslang_spirv_tools.sh create mode 100755 test_shaders.sh create mode 100755 update_test_shaders.sh diff --git a/.gitignore b/.gitignore index 206279ae..b89f7297 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,6 @@ *.shader *.a *.bc +/external !CMakeLists.txt diff --git a/README.md b/README.md index 2a4f484c..e1409a4b 100644 --- a/README.md +++ b/README.md @@ -264,12 +264,36 @@ Contributions to SPIRV-Cross are welcome. See Testing and Licensing sections for SPIRV-Cross maintains a test suite of shaders with reference output of how the output looks after going through a roundtrip through glslangValidator then back through SPIRV-Cross again. The reference files are stored inside the repository in order to be able to track regressions. -All pull requests should ensure that test output does not change unexpectedly. This can be tested with `./test_shaders.py shaders`. -However, when improving SPIRV-Cross there are of course legitimate cases where reference output should change. -In these cases, run `./test_shaders.py shaders --update` to update the reference files and include these changes as part of the pull request. -Always make sure you are running up to date glslangValidator as well as SPIRV-Tools when updating reference files. +All pull requests should ensure that test output does not change unexpectedly. This can be tested with: -In short, the master branch should always be able to run `./test_shaders.py shaders` without failure. +``` +./test_shaders.py shaders +./test_shaders.py shaders --opt +./test_shaders.py shaders-hlsl --hlsl +./test_shaders.py shaders-hlsl --hlsl --opt +./test_shaders.py shaders-msl --msl +./test_shaders.py shaders-msl --msl --opt +``` + +although there are a couple of convenience script for doing this: + +``` +./checkout_glslang_spirv_tools.sh # Checks out glslang and SPIRV-Tools at a fixed revision which matches the reference output. +./test_shaders.sh # Runs over all changes and makes sure that there are no deltas compared to reference files. +``` + +However, when improving SPIRV-Cross there are of course legitimate cases where reference output should change. +In these cases, run: + +``` +./update_test_shaders.sh +``` + +to update the reference files and include these changes as part of the pull request. +Always make sure you are running the correct version of glslangValidator as well as SPIRV-Tools when updating reference files. +See `checkout_glslang_spirv_tools.sh`. + +In short, the master branch should always be able to run `./test_shaders.py shaders` and friends without failure. SPIRV-Cross uses Travis CI to test all pull requests, so it is not strictly needed to perform testing yourself if you have problems running it locally. A pull request which does not pass testing on Travis will not be accepted however. diff --git a/checkout_glslang_spirv_tools.sh b/checkout_glslang_spirv_tools.sh new file mode 100755 index 00000000..abc5a586 --- /dev/null +++ b/checkout_glslang_spirv_tools.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +GLSLANG_REV=698bf7547a96b6feb7291e8ddc0d5d16475dbae2 +SPIRV_TOOLS_REV=e28edd458b729da7bbfd51e375feb33103709e6f + +if [ -d external/glslang ]; then + echo "Updating glslang to revision $GLSLANG_REV." + cd external/glslang + git fetch origin + git checkout $GLSLANG_REV +else + echo "Cloning glslang revision $GLSLANG_REV." + mkdir -p external + cd external + git clone git://github.com/KhronosGroup/glslang.git + cd glslang + git checkout $GLSLANG_REV +fi +cd ../.. + +echo "Building glslang." +mkdir -p external/glslang-build +cd external/glslang-build +cmake ../glslang -DCMAKE_BUILD_TYPE=Release +make -j$(nproc) +cd ../.. + +if [ -d external/spirv-tools ]; then + echo "Updating SPIRV-Tools to revision $SPIRV_TOOLS_REV." + cd external/spirv-tools + git fetch origin + git checkout $SPIRV_TOOLS_REV +else + echo "Cloning SPIRV-Tools revision $SPIRV_TOOLS_REV." + mkdir -p external + cd external + git clone git://github.com/KhronosGroup/SPIRV-Tools.git spirv-tools + cd spirv-tools + git checkout $SPIRV_TOOLS_REV + + if [ -d external/spirv-headers ]; then + cd external/spirv-headers + git pull origin master + cd ../.. + else + git clone git://github.com/KhronosGroup/SPIRV-Headers.git external/spirv-headers + fi +fi +cd ../.. + +echo "Building SPIRV-Tools." +mkdir -p external/spirv-tools-build +cd external/spirv-tools-build +cmake ../spirv-tools -DCMAKE_BUILD_TYPE=Release +make -j$(nproc) +cd ../.. + diff --git a/test_shaders.sh b/test_shaders.sh new file mode 100755 index 00000000..fd24fb7c --- /dev/null +++ b/test_shaders.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +echo "Building spirv-cross" +make -j$(nproc) + +export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/tools:$PATH" +echo "Using glslangValidation in: $(which glslangValidator)." +echo "Using spirv-opt in: $(which spirv-opt)." + +./test_shaders.py shaders +./test_shaders.py shaders --opt +./test_shaders.py shaders-msl --msl +./test_shaders.py shaders-msl --msl --opt +./test_shaders.py shaders-hlsl --hlsl +./test_shaders.py shaders-hlsl --hlsl --opt diff --git a/update_test_shaders.sh b/update_test_shaders.sh new file mode 100755 index 00000000..c858a260 --- /dev/null +++ b/update_test_shaders.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +echo "Building spirv-cross" +make -j$(nproc) + +export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/tools:$PATH" +echo "Using glslangValidation in: $(which glslangValidator)." +echo "Using spirv-opt in: $(which spirv-opt)." + +./test_shaders.py shaders --update +./test_shaders.py shaders --update --opt +./test_shaders.py shaders-msl --msl --update +./test_shaders.py shaders-msl --msl --update --opt +./test_shaders.py shaders-hlsl --hlsl --update +./test_shaders.py shaders-hlsl --hlsl --update --opt