TEST_P(CompileToAstTest, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::OpenGL,
Target::AST);
}
TEST_F(DefaultResourceTest, FromFile)
{
- const std::string path = GLSLANG_TEST_DIRECTORY "/baseResults/test.conf";
+ const std::string path = GlobalTestSettings.testRoot + "/baseResults/test.conf";
std::string expectedConfig;
tryLoadFile(path, "expected resource limit", &expectedConfig);
const std::string realConfig = glslang::GetDefaultTBuiltInResourceString();
install(TARGETS glslangtests
RUNTIME DESTINATION bin)
+ set(GLSLANG_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Test")
+ # Supply a default test root directory, so that manual testing
+ # doesn't have to specify the --test-root option in the normal
+ # case that you want to use the tests from the same source tree.
target_compile_definitions(glslangtests
- PRIVATE GLSLANG_TEST_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/../Test")
+ PRIVATE GLSLANG_TEST_DIRECTORY="${GLSLANG_TEST_DIRECTORY}")
target_include_directories(glslangtests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}
target_link_libraries(glslangtests PRIVATE
SPVRemapper glslang OSDependent OGLCompiler HLSL glslang
SPIRV glslang-default-resource-limits gmock)
- add_test(NAME glslang-gtests COMMAND glslangtests)
+ add_test(NAME glslang-gtests
+ COMMAND glslangtests --test-root "${GLSLANG_TEST_DIRECTORY}")
endif()
// Get the contents for input shader and limit configurations.
std::string shaderContents, configContents;
- tryLoadFile(GLSLANG_TEST_DIRECTORY "/" + testCase.input, "input", &shaderContents);
- tryLoadFile(GLSLANG_TEST_DIRECTORY "/" + testCase.config, "limits config", &configContents);
+ tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.input, "input", &shaderContents);
+ tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.config, "limits config", &configContents);
// Decode limit configurations.
TBuiltInResource resources = {};
// Check with expected results.
const std::string expectedOutputFname =
- GLSLANG_TEST_DIRECTORY "/baseResults/" + testCase.output;
+ GlobalTestSettings.testRoot + "/baseResults/" + testCase.output;
std::string expectedOutput;
tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
// generate both AST and SPIR-V.
TEST_P(HlslCompileTest, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan,
Target::BothASTAndSpv, GetParam().entryPoint);
}
TEST_P(HlslCompileAndFlattenTest, FromFile)
{
- loadFileCompileFlattenUniformsAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
+ loadFileCompileFlattenUniformsAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan,
Target::BothASTAndSpv, GetParam().entryPoint);
}
std::vector<std::unique_ptr<glslang::TShader>> shaders;
for (size_t i = 0; i < fileCount; ++i) {
std::string contents;
- tryLoadFile(GLSLANG_TEST_DIRECTORY "/" + fileNames[i],
+ tryLoadFile(GlobalTestSettings.testRoot + "/" + fileNames[i],
"input", &contents);
shaders.emplace_back(
new glslang::TShader(GetShaderStage(GetSuffix(fileNames[i]))));
// Check with expected results.
const std::string expectedOutputFname =
- GLSLANG_TEST_DIRECTORY "/baseResults/" + fileNames.front() + ".out";
+ GlobalTestSettings.testRoot + "/baseResults/" + fileNames.front() + ".out";
std::string expectedOutput;
tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
TEST_P(PreprocessingTest, FromFile)
{
- loadFilePreprocessAndCheck(GLSLANG_TEST_DIRECTORY, GetParam());
+ loadFilePreprocessAndCheck(GlobalTestSettings.testRoot, GetParam());
}
// clang-format off
using RemapTest = GlslangTest<::testing::TestWithParam<RemapTestArgs>>;
-// Remapping SPIR-V modules.
+// Remapping SPIR-V modules.
TEST_P(RemapTest, FromFile)
{
if (GetSuffix(GetParam().fileName) == "spv") {
- loadFileRemapAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
+ loadFileRemapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
GetParam().sourceLanguage,
Semantics::Vulkan,
Target::Spv,
GetParam().remapOpts);
} else {
- loadFileCompileRemapAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
+ loadFileCompileRemapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
GetParam().sourceLanguage,
Semantics::Vulkan,
Target::Spv,
namespace glslangtest {
-GTestSettings GlobalTestSettings = {nullptr, false};
+// We need CMake to provide us the absolute path to the directory containing
+// test files, so we are certain to find those files no matter where the test
+// harness binary is generated. This provides out-of-source build capability.
+// This will be used as the default test root, but can be overridden with
+// the --test-root argument.
+#ifndef GLSLANG_TEST_DIRECTORY
+#error \
+ "GLSLANG_TEST_DIRECTORY needs to be defined for gtest to locate test files."
+#endif
+
+GTestSettings GlobalTestSettings = {nullptr, false, GLSLANG_TEST_DIRECTORY};
} // namespace glslangtest
#ifndef GLSLANG_GTESTS_SETTINGS_H
#define GLSLANG_GTESTS_SETTINGS_H
+#include <string>
+
namespace glslangtest {
class GlslangInitializer;
// An indicator of whether GTest should write real output to the file for
// the expected output.
bool updateMode;
+ // The root directory for test files.
+ std::string testRoot;
};
extern GTestSettings GlobalTestSettings;
// generate SPIR-V.
TEST_P(CompileVulkanToSpirvTest, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::Vulkan,
Target::Spv);
}
// generate SPIR-V.
TEST_P(CompileOpenGLToSpirvTest, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::OpenGL,
Target::Spv);
}
// SPIR-V.
TEST_P(VulkanSemantics, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::Vulkan,
Target::Spv);
}
// SPIR-V.
TEST_P(OpenGLSemantics, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::OpenGL,
Target::Spv);
}
// GLSL-level Vulkan semantics test that need to see the AST for validation.
TEST_P(VulkanAstSemantics, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::Vulkan,
Target::AST);
}
// HLSL-level Vulkan semantics tests.
TEST_P(HlslIoMap, FromFile)
{
- loadFileCompileIoMapAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
+ loadFileCompileIoMapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan,
Target::Spv, GetParam().entryPoint,
GetParam().baseSamplerBinding,
// GLSL-level Vulkan semantics tests.
TEST_P(GlslIoMap, FromFile)
{
- loadFileCompileIoMapAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
+ loadFileCompileIoMapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::GLSL, Semantics::Vulkan,
Target::Spv, GetParam().entryPoint,
GetParam().baseSamplerBinding,
// Expected to successfully generate SPIR-V.
TEST_P(CompileVulkanToSpirvTestAMD, FromFile)
{
- loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
+ loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
Source::GLSL, Semantics::Vulkan,
Target::Spv);
}
#include "Initializer.h"
#include "Settings.h"
-// We need CMake to provide us the absolute path to the directory containing
-// test files, so we are certain to find those files no matter where the test
-// harness binary is generated. This provides out-of-source build capability.
-#ifndef GLSLANG_TEST_DIRECTORY
-#error \
- "GLSLANG_TEST_DIRECTORY needs to be defined for gtest to locate test files."
-#endif
-
namespace glslangtest {
// This function is used to provide custom test name suffixes based on the
// POSSIBILITY OF SUCH DAMAGE.
#include <memory>
+#include <string>
#include <gtest/gtest.h>
glslangtest::GlobalTestSettings.initializer = initializer.get();
for (int i = 1; i < argc; ++i) {
- if (!strncmp("--update-mode", argv[i], 13)) {
+ if (std::string("--update-mode") == argv[i]) {
glslangtest::GlobalTestSettings.updateMode = true;
- break;
+ }
+ if (std::string("--test-root") == argv[i]) {
+ // Allow the user set the tets root directory. This is useful
+ // for testing with files from another source tree.
+ if (i + 1 < argc) {
+ glslangtest::GlobalTestSettings.testRoot = argv[i + 1];
+ i++;
+ } else {
+ printf("error: --test-root requires an argument\n");
+ return 1;
+ }
}
}