blob: f3a27724d1fc4e0711fd54d50e9cb117cd32531e [file] [log] [blame]
Lei Zhang1b141722016-05-19 13:50:49 -04001//
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 "StandAlone/ResourceLimits.h"
36#include "TestFixture.h"
37
38namespace glslangtest {
39namespace {
40
41struct TestCaseSpec {
42 std::string input;
43 std::string config;
44 std::string output;
45 EShMessages controls;
46};
47
48using ConfigTest = GlslangTest<::testing::TestWithParam<TestCaseSpec>>;
49
50TEST_P(ConfigTest, FromFile)
51{
52 TestCaseSpec testCase = GetParam();
53 GlslangResult result;
54
55 // Get the contents for input shader and limit configurations.
56 std::string shaderContents, configContents;
David Neto1d3a9662016-10-05 10:25:09 -040057 tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.input, "input", &shaderContents);
58 tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.config, "limits config", &configContents);
Lei Zhang1b141722016-05-19 13:50:49 -040059
60 // Decode limit configurations.
61 TBuiltInResource resources = {};
62 {
63 const size_t len = configContents.size();
64 char* configChars = new char[len + 1];
65 memcpy(configChars, configContents.data(), len);
66 configChars[len] = 0;
67 glslang::DecodeResourceLimits(&resources, configChars);
68 delete[] configChars;
69 }
70
71 // Compile the shader.
72 glslang::TShader shader(GetShaderStage(GetSuffix(testCase.input)));
73 compile(&shader, shaderContents, "", testCase.controls, &resources);
74 result.shaderResults.push_back(
75 {testCase.input, shader.getInfoLog(), shader.getInfoDebugLog()});
76
77 // Link the shader.
78 glslang::TProgram program;
79 program.addShader(&shader);
80 program.link(testCase.controls);
81 result.linkingOutput = program.getInfoLog();
82 result.linkingError = program.getInfoDebugLog();
83
84 std::ostringstream stream;
85 outputResultToStream(&stream, result, testCase.controls);
86
87 // Check with expected results.
88 const std::string expectedOutputFname =
David Neto1d3a9662016-10-05 10:25:09 -040089 GlobalTestSettings.testRoot + "/baseResults/" + testCase.output;
Lei Zhang1b141722016-05-19 13:50:49 -040090 std::string expectedOutput;
91 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
92
93 checkEqAndUpdateIfRequested(expectedOutput, stream.str(), expectedOutputFname);
94}
95
96// clang-format off
97INSTANTIATE_TEST_CASE_P(
98 Glsl, ConfigTest,
99 ::testing::ValuesIn(std::vector<TestCaseSpec>({
John Kessenich2d9973d2018-02-21 18:42:10 -0700100 {"specExamples.vert", "baseResults/test.conf", "specExamplesConf.vert.out", (EShMessages)(EShMsgAST | EShMsgCascadingErrors)},
John Kessenicha86836e2016-07-09 14:50:57 -0600101 {"100Limits.vert", "100.conf", "100LimitsConf.vert.out", EShMsgCascadingErrors},
Lei Zhang1b141722016-05-19 13:50:49 -0400102 })),
103);
104// clang-format on
105
106} // anonymous namespace
107} // namespace glslangtest