Debian Codegraph @

test/val/val_extension_spv_intel_function_variants.cpp

raw
1 // Copyright 2025 The Khronos Group 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 // Tests for SPV_INTEL_inline_assembly
16
17 #include <string>
18
19 #include "gmock/gmock.h"
20 #include "test/val/val_fixtures.h"
21
22 namespace spvtools {
23 namespace val {
24 namespace {
25
26 using ::testing::HasSubstr;
27
28 using ValidateSpvINTELFunctionVariants = spvtest::ValidateBase<bool>;
29
30 TEST_F(ValidateSpvINTELFunctionVariants, Valid) {
31 const std::string str = R"(
32 OpCapability Kernel
33 OpCapability Linkage
34 OpCapability SpecConditionalINTEL
35 OpCapability FunctionVariantsINTEL
36 OpConditionalCapabilityINTEL %1 Int8
37 OpExtension "SPV_INTEL_function_variants"
38 OpMemoryModel Logical OpenCL
39 %bool = OpTypeBool
40 %1 = OpSpecConstantTrue %bool
41 )";
42 CompileSuccessfully(str.c_str());
43 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
44 }
45
46 TEST_F(ValidateSpvINTELFunctionVariants, RequiresExtension1) {
47 const std::string str = R"(
48 OpCapability Kernel
49 OpCapability Linkage
50 OpCapability SpecConditionalINTEL
51 OpMemoryModel Logical OpenCL
52 )";
53 CompileSuccessfully(str.c_str());
54 EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
55 const std::string diag = getDiagnosticString();
56 EXPECT_THAT(
57 diag, HasSubstr("1st operand of Capability: operand "
58 "SpecConditionalINTEL(6245) requires "
59 "one of these extensions: SPV_INTEL_function_variants"));
60 EXPECT_THAT(diag, HasSubstr("OpCapability SpecConditionalINTEL"));
61 }
62
63 TEST_F(ValidateSpvINTELFunctionVariants, RequiresExtension2) {
64 const std::string str = R"(
65 OpCapability Kernel
66 OpCapability Linkage
67 OpCapability FunctionVariantsINTEL
68 OpMemoryModel Logical OpenCL
69 )";
70 CompileSuccessfully(str.c_str());
71 EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
72 const std::string diag = getDiagnosticString();
73 EXPECT_THAT(
74 diag, HasSubstr("1st operand of Capability: operand "
75 "FunctionVariantsINTEL(6246) requires "
76 "one of these extensions: SPV_INTEL_function_variants"));
77 EXPECT_THAT(diag, HasSubstr("OpCapability FunctionVariantsINTEL"));
78 }
79
80 TEST_F(ValidateSpvINTELFunctionVariants, RequiresCapability1) {
81 const std::string str = R"(
82 OpCapability Kernel
83 OpCapability Linkage
84 OpConditionalCapabilityINTEL %1 Int8
85 OpExtension "SPV_INTEL_function_variants"
86 OpMemoryModel Logical OpenCL
87 %bool = OpTypeBool
88 %1 = OpSpecConstantTrue %bool
89 )";
90 CompileSuccessfully(str.c_str());
91 EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
92 const std::string diag = getDiagnosticString();
93 EXPECT_THAT(
94 diag, HasSubstr("Opcode ConditionalCapabilityINTEL requires one of these "
95 "capabilities: SpecConditionalINTEL"));
96 EXPECT_THAT(diag, HasSubstr("OpConditionalCapabilityINTEL %1 Int8"));
97 }
98
99 TEST_F(ValidateSpvINTELFunctionVariants, RequiresCapability2) {
100 const std::string str = R"(
101 OpCapability Kernel
102 OpCapability Linkage
103 OpCapability SpecConditionalINTEL
104 OpConditionalCapabilityINTEL %1 Int8
105 OpExtension "SPV_INTEL_function_variants"
106 OpMemoryModel Logical OpenCL
107 %bool = OpTypeBool
108 %1 = OpSpecConstantArchitectureINTEL %bool 0 0 170 0
109 )";
110 CompileSuccessfully(str.c_str());
111 EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
112 const std::string diag = getDiagnosticString();
113 EXPECT_THAT(
114 diag,
115 HasSubstr("Opcode SpecConstantArchitectureINTEL requires one of these "
116 "capabilities: FunctionVariantsINTEL"));
117 EXPECT_THAT(
118 diag, HasSubstr("%1 = OpSpecConstantArchitectureINTEL %bool 0 0 170 0"));
119 }
120
121 } // namespace
122 } // namespace val
123 } // namespace spvtools