• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 Samsung Inc
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/unit_spirv.h"
19 #include "test/val/val_fixtures.h"
20 
21 namespace spvtools {
22 namespace {
23 
24 using ::testing::Eq;
25 using ::testing::HasSubstr;
26 
27 using ValidateEntryPoints = spvtest::ValidateBase<bool>;
28 
TEST_F(ValidateEntryPoints,DuplicateEntryPoints)29 TEST_F(ValidateEntryPoints, DuplicateEntryPoints) {
30   const std::string body = R"(
31 OpCapability Shader
32 OpMemoryModel Logical GLSL450
33 OpEntryPoint GLCompute %3 "foo"
34 OpEntryPoint GLCompute %4 "foo"
35 %1 = OpTypeVoid
36 %2 = OpTypeFunction %1
37 %3 = OpFunction %1 None %2
38 %20 = OpLabel
39 OpReturn
40 OpFunctionEnd
41 %4 = OpFunction %1 None %2
42 %21 = OpLabel
43 OpReturn
44 OpFunctionEnd
45 )";
46 
47   CompileSuccessfully(body);
48   EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
49   EXPECT_THAT(getDiagnosticString(),
50               HasSubstr("Entry points cannot share the same name"));
51 }
52 
TEST_F(ValidateEntryPoints,UniqueEntryPoints)53 TEST_F(ValidateEntryPoints, UniqueEntryPoints) {
54   const std::string body = R"(
55 OpCapability Shader
56 OpMemoryModel Logical GLSL450
57 OpEntryPoint GLCompute %3 "foo"
58 OpEntryPoint GLCompute %4 "foo2"
59 %1 = OpTypeVoid
60 %2 = OpTypeFunction %1
61 %3 = OpFunction %1 None %2
62 %20 = OpLabel
63 OpReturn
64 OpFunctionEnd
65 %4 = OpFunction %1 None %2
66 %21 = OpLabel
67 OpReturn
68 OpFunctionEnd
69 )";
70 
71   CompileSuccessfully(body);
72   EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
73 }
74 
75 }  // namespace
76 }  // namespace spvtools
77