memory_model_test.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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(spv::AddressingModel::Logical,
  32. static_cast<spv::AddressingModel>(linked_binary[6]));
  33. EXPECT_EQ(spv::MemoryModel::Simple,
  34. static_cast<spv::MemoryModel>(linked_binary[7]));
  35. }
  36. TEST_F(MemoryModel, AddressingMismatch) {
  37. const std::string body1 = R"(
  38. OpMemoryModel Logical Simple
  39. )";
  40. const std::string body2 = R"(
  41. OpMemoryModel Physical32 Simple
  42. )";
  43. spvtest::Binary linked_binary;
  44. EXPECT_EQ(SPV_ERROR_INTERNAL,
  45. AssembleAndLink({body1, body2}, &linked_binary));
  46. EXPECT_THAT(GetErrorMessage(),
  47. HasSubstr("Conflicting addressing models: Logical (input modules "
  48. "1 through 1) vs Physical32 (input module 2)."));
  49. }
  50. TEST_F(MemoryModel, MemoryMismatch) {
  51. const std::string body1 = R"(
  52. OpMemoryModel Logical Simple
  53. )";
  54. const std::string body2 = R"(
  55. OpMemoryModel Logical GLSL450
  56. )";
  57. spvtest::Binary linked_binary;
  58. EXPECT_EQ(SPV_ERROR_INTERNAL,
  59. AssembleAndLink({body1, body2}, &linked_binary));
  60. EXPECT_THAT(GetErrorMessage(),
  61. HasSubstr("Conflicting memory models: Simple (input modules 1 "
  62. "through 1) vs GLSL450 (input module 2)."));
  63. }
  64. TEST_F(MemoryModel, FirstLackMemoryModel) {
  65. const std::string body1 = R"(
  66. )";
  67. const std::string body2 = R"(
  68. OpMemoryModel Logical GLSL450
  69. )";
  70. spvtest::Binary linked_binary;
  71. EXPECT_EQ(SPV_ERROR_INVALID_BINARY,
  72. AssembleAndLink({body1, body2}, &linked_binary));
  73. EXPECT_THAT(
  74. GetErrorMessage(),
  75. HasSubstr("Input module 1 is lacking an OpMemoryModel instruction."));
  76. }
  77. TEST_F(MemoryModel, SecondLackMemoryModel) {
  78. const std::string body1 = R"(
  79. OpMemoryModel Logical GLSL450
  80. )";
  81. const std::string body2 = R"(
  82. )";
  83. spvtest::Binary linked_binary;
  84. EXPECT_EQ(SPV_ERROR_INVALID_BINARY,
  85. AssembleAndLink({body1, body2}, &linked_binary));
  86. EXPECT_THAT(
  87. GetErrorMessage(),
  88. HasSubstr("Input module 2 is lacking an OpMemoryModel instruction."));
  89. }
  90. } // namespace
  91. } // namespace spvtools