Debian Codegraph @

test/val/val_entry_point_test.cpp

raw
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
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
53 TEST_F(ValidateEntryPoints, DuplicateConditionalEntryPointsAllowed) {
54 const std::string body = R"(
55 OpCapability Shader
56 OpCapability SpecConditionalINTEL
57 OpExtension "SPV_INTEL_function_variants"
58 OpMemoryModel Logical GLSL450
59 OpConditionalEntryPointINTEL %10 GLCompute %3 "foo"
60 OpConditionalEntryPointINTEL %11 GLCompute %4 "foo"
61 %bool = OpTypeBool
62 %1 = OpTypeVoid
63 %2 = OpTypeFunction %1
64 %10 = OpSpecConstantTrue %bool
65 %11 = OpSpecConstantFalse %bool
66 %3 = OpFunction %1 None %2
67 %20 = OpLabel
68 OpReturn
69 OpFunctionEnd
70 %4 = OpFunction %1 None %2
71 %21 = OpLabel
72 OpReturn
73 OpFunctionEnd
74 )";
75
76 CompileSuccessfully(body);
77 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
78 }
79
80 TEST_F(ValidateEntryPoints, UniqueEntryPoints) {
81 const std::string body = R"(
82 OpCapability Shader
83 OpMemoryModel Logical GLSL450
84 OpEntryPoint GLCompute %3 "foo"
85 OpEntryPoint GLCompute %4 "foo2"
86 %1 = OpTypeVoid
87 %2 = OpTypeFunction %1
88 %3 = OpFunction %1 None %2
89 %20 = OpLabel
90 OpReturn
91 OpFunctionEnd
92 %4 = OpFunction %1 None %2
93 %21 = OpLabel
94 OpReturn
95 OpFunctionEnd
96 )";
97
98 CompileSuccessfully(body);
99 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
100 }
101
102 } // namespace
103 } // namespace spvtools