val_entry_point_test.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2019 Samsung Inc
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <string>
  15. #include "gmock/gmock.h"
  16. #include "test/unit_spirv.h"
  17. #include "test/val/val_fixtures.h"
  18. namespace spvtools {
  19. namespace {
  20. using ::testing::Eq;
  21. using ::testing::HasSubstr;
  22. using ValidateEntryPoints = spvtest::ValidateBase<bool>;
  23. TEST_F(ValidateEntryPoints, DuplicateEntryPoints) {
  24. const std::string body = R"(
  25. OpCapability Shader
  26. OpMemoryModel Logical GLSL450
  27. OpEntryPoint GLCompute %3 "foo"
  28. OpEntryPoint GLCompute %4 "foo"
  29. %1 = OpTypeVoid
  30. %2 = OpTypeFunction %1
  31. %3 = OpFunction %1 None %2
  32. %20 = OpLabel
  33. OpReturn
  34. OpFunctionEnd
  35. %4 = OpFunction %1 None %2
  36. %21 = OpLabel
  37. OpReturn
  38. OpFunctionEnd
  39. )";
  40. CompileSuccessfully(body);
  41. EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  42. EXPECT_THAT(getDiagnosticString(),
  43. HasSubstr("Entry points cannot share the same name"));
  44. }
  45. TEST_F(ValidateEntryPoints, UniqueEntryPoints) {
  46. const std::string body = R"(
  47. OpCapability Shader
  48. OpMemoryModel Logical GLSL450
  49. OpEntryPoint GLCompute %3 "foo"
  50. OpEntryPoint GLCompute %4 "foo2"
  51. %1 = OpTypeVoid
  52. %2 = OpTypeFunction %1
  53. %3 = OpFunction %1 None %2
  54. %20 = OpLabel
  55. OpReturn
  56. OpFunctionEnd
  57. %4 = OpFunction %1 None %2
  58. %21 = OpLabel
  59. OpReturn
  60. OpFunctionEnd
  61. )";
  62. CompileSuccessfully(body);
  63. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  64. }
  65. } // namespace
  66. } // namespace spvtools