1617a3babSopenharmony_ci// 2617a3babSopenharmony_ci// Copyright (C) 2016 Google, Inc. 3617a3babSopenharmony_ci// 4617a3babSopenharmony_ci// All rights reserved. 5617a3babSopenharmony_ci// 6617a3babSopenharmony_ci// Redistribution and use in source and binary forms, with or without 7617a3babSopenharmony_ci// modification, are permitted provided that the following conditions 8617a3babSopenharmony_ci// are met: 9617a3babSopenharmony_ci// 10617a3babSopenharmony_ci// Redistributions of source code must retain the above copyright 11617a3babSopenharmony_ci// notice, this list of conditions and the following disclaimer. 12617a3babSopenharmony_ci// 13617a3babSopenharmony_ci// Redistributions in binary form must reproduce the above 14617a3babSopenharmony_ci// copyright notice, this list of conditions and the following 15617a3babSopenharmony_ci// disclaimer in the documentation and/or other materials provided 16617a3babSopenharmony_ci// with the distribution. 17617a3babSopenharmony_ci// 18617a3babSopenharmony_ci// Neither the name of Google Inc. nor the names of its 19617a3babSopenharmony_ci// contributors may be used to endorse or promote products derived 20617a3babSopenharmony_ci// from this software without specific prior written permission. 21617a3babSopenharmony_ci// 22617a3babSopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23617a3babSopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24617a3babSopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25617a3babSopenharmony_ci// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26617a3babSopenharmony_ci// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27617a3babSopenharmony_ci// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28617a3babSopenharmony_ci// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29617a3babSopenharmony_ci// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30617a3babSopenharmony_ci// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31617a3babSopenharmony_ci// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32617a3babSopenharmony_ci// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33617a3babSopenharmony_ci// POSSIBILITY OF SUCH DAMAGE. 34617a3babSopenharmony_ci 35617a3babSopenharmony_ci#include <memory> 36617a3babSopenharmony_ci 37617a3babSopenharmony_ci#include <gtest/gtest.h> 38617a3babSopenharmony_ci 39617a3babSopenharmony_ci#include "TestFixture.h" 40617a3babSopenharmony_ci 41617a3babSopenharmony_cinamespace glslangtest { 42617a3babSopenharmony_cinamespace { 43617a3babSopenharmony_ci 44617a3babSopenharmony_ciusing LinkTest = GlslangTest< 45617a3babSopenharmony_ci ::testing::TestWithParam<std::vector<std::string>>>; 46617a3babSopenharmony_ci 47617a3babSopenharmony_ciTEST_P(LinkTest, FromFile) 48617a3babSopenharmony_ci{ 49617a3babSopenharmony_ci const auto& fileNames = GetParam(); 50617a3babSopenharmony_ci const size_t fileCount = fileNames.size(); 51617a3babSopenharmony_ci const EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST); 52617a3babSopenharmony_ci GlslangResult result; 53617a3babSopenharmony_ci result.validationResult = true; 54617a3babSopenharmony_ci 55617a3babSopenharmony_ci // Compile each input shader file. 56617a3babSopenharmony_ci std::vector<std::unique_ptr<glslang::TShader>> shaders; 57617a3babSopenharmony_ci for (size_t i = 0; i < fileCount; ++i) { 58617a3babSopenharmony_ci std::string contents; 59617a3babSopenharmony_ci tryLoadFile(GlobalTestSettings.testRoot + "/" + fileNames[i], 60617a3babSopenharmony_ci "input", &contents); 61617a3babSopenharmony_ci shaders.emplace_back( 62617a3babSopenharmony_ci new glslang::TShader(GetShaderStage(GetSuffix(fileNames[i])))); 63617a3babSopenharmony_ci auto* shader = shaders.back().get(); 64617a3babSopenharmony_ci compile(shader, contents, "", controls); 65617a3babSopenharmony_ci result.shaderResults.push_back( 66617a3babSopenharmony_ci {fileNames[i], shader->getInfoLog(), shader->getInfoDebugLog()}); 67617a3babSopenharmony_ci } 68617a3babSopenharmony_ci 69617a3babSopenharmony_ci // Link all of them. 70617a3babSopenharmony_ci glslang::TProgram program; 71617a3babSopenharmony_ci for (const auto& shader : shaders) program.addShader(shader.get()); 72617a3babSopenharmony_ci program.link(controls); 73617a3babSopenharmony_ci result.linkingOutput = program.getInfoLog(); 74617a3babSopenharmony_ci result.linkingError = program.getInfoDebugLog(); 75617a3babSopenharmony_ci 76617a3babSopenharmony_ci std::ostringstream stream; 77617a3babSopenharmony_ci outputResultToStream(&stream, result, controls); 78617a3babSopenharmony_ci 79617a3babSopenharmony_ci // Check with expected results. 80617a3babSopenharmony_ci const std::string expectedOutputFname = 81617a3babSopenharmony_ci GlobalTestSettings.testRoot + "/baseResults/" + fileNames.front() + ".out"; 82617a3babSopenharmony_ci std::string expectedOutput; 83617a3babSopenharmony_ci tryLoadFile(expectedOutputFname, "expected output", &expectedOutput); 84617a3babSopenharmony_ci 85617a3babSopenharmony_ci checkEqAndUpdateIfRequested(expectedOutput, stream.str(), expectedOutputFname); 86617a3babSopenharmony_ci} 87617a3babSopenharmony_ci 88617a3babSopenharmony_ci// clang-format off 89617a3babSopenharmony_ciINSTANTIATE_TEST_SUITE_P( 90617a3babSopenharmony_ci Glsl, LinkTest, 91617a3babSopenharmony_ci ::testing::ValuesIn(std::vector<std::vector<std::string>>({ 92617a3babSopenharmony_ci {"mains1.frag", "mains2.frag", "noMain1.geom", "noMain2.geom"}, 93617a3babSopenharmony_ci {"implicitArraySize.vert", "implicitArraySize.frag"}, 94617a3babSopenharmony_ci {"implicitArraySizeBuiltin.vert", "implicitArraySizeBuiltin.geom"}, 95617a3babSopenharmony_ci {"implicitArraySize1.geom", "implicitArraySize2.geom"}, 96617a3babSopenharmony_ci {"noMain.vert", "mains.frag"}, 97617a3babSopenharmony_ci {"link1.frag", "link2.frag", "link3.frag"}, 98617a3babSopenharmony_ci {"recurse1.vert", "recurse1.frag", "recurse2.frag"}, 99617a3babSopenharmony_ci {"300link.frag"}, 100617a3babSopenharmony_ci {"300link2.frag"}, 101617a3babSopenharmony_ci {"300link3.frag"}, 102617a3babSopenharmony_ci {"empty.frag", "empty2.frag", "empty3.frag"}, 103617a3babSopenharmony_ci {"150.tesc", "150.tese", "400.tesc", "400.tese", "410.tesc", "420.tesc", "420.tese"}, 104617a3babSopenharmony_ci {"max_vertices_0.geom"}, 105617a3babSopenharmony_ci {"contradict_0.geom", "contradict_1.geom"}, 106617a3babSopenharmony_ci {"es-link1.frag", "es-link2.frag"}, 107617a3babSopenharmony_ci {"missingBodies.vert"}, 108617a3babSopenharmony_ci {"link.multiAnonBlocksInvalid.0.0.vert", "link.multiAnonBlocksInvalid.0.1.vert"}, 109617a3babSopenharmony_ci {"link.multiAnonBlocksValid.0.0.vert", "link.multiAnonBlocksValid.0.1.vert"}, 110617a3babSopenharmony_ci {"link.multiBlocksInvalid.0.0.vert", "link.multiBlocksInvalid.0.1.vert"}, 111617a3babSopenharmony_ci {"link.multiBlocksValid.1.0.vert", "link.multiBlocksValid.1.1.vert"}, 112617a3babSopenharmony_ci {"link.tesselation.vert", "link.tesselation.frag"}, 113617a3babSopenharmony_ci {"link.tesselation.tese", "link.tesselation.tesc"}, 114617a3babSopenharmony_ci {"link.redeclareBuiltin.vert", "link.redeclareBuiltin.geom"}, 115617a3babSopenharmony_ci })) 116617a3babSopenharmony_ci); 117617a3babSopenharmony_ci// clang-format on 118617a3babSopenharmony_ci 119617a3babSopenharmony_ci} // anonymous namespace 120617a3babSopenharmony_ci} // namespace glslangtest 121