2 // Copyright (C) 2016 Google, Inc.
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
10 // Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
13 // Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
18 // Neither the name of Google Inc. nor the names of its
19 // contributors may be used to endorse or promote products derived
20 // from this software without specific prior written permission.
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
35 #ifndef GLSLANG_GTESTS_TEST_FIXTURE_H
36 #define GLSLANG_GTESTS_TEST_FIXTURE_H
45 #include <gtest/gtest.h>
47 #include "SPIRV/GlslangToSpv.h"
48 #include "SPIRV/disassemble.h"
49 #include "SPIRV/doc.h"
50 #include "SPIRV/SPVRemapper.h"
51 #include "glslang/Public/ResourceLimits.h"
52 #include "glslang/Public/ShaderLang.h"
54 #include "Initializer.h"
57 namespace glslangtest {
59 // This function is used to provide custom test name suffixes based on the
60 // shader source file names. Otherwise, the test name suffixes will just be
61 // numbers, which are not quite obvious.
62 std::string FileNameAsCustomTestSuffix(
63 const ::testing::TestParamInfo<std::string>& info);
70 // Enum for shader compilation semantics.
71 enum class Semantics {
76 // Enum for compilation target.
83 EShLanguage GetShaderStage(const std::string& stage);
85 EShMessages DeriveOptions(Source, Semantics, Target);
87 // Reads the content of the file at the given |path|. On success, returns true
88 // and the contents; otherwise, returns false and an empty string.
89 std::pair<bool, std::string> ReadFile(const std::string& path);
90 std::pair<bool, std::vector<std::uint32_t> > ReadSpvBinaryFile(const std::string& path);
92 // Writes the given |contents| into the file at the given |path|. Returns true
93 // on successful output.
94 bool WriteFile(const std::string& path, const std::string& contents);
96 // Returns the suffix of the given |name|.
97 std::string GetSuffix(const std::string& name);
99 // Base class for glslang integration tests. It contains many handy utility-like
100 // methods such as reading shader source files, compiling into AST/SPIR-V, and
101 // comparing with expected outputs.
103 // To write value-Parameterized tests:
104 // using ValueParamTest = GlslangTest<::testing::TestWithParam<std::string>>;
105 // To use as normal fixture:
106 // using FixtureTest = GlslangTest<::testing::Test>;
107 template <typename GT>
108 class GlslangTest : public GT {
111 : defaultVersion(100),
112 defaultProfile(ENoProfile),
113 forceVersionProfile(false),
114 isForwardCompatible(false) {
115 // Perform validation by default.
116 spirvOptions.validate = true;
119 // Tries to load the contents from the file at the given |path|. On success,
120 // writes the contents into |contents|. On failure, errors out.
121 void tryLoadFile(const std::string& path, const std::string& tag,
122 std::string* contents)
125 std::tie(fileReadOk, *contents) = ReadFile(path);
126 ASSERT_TRUE(fileReadOk) << "Cannot open " << tag << " file: " << path;
129 // Tries to load the contents from the file at the given |path|. On success,
130 // writes the contents into |contents|. On failure, errors out.
131 void tryLoadSpvFile(const std::string& path, const std::string& tag,
132 std::vector<uint32_t>& contents)
135 std::tie(fileReadOk, contents) = ReadSpvBinaryFile(path);
136 ASSERT_TRUE(fileReadOk) << "Cannot open " << tag << " file: " << path;
139 // Checks the equality of |expected| and |real|. If they are not equal,
140 // write |real| to the given file named as |fname| if update mode is on.
141 void checkEqAndUpdateIfRequested(const std::string& expected,
142 const std::string& real,
143 const std::string& fname,
144 const std::string& errorsAndWarnings = "")
146 // In order to output the message we want under proper circumstances,
147 // we need the following operator<< stuff.
148 EXPECT_EQ(expected, real)
149 << (GlobalTestSettings.updateMode
150 ? ("Mismatch found and update mode turned on - "
151 "flushing expected result output.\n")
153 << "The following warnings/errors occurred:\n"
154 << errorsAndWarnings;
156 // Update the expected output file if requested.
157 // It looks weird to duplicate the comparison between expected_output
158 // and stream.str(). However, if creating a variable for the comparison
159 // result, we cannot have pretty print of the string diff in the above.
160 if (GlobalTestSettings.updateMode && expected != real) {
161 EXPECT_TRUE(WriteFile(fname, real)) << "Flushing failed";
165 struct ShaderResult {
166 std::string shaderName;
171 // A struct for holding all the information returned by glslang compilation
173 struct GlslangResult {
174 std::vector<ShaderResult> shaderResults;
175 std::string linkingOutput;
176 std::string linkingError;
177 bool validationResult;
178 std::string spirvWarningsErrors;
179 std::string spirv; // Optional SPIR-V disassembly text.
182 // Compiles and the given source |code| of the given shader |stage| into
183 // the target under the semantics conveyed via |controls|. Returns true
184 // and modifies |shader| on success.
185 bool compile(glslang::TShader* shader, const std::string& code,
186 const std::string& entryPointName, EShMessages controls,
187 const TBuiltInResource* resources=nullptr,
188 const std::string* shaderName=nullptr)
190 const char* shaderStrings = code.data();
191 const int shaderLengths = static_cast<int>(code.size());
192 const char* shaderNames = nullptr;
194 if ((controls & EShMsgDebugInfo) && shaderName != nullptr) {
195 shaderNames = shaderName->data();
196 shader->setStringsWithLengthsAndNames(
197 &shaderStrings, &shaderLengths, &shaderNames, 1);
199 shader->setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
200 if (!entryPointName.empty()) shader->setEntryPoint(entryPointName.c_str());
201 return shader->parse(
202 (resources ? resources : GetDefaultResources()),
203 defaultVersion, isForwardCompatible, controls);
206 // Compiles and links the given source |code| of the given shader
207 // |stage| into the target under the semantics specified via |controls|.
208 // Returns a GlslangResult instance containing all the information generated
209 // during the process. If the target includes SPIR-V, also disassembles
210 // the result and returns disassembly text.
211 GlslangResult compileAndLink(
212 const std::string& shaderName, const std::string& code,
213 const std::string& entryPointName, EShMessages controls,
214 glslang::EShTargetClientVersion clientTargetVersion,
215 glslang::EShTargetLanguageVersion targetLanguageVersion,
216 bool flattenUniformArrays = false,
217 EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep,
218 bool enableOptimizer = false,
219 bool enableDebug = false,
220 bool enableNonSemanticShaderDebugInfo = false,
223 const EShLanguage stage = GetShaderStage(GetSuffix(shaderName));
225 glslang::TShader shader(stage);
227 shader.setAutoMapLocations(true);
228 shader.setAutoMapBindings(true);
230 shader.setTextureSamplerTransformMode(texSampTransMode);
232 shader.setFlattenUniformArrays(flattenUniformArrays);
235 if (controls & EShMsgSpvRules) {
236 if (controls & EShMsgVulkanRules) {
237 shader.setEnvInput((controls & EShMsgReadHlsl) ? glslang::EShSourceHlsl
238 : glslang::EShSourceGlsl,
239 stage, glslang::EShClientVulkan, 100);
240 shader.setEnvClient(glslang::EShClientVulkan, clientTargetVersion);
241 shader.setEnvTarget(glslang::EShTargetSpv, targetLanguageVersion);
243 shader.setEnvInput((controls & EShMsgReadHlsl) ? glslang::EShSourceHlsl
244 : glslang::EShSourceGlsl,
245 stage, glslang::EShClientOpenGL, 100);
246 shader.setEnvClient(glslang::EShClientOpenGL, clientTargetVersion);
247 shader.setEnvTarget(glslang::EshTargetSpv, glslang::EShTargetSpv_1_0);
251 bool success = compile(
252 &shader, code, entryPointName, controls, nullptr, &shaderName);
254 glslang::TProgram program;
255 program.addShader(&shader);
256 success &= program.link(controls);
257 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
262 if (success && (controls & EShMsgSpvRules)) {
263 spv::SpvBuildLogger logger;
264 std::vector<uint32_t> spirv_binary;
265 options().disableOptimizer = !enableOptimizer;
266 options().generateDebugInfo = enableDebug;
267 options().emitNonSemanticShaderDebugInfo = enableNonSemanticShaderDebugInfo;
268 options().emitNonSemanticShaderDebugSource = enableNonSemanticShaderDebugInfo;
269 glslang::GlslangToSpv(*program.getIntermediate(stage),
270 spirv_binary, &logger, &options());
272 std::ostringstream disassembly_stream;
274 spv::Disassemble(disassembly_stream, spirv_binary);
275 bool validation_result = !options().validate || logger.getAllMessages().empty();
276 return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
277 program.getInfoLog(), program.getInfoDebugLog(),
278 validation_result, logger.getAllMessages(), disassembly_stream.str()};
280 return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
281 program.getInfoLog(), program.getInfoDebugLog(), true, "", ""};
285 // Compiles and links the given source |code| of the given shader
286 // |stage| into the target under the semantics specified via |controls|.
287 // Returns a GlslangResult instance containing all the information generated
288 // during the process. If the target includes SPIR-V, also disassembles
289 // the result and returns disassembly text.
290 GlslangResult compileLinkIoMap(
291 const std::string shaderName, const std::string& code,
292 const std::string& entryPointName, EShMessages controls,
293 int baseSamplerBinding,
294 int baseTextureBinding,
295 int baseImageBinding,
298 bool autoMapBindings,
299 bool flattenUniformArrays)
301 const EShLanguage stage = GetShaderStage(GetSuffix(shaderName));
303 glslang::TShader shader(stage);
304 shader.setShiftSamplerBinding(baseSamplerBinding);
305 shader.setShiftTextureBinding(baseTextureBinding);
306 shader.setShiftImageBinding(baseImageBinding);
307 shader.setShiftUboBinding(baseUboBinding);
308 shader.setShiftSsboBinding(baseSsboBinding);
309 shader.setAutoMapBindings(autoMapBindings);
310 shader.setAutoMapLocations(true);
312 shader.setFlattenUniformArrays(flattenUniformArrays);
315 bool success = compile(&shader, code, entryPointName, controls);
317 glslang::TProgram program;
318 program.addShader(&shader);
320 success &= program.link(controls);
321 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
326 spv::SpvBuildLogger logger;
328 if (success && (controls & EShMsgSpvRules)) {
329 std::vector<uint32_t> spirv_binary;
330 glslang::GlslangToSpv(*program.getIntermediate(stage),
331 spirv_binary, &logger, &options());
333 std::ostringstream disassembly_stream;
335 spv::Disassemble(disassembly_stream, spirv_binary);
336 bool validation_result = !options().validate || logger.getAllMessages().empty();
337 return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
338 program.getInfoLog(), program.getInfoDebugLog(),
339 validation_result, logger.getAllMessages(), disassembly_stream.str()};
341 return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
342 program.getInfoLog(), program.getInfoDebugLog(), true, "", ""};
346 // This is like compileAndLink but with remapping of the SPV binary
347 // through spirvbin_t::remap(). While technically this could be merged
348 // with compileAndLink() above (with the remap step optionally being a no-op)
349 // it is given separately here for ease of future extraction.
350 GlslangResult compileLinkRemap(
351 const std::string shaderName, const std::string& code,
352 const std::string& entryPointName, EShMessages controls,
353 const unsigned int remapOptions = spv::spirvbin_t::NONE)
355 const EShLanguage stage = GetShaderStage(GetSuffix(shaderName));
357 glslang::TShader shader(stage);
358 shader.setAutoMapBindings(true);
359 shader.setAutoMapLocations(true);
361 bool success = compile(&shader, code, entryPointName, controls);
363 glslang::TProgram program;
364 program.addShader(&shader);
365 success &= program.link(controls);
366 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
371 if (success && (controls & EShMsgSpvRules)) {
372 spv::SpvBuildLogger logger;
373 std::vector<std::string> whiteListStrings;
374 std::vector<uint32_t> spirv_binary;
375 glslang::GlslangToSpv(*program.getIntermediate(stage),
376 spirv_binary, &logger, &options());
378 spv::spirvbin_t(0 /*verbosity*/).remap(spirv_binary, whiteListStrings, remapOptions);
380 std::ostringstream disassembly_stream;
382 spv::Disassemble(disassembly_stream, spirv_binary);
383 bool validation_result = !options().validate || logger.getAllMessages().empty();
384 return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
385 program.getInfoLog(), program.getInfoDebugLog(),
386 validation_result, logger.getAllMessages(), disassembly_stream.str()};
388 return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
389 program.getInfoLog(), program.getInfoDebugLog(), true, "", ""};
393 // remap the binary in 'code' with the options in remapOptions
395 const std::string shaderName, const std::vector<uint32_t>& code,
396 EShMessages controls,
397 const unsigned int remapOptions = spv::spirvbin_t::NONE)
399 if ((controls & EShMsgSpvRules)) {
400 std::vector<uint32_t> spirv_binary(code); // scratch copy
401 std::vector<std::string> whiteListStrings;
402 spv::spirvbin_t(0 /*verbosity*/).remap(spirv_binary, whiteListStrings, remapOptions);
404 std::ostringstream disassembly_stream;
406 spv::Disassemble(disassembly_stream, spirv_binary);
408 return {{{shaderName, "", ""},},
410 true, "", disassembly_stream.str()};
412 return {{{shaderName, "", ""},}, "", "", true, "", ""};
416 void outputResultToStream(std::ostringstream* stream,
417 const GlslangResult& result,
418 EShMessages controls)
420 const auto outputIfNotEmpty = [&stream](const std::string& str) {
421 if (!str.empty()) *stream << str << "\n";
424 for (const auto& shaderResult : result.shaderResults) {
425 *stream << shaderResult.shaderName << "\n";
426 outputIfNotEmpty(shaderResult.output);
427 outputIfNotEmpty(shaderResult.error);
429 outputIfNotEmpty(result.linkingOutput);
430 outputIfNotEmpty(result.linkingError);
431 if (!result.validationResult) {
432 *stream << "Validation failed\n";
435 if (controls & EShMsgSpvRules) {
437 << (result.spirv.empty()
438 ? "SPIR-V is not generated for failed compile or link\n"
443 void loadFileCompileAndCheck(const std::string& testDir,
444 const std::string& testName,
447 glslang::EShTargetClientVersion clientTargetVersion,
448 glslang::EShTargetLanguageVersion targetLanguageVersion,
451 const std::string& entryPointName="",
452 const std::string& baseDir="/baseResults/",
453 const bool enableOptimizer = false,
454 const bool enableDebug = false,
455 const bool enableNonSemanticShaderDebugInfo = false)
457 const std::string inputFname = testDir + "/" + testName;
458 const std::string expectedOutputFname =
459 testDir + baseDir + testName + ".out";
460 std::string input, expectedOutput;
462 tryLoadFile(inputFname, "input", &input);
463 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
465 EShMessages controls = DeriveOptions(source, semantics, target);
467 controls = static_cast<EShMessages>(controls & ~EShMsgHlslLegalization);
469 controls = static_cast<EShMessages>(controls | EShMsgDebugInfo);
470 GlslangResult result = compileAndLink(testName, input, entryPointName, controls, clientTargetVersion,
471 targetLanguageVersion, false, EShTexSampTransKeep, enableOptimizer, enableDebug,
472 enableNonSemanticShaderDebugInfo, automap);
474 // Generate the hybrid output in the way of glslangValidator.
475 std::ostringstream stream;
476 outputResultToStream(&stream, result, controls);
478 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
479 expectedOutputFname, result.spirvWarningsErrors);
482 void loadFileCompileAndCheckWithOptions(const std::string &testDir,
483 const std::string &testName,
486 glslang::EShTargetClientVersion clientTargetVersion,
487 glslang::EShTargetLanguageVersion targetLanguageVersion,
488 Target target, bool automap = true, const std::string &entryPointName = "",
489 const std::string &baseDir = "/baseResults/",
490 const EShMessages additionalOptions = EShMessages::EShMsgDefault)
492 const std::string inputFname = testDir + "/" + testName;
493 const std::string expectedOutputFname = testDir + baseDir + testName + ".out";
494 std::string input, expectedOutput;
496 tryLoadFile(inputFname, "input", &input);
497 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
499 EShMessages controls = DeriveOptions(source, semantics, target);
500 controls = static_cast<EShMessages>(controls | additionalOptions);
501 GlslangResult result = compileAndLink(testName, input, entryPointName, controls, clientTargetVersion,
502 targetLanguageVersion, false, EShTexSampTransKeep, false, automap);
504 // Generate the hybrid output in the way of glslangValidator.
505 std::ostringstream stream;
506 outputResultToStream(&stream, result, controls);
508 checkEqAndUpdateIfRequested(expectedOutput, stream.str(), expectedOutputFname);
511 void loadFileCompileFlattenUniformsAndCheck(const std::string& testDir,
512 const std::string& testName,
516 const std::string& entryPointName="")
518 const std::string inputFname = testDir + "/" + testName;
519 const std::string expectedOutputFname =
520 testDir + "/baseResults/" + testName + ".out";
521 std::string input, expectedOutput;
523 tryLoadFile(inputFname, "input", &input);
524 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
526 const EShMessages controls = DeriveOptions(source, semantics, target);
527 GlslangResult result = compileAndLink(testName, input, entryPointName, controls,
528 glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0, true);
530 // Generate the hybrid output in the way of glslangValidator.
531 std::ostringstream stream;
532 outputResultToStream(&stream, result, controls);
534 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
535 expectedOutputFname, result.spirvWarningsErrors);
538 void loadFileCompileIoMapAndCheck(const std::string& testDir,
539 const std::string& testName,
543 const std::string& entryPointName,
544 int baseSamplerBinding,
545 int baseTextureBinding,
546 int baseImageBinding,
549 bool autoMapBindings,
550 bool flattenUniformArrays)
552 const std::string inputFname = testDir + "/" + testName;
553 const std::string expectedOutputFname =
554 testDir + "/baseResults/" + testName + ".out";
555 std::string input, expectedOutput;
557 tryLoadFile(inputFname, "input", &input);
558 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
560 const EShMessages controls = DeriveOptions(source, semantics, target);
561 GlslangResult result = compileLinkIoMap(testName, input, entryPointName, controls,
562 baseSamplerBinding, baseTextureBinding, baseImageBinding,
563 baseUboBinding, baseSsboBinding,
565 flattenUniformArrays);
567 // Generate the hybrid output in the way of glslangValidator.
568 std::ostringstream stream;
569 outputResultToStream(&stream, result, controls);
571 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
572 expectedOutputFname, result.spirvWarningsErrors);
575 void loadFileCompileRemapAndCheck(const std::string& testDir,
576 const std::string& testName,
580 const std::string& entryPointName="",
581 const unsigned int remapOptions = spv::spirvbin_t::NONE)
583 const std::string inputFname = testDir + "/" + testName;
584 const std::string expectedOutputFname =
585 testDir + "/baseResults/" + testName + ".out";
586 std::string input, expectedOutput;
588 tryLoadFile(inputFname, "input", &input);
589 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
591 const EShMessages controls = DeriveOptions(source, semantics, target);
592 GlslangResult result = compileLinkRemap(testName, input, entryPointName, controls, remapOptions);
594 // Generate the hybrid output in the way of glslangValidator.
595 std::ostringstream stream;
596 outputResultToStream(&stream, result, controls);
598 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
599 expectedOutputFname, result.spirvWarningsErrors);
602 void loadFileRemapAndCheck(const std::string& testDir,
603 const std::string& testName,
607 const unsigned int remapOptions = spv::spirvbin_t::NONE)
609 const std::string inputFname = testDir + "/" + testName;
610 const std::string expectedOutputFname =
611 testDir + "/baseResults/" + testName + ".out";
612 std::vector<std::uint32_t> input;
613 std::string expectedOutput;
615 tryLoadSpvFile(inputFname, "input", input);
616 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
618 const EShMessages controls = DeriveOptions(source, semantics, target);
619 GlslangResult result = remap(testName, input, controls, remapOptions);
621 // Generate the hybrid output in the way of glslangValidator.
622 std::ostringstream stream;
623 outputResultToStream(&stream, result, controls);
625 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
626 expectedOutputFname, result.spirvWarningsErrors);
629 // Preprocesses the given |source| code. On success, returns true, the
630 // preprocessed shader, and warning messages. Otherwise, returns false, an
631 // empty string, and error messages.
632 std::tuple<bool, std::string, std::string> preprocess(
633 const std::string& source)
635 const char* shaderStrings = source.data();
636 const int shaderLengths = static_cast<int>(source.size());
638 glslang::TShader shader(EShLangVertex);
639 shader.setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
640 std::string ppShader;
641 glslang::TShader::ForbidIncluder includer;
642 const bool success = shader.preprocess(
643 GetDefaultResources(), defaultVersion, defaultProfile,
644 forceVersionProfile, isForwardCompatible, (EShMessages)(EShMsgOnlyPreprocessor | EShMsgCascadingErrors),
645 &ppShader, includer);
647 std::string log = shader.getInfoLog();
648 log += shader.getInfoDebugLog();
650 return std::make_tuple(true, ppShader, log);
652 return std::make_tuple(false, "", log);
656 void loadFilePreprocessAndCheck(const std::string& testDir,
657 const std::string& testName)
659 const std::string inputFname = testDir + "/" + testName;
660 const std::string expectedOutputFname =
661 testDir + "/baseResults/" + testName + ".out";
662 const std::string expectedErrorFname =
663 testDir + "/baseResults/" + testName + ".err";
664 std::string input, expectedOutput, expectedError;
666 tryLoadFile(inputFname, "input", &input);
667 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
668 tryLoadFile(expectedErrorFname, "expected error", &expectedError);
671 std::string output, error;
672 std::tie(ppOk, output, error) = preprocess(input);
673 if (!output.empty()) output += '\n';
674 if (!error.empty()) error += '\n';
676 checkEqAndUpdateIfRequested(expectedOutput, output,
677 expectedOutputFname);
678 checkEqAndUpdateIfRequested(expectedError, error,
682 void loadCompileUpgradeTextureToSampledTextureAndDropSamplersAndCheck(const std::string& testDir,
683 const std::string& testName,
687 const std::string& entryPointName = "")
689 const std::string inputFname = testDir + "/" + testName;
690 const std::string expectedOutputFname = testDir + "/baseResults/" + testName + ".out";
691 std::string input, expectedOutput;
693 tryLoadFile(inputFname, "input", &input);
694 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
696 const EShMessages controls = DeriveOptions(source, semantics, target);
697 GlslangResult result = compileAndLink(testName, input, entryPointName, controls,
698 glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0, false,
699 EShTexSampTransUpgradeTextureRemoveSampler);
701 // Generate the hybrid output in the way of glslangValidator.
702 std::ostringstream stream;
703 outputResultToStream(&stream, result, controls);
705 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
706 expectedOutputFname, result.spirvWarningsErrors);
709 glslang::SpvOptions& options() { return spirvOptions; }
712 const int defaultVersion;
713 const EProfile defaultProfile;
714 const bool forceVersionProfile;
715 const bool isForwardCompatible;
716 glslang::SpvOptions spirvOptions;
719 } // namespace glslangtest
721 #endif // GLSLANG_GTESTS_TEST_FIXTURE_H