1 //
2 // Copyright (C) 2016 Google, Inc.
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
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.
17 //
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.
21 //
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.
34
35 #include "glslang/Public/ResourceLimits.h"
36 #include "TestFixture.h"
37
38 namespace glslangtest {
39 namespace {
40
41 struct TestCaseSpec {
42 std::string input;
43 std::string config;
44 std::string output;
45 EShMessages controls;
46 };
47
48 using ConfigTest = GlslangTest<::testing::TestWithParam<TestCaseSpec>>;
49
TEST_P(ConfigTest,FromFile)50 TEST_P(ConfigTest, FromFile)
51 {
52 TestCaseSpec testCase = GetParam();
53 GlslangResult result;
54 result.validationResult = true;
55
56 // Get the contents for input shader and limit configurations.
57 std::string shaderContents, configContents;
58 tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.input, "input", &shaderContents);
59 tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.config, "limits config", &configContents);
60
61 // Decode limit configurations.
62 TBuiltInResource resources = {};
63 {
64 const size_t len = configContents.size();
65 char* configChars = new char[len + 1];
66 memcpy(configChars, configContents.data(), len);
67 configChars[len] = 0;
68 DecodeResourceLimits(&resources, configChars);
69 delete[] configChars;
70 }
71
72 // Compile the shader.
73 glslang::TShader shader(GetShaderStage(GetSuffix(testCase.input)));
74 compile(&shader, shaderContents, "", testCase.controls, &resources);
75 result.shaderResults.push_back(
76 {testCase.input, shader.getInfoLog(), shader.getInfoDebugLog()});
77
78 // Link the shader.
79 glslang::TProgram program;
80 program.addShader(&shader);
81 program.link(testCase.controls);
82 result.linkingOutput = program.getInfoLog();
83 result.linkingError = program.getInfoDebugLog();
84
85 std::ostringstream stream;
86 outputResultToStream(&stream, result, testCase.controls);
87
88 // Check with expected results.
89 const std::string expectedOutputFname =
90 GlobalTestSettings.testRoot + "/baseResults/" + testCase.output;
91 std::string expectedOutput;
92 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
93
94 checkEqAndUpdateIfRequested(expectedOutput, stream.str(), expectedOutputFname);
95 }
96
97 // clang-format off
98 INSTANTIATE_TEST_SUITE_P(
99 Glsl, ConfigTest,
100 ::testing::ValuesIn(std::vector<TestCaseSpec>({
101 {"specExamples.vert", "baseResults/test.conf", "specExamplesConf.vert.out", (EShMessages)(EShMsgAST | EShMsgCascadingErrors)},
102 {"100Limits.vert", "100.conf", "100LimitsConf.vert.out", EShMsgCascadingErrors},
103 }))
104 );
105 // clang-format on
106
107 } // anonymous namespace
108 } // namespace glslangtest
109