entry_points_test.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (c) 2017 Pierre Moreau
  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/link/linker_fixture.h"
  17. namespace spvtools {
  18. namespace {
  19. using ::testing::HasSubstr;
  20. class EntryPoints : public spvtest::LinkerTest {};
  21. TEST_F(EntryPoints, SameModelDifferentName) {
  22. const std::string body1 = R"(
  23. OpEntryPoint GLCompute %3 "foo"
  24. %1 = OpTypeVoid
  25. %2 = OpTypeFunction %1
  26. %3 = OpFunction %1 None %2
  27. OpFunctionEnd
  28. )";
  29. const std::string body2 = R"(
  30. OpEntryPoint GLCompute %3 "bar"
  31. %1 = OpTypeVoid
  32. %2 = OpTypeFunction %1
  33. %3 = OpFunction %1 None %2
  34. OpFunctionEnd
  35. )";
  36. spvtest::Binary linked_binary;
  37. EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary));
  38. EXPECT_THAT(GetErrorMessage(), std::string());
  39. }
  40. TEST_F(EntryPoints, DifferentModelSameName) {
  41. const std::string body1 = R"(
  42. OpEntryPoint GLCompute %3 "foo"
  43. %1 = OpTypeVoid
  44. %2 = OpTypeFunction %1
  45. %3 = OpFunction %1 None %2
  46. OpFunctionEnd
  47. )";
  48. const std::string body2 = R"(
  49. OpEntryPoint Vertex %3 "foo"
  50. %1 = OpTypeVoid
  51. %2 = OpTypeFunction %1
  52. %3 = OpFunction %1 None %2
  53. OpFunctionEnd
  54. )";
  55. spvtest::Binary linked_binary;
  56. EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary));
  57. EXPECT_THAT(GetErrorMessage(), std::string());
  58. }
  59. TEST_F(EntryPoints, SameModelAndName) {
  60. const std::string body1 = R"(
  61. OpEntryPoint GLCompute %3 "foo"
  62. %1 = OpTypeVoid
  63. %2 = OpTypeFunction %1
  64. %3 = OpFunction %1 None %2
  65. OpFunctionEnd
  66. )";
  67. const std::string body2 = R"(
  68. OpEntryPoint GLCompute %3 "foo"
  69. %1 = OpTypeVoid
  70. %2 = OpTypeFunction %1
  71. %3 = OpFunction %1 None %2
  72. OpFunctionEnd
  73. )";
  74. spvtest::Binary linked_binary;
  75. EXPECT_EQ(SPV_ERROR_INTERNAL,
  76. AssembleAndLink({body1, body2}, &linked_binary));
  77. EXPECT_THAT(GetErrorMessage(),
  78. HasSubstr("The entry point \"foo\", with execution model "
  79. "GLCompute, was already defined."));
  80. }
  81. } // namespace
  82. } // namespace spvtools