Config.FromFile.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include "StandAlone/ResourceLimits.h"
  35. #include "TestFixture.h"
  36. namespace glslangtest {
  37. namespace {
  38. struct TestCaseSpec {
  39. std::string input;
  40. std::string config;
  41. std::string output;
  42. EShMessages controls;
  43. };
  44. using ConfigTest = GlslangTest<::testing::TestWithParam<TestCaseSpec>>;
  45. TEST_P(ConfigTest, FromFile)
  46. {
  47. TestCaseSpec testCase = GetParam();
  48. GlslangResult result;
  49. result.validationResult = true;
  50. // Get the contents for input shader and limit configurations.
  51. std::string shaderContents, configContents;
  52. tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.input, "input", &shaderContents);
  53. tryLoadFile(GlobalTestSettings.testRoot + "/" + testCase.config, "limits config", &configContents);
  54. // Decode limit configurations.
  55. TBuiltInResource resources = {};
  56. {
  57. const size_t len = configContents.size();
  58. char* configChars = new char[len + 1];
  59. memcpy(configChars, configContents.data(), len);
  60. configChars[len] = 0;
  61. glslang::DecodeResourceLimits(&resources, configChars);
  62. delete[] configChars;
  63. }
  64. // Compile the shader.
  65. glslang::TShader shader(GetShaderStage(GetSuffix(testCase.input)));
  66. compile(&shader, shaderContents, "", testCase.controls, &resources);
  67. result.shaderResults.push_back(
  68. {testCase.input, shader.getInfoLog(), shader.getInfoDebugLog()});
  69. // Link the shader.
  70. glslang::TProgram program;
  71. program.addShader(&shader);
  72. program.link(testCase.controls);
  73. result.linkingOutput = program.getInfoLog();
  74. result.linkingError = program.getInfoDebugLog();
  75. std::ostringstream stream;
  76. outputResultToStream(&stream, result, testCase.controls);
  77. // Check with expected results.
  78. const std::string expectedOutputFname =
  79. GlobalTestSettings.testRoot + "/baseResults/" + testCase.output;
  80. std::string expectedOutput;
  81. tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
  82. checkEqAndUpdateIfRequested(expectedOutput, stream.str(), expectedOutputFname);
  83. }
  84. // clang-format off
  85. INSTANTIATE_TEST_SUITE_P(
  86. Glsl, ConfigTest,
  87. ::testing::ValuesIn(std::vector<TestCaseSpec>({
  88. {"specExamples.vert", "baseResults/test.conf", "specExamplesConf.vert.out", (EShMessages)(EShMsgAST | EShMsgCascadingErrors)},
  89. {"100Limits.vert", "100.conf", "100LimitsConf.vert.out", EShMsgCascadingErrors},
  90. }))
  91. );
  92. // clang-format on
  93. } // anonymous namespace
  94. } // namespace glslangtest