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 15 #include <string> 16 17 #include "gmock/gmock.h" 18 #include "test/link/linker_fixture.h" 19 20 namespace spvtools { 21 namespace { 22 23 using ::testing::HasSubstr; 24 using MemoryModel = spvtest::LinkerTest; 25 26 TEST_F(MemoryModel, Default) { 27 const std::string body1 = R"( 28 OpMemoryModel Logical Simple 29 )"; 30 const std::string body2 = R"( 31 OpMemoryModel Logical Simple 32 )"; 33 34 spvtest::Binary linked_binary; 35 ASSERT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary)); 36 EXPECT_THAT(GetErrorMessage(), std::string()); 37 38 EXPECT_EQ(SpvAddressingModelLogical, linked_binary[6]); 39 EXPECT_EQ(SpvMemoryModelSimple, linked_binary[7]); 40 } 41 42 TEST_F(MemoryModel, AddressingMismatch) { 43 const std::string body1 = R"( 44 OpMemoryModel Logical Simple 45 )"; 46 const std::string body2 = R"( 47 OpMemoryModel Physical32 Simple 48 )"; 49 50 spvtest::Binary linked_binary; 51 EXPECT_EQ(SPV_ERROR_INTERNAL, 52 AssembleAndLink({body1, body2}, &linked_binary)); 53 EXPECT_THAT( 54 GetErrorMessage(), 55 HasSubstr("Conflicting addressing models: Logical vs Physical32.")); 56 } 57 58 TEST_F(MemoryModel, MemoryMismatch) { 59 const std::string body1 = R"( 60 OpMemoryModel Logical Simple 61 )"; 62 const std::string body2 = R"( 63 OpMemoryModel Logical GLSL450 64 )"; 65 66 spvtest::Binary linked_binary; 67 EXPECT_EQ(SPV_ERROR_INTERNAL, 68 AssembleAndLink({body1, body2}, &linked_binary)); 69 EXPECT_THAT(GetErrorMessage(), 70 HasSubstr("Conflicting memory models: Simple vs GLSL450.")); 71 } 72 73 } // namespace 74 } // namespace spvtools 75