• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TEST_F(EntryPoints,SameModelDifferentName)27 TEST_F(EntryPoints, SameModelDifferentName) {
28   const std::string body1 = R"(
29 OpCapability Shader
30 OpMemoryModel Logical GLSL450
31 OpEntryPoint GLCompute %3 "foo"
32 %1 = OpTypeVoid
33 %2 = OpTypeFunction %1
34 %3 = OpFunction %1 None %2
35 OpFunctionEnd
36 )";
37   const std::string body2 = R"(
38 OpCapability Shader
39 OpMemoryModel Logical GLSL450
40 OpEntryPoint GLCompute %3 "bar"
41 %1 = OpTypeVoid
42 %2 = OpTypeFunction %1
43 %3 = OpFunction %1 None %2
44 OpFunctionEnd
45 )";
46 
47   spvtest::Binary linked_binary;
48   ASSERT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary))
49       << GetErrorMessage();
50   EXPECT_THAT(GetErrorMessage(), std::string());
51 }
52 
TEST_F(EntryPoints,DifferentModelSameName)53 TEST_F(EntryPoints, DifferentModelSameName) {
54   const std::string body1 = R"(
55 OpCapability Shader
56 OpMemoryModel Logical GLSL450
57 OpEntryPoint GLCompute %3 "foo"
58 %1 = OpTypeVoid
59 %2 = OpTypeFunction %1
60 %3 = OpFunction %1 None %2
61 OpFunctionEnd
62 )";
63   const std::string body2 = R"(
64 OpCapability Shader
65 OpMemoryModel Logical GLSL450
66 OpEntryPoint Vertex %3 "foo"
67 %1 = OpTypeVoid
68 %2 = OpTypeFunction %1
69 %3 = OpFunction %1 None %2
70 OpFunctionEnd
71 )";
72 
73   spvtest::Binary linked_binary;
74   ASSERT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary))
75       << GetErrorMessage();
76   EXPECT_THAT(GetErrorMessage(), std::string());
77 }
78 
TEST_F(EntryPoints,SameModelAndName)79 TEST_F(EntryPoints, SameModelAndName) {
80   const std::string body1 = R"(
81 OpCapability Shader
82 OpMemoryModel Logical GLSL450
83 OpEntryPoint GLCompute %3 "foo"
84 %1 = OpTypeVoid
85 %2 = OpTypeFunction %1
86 %3 = OpFunction %1 None %2
87 OpFunctionEnd
88 )";
89   const std::string body2 = R"(
90 OpCapability Shader
91 OpMemoryModel Logical GLSL450
92 OpEntryPoint GLCompute %3 "foo"
93 %1 = OpTypeVoid
94 %2 = OpTypeFunction %1
95 %3 = OpFunction %1 None %2
96 OpFunctionEnd
97 )";
98 
99   spvtest::Binary linked_binary;
100   EXPECT_EQ(SPV_ERROR_INTERNAL,
101             AssembleAndLink({body1, body2}, &linked_binary));
102   EXPECT_THAT(GetErrorMessage(),
103               HasSubstr("The entry point \"foo\", with execution model "
104                         "GLCompute, was already defined."));
105 }
106 
107 }  // namespace
108 }  // namespace spvtools
109