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