memory_model_test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. using MemoryModel = spvtest::LinkerTest;
  21. TEST_F(MemoryModel, Default) {
  22. const std::string body1 = R"(
  23. OpMemoryModel Logical Simple
  24. )";
  25. const std::string body2 = R"(
  26. OpMemoryModel Logical Simple
  27. )";
  28. spvtest::Binary linked_binary;
  29. ASSERT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary));
  30. EXPECT_THAT(GetErrorMessage(), std::string());
  31. EXPECT_EQ(SpvAddressingModelLogical, linked_binary[6]);
  32. EXPECT_EQ(SpvMemoryModelSimple, linked_binary[7]);
  33. }
  34. TEST_F(MemoryModel, AddressingMismatch) {
  35. const std::string body1 = R"(
  36. OpMemoryModel Logical Simple
  37. )";
  38. const std::string body2 = R"(
  39. OpMemoryModel Physical32 Simple
  40. )";
  41. spvtest::Binary linked_binary;
  42. EXPECT_EQ(SPV_ERROR_INTERNAL,
  43. AssembleAndLink({body1, body2}, &linked_binary));
  44. EXPECT_THAT(
  45. GetErrorMessage(),
  46. HasSubstr("Conflicting addressing models: Logical vs Physical32."));
  47. }
  48. TEST_F(MemoryModel, MemoryMismatch) {
  49. const std::string body1 = R"(
  50. OpMemoryModel Logical Simple
  51. )";
  52. const std::string body2 = R"(
  53. OpMemoryModel Logical GLSL450
  54. )";
  55. spvtest::Binary linked_binary;
  56. EXPECT_EQ(SPV_ERROR_INTERNAL,
  57. AssembleAndLink({body1, body2}, &linked_binary));
  58. EXPECT_THAT(GetErrorMessage(),
  59. HasSubstr("Conflicting memory models: Simple vs GLSL450."));
  60. }
  61. } // namespace
  62. } // namespace spvtools