| 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 ValidateSpvINTELInlineAssembly = spvtest::ValidateBase<bool>; |
| 29 |
|
| 30 |
TEST_F(ValidateSpvINTELInlineAssembly, Valid) { |
| 31 |
const std::string str = R"( |
| 32 |
OpCapability Kernel |
| 33 |
OpCapability Addresses |
| 34 |
OpCapability Linkage |
| 35 |
OpCapability AsmINTEL |
| 36 |
OpExtension "SPV_INTEL_inline_assembly" |
| 37 |
OpMemoryModel Physical32 OpenCL |
| 38 |
OpDecorate %1 SideEffectsINTEL |
| 39 |
%2 = OpTypeVoid |
| 40 |
%3 = OpTypeFunction %2 |
| 41 |
%4 = OpAsmTargetINTEL "spirv64-unknown-unknown" |
| 42 |
%1 = OpAsmINTEL %2 %3 %4 "nop" "" |
| 43 |
%5 = OpFunction %2 None %3 |
| 44 |
%6 = OpLabel |
| 45 |
%7 = OpAsmCallINTEL %2 %1 |
| 46 |
OpReturn |
| 47 |
OpFunctionEnd |
| 48 |
)"; |
| 49 |
CompileSuccessfully(str.c_str()); |
| 50 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 51 |
} |
| 52 |
|
| 53 |
TEST_F(ValidateSpvINTELInlineAssembly, RequiresExtension) { |
| 54 |
const std::string str = R"( |
| 55 |
OpCapability Kernel |
| 56 |
OpCapability Addresses |
| 57 |
OpCapability Linkage |
| 58 |
OpCapability AsmINTEL |
| 59 |
OpMemoryModel Physical32 OpenCL |
| 60 |
OpDecorate %1 SideEffectsINTEL |
| 61 |
%2 = OpTypeVoid |
| 62 |
%3 = OpTypeFunction %2 |
| 63 |
%4 = OpAsmTargetINTEL "spirv64-unknown-unknown" |
| 64 |
%1 = OpAsmINTEL %2 %3 %4 "nop" "" |
| 65 |
%5 = OpFunction %2 None %3 |
| 66 |
%6 = OpLabel |
| 67 |
%7 = OpAsmCallINTEL %2 %1 |
| 68 |
OpReturn |
| 69 |
OpFunctionEnd |
| 70 |
)"; |
| 71 |
CompileSuccessfully(str.c_str()); |
| 72 |
EXPECT_NE(SPV_SUCCESS, ValidateInstructions()); |
| 73 |
const std::string diag = getDiagnosticString(); |
| 74 |
EXPECT_THAT( |
| 75 |
diag, |
| 76 |
HasSubstr("1st operand of Capability: operand AsmINTEL(5606) requires " |
| 77 |
"one of these extensions: SPV_INTEL_inline_assembly")); |
| 78 |
EXPECT_THAT(diag, HasSubstr("OpCapability AsmINTEL")); |
| 79 |
} |
| 80 |
|
| 81 |
TEST_F(ValidateSpvINTELInlineAssembly, RequiresCapability) { |
| 82 |
const std::string str = R"( |
| 83 |
OpCapability Kernel |
| 84 |
OpCapability Addresses |
| 85 |
OpCapability Linkage |
| 86 |
OpExtension "SPV_INTEL_inline_assembly" |
| 87 |
OpMemoryModel Physical32 OpenCL |
| 88 |
OpDecorate %1 SideEffectsINTEL |
| 89 |
%2 = OpTypeVoid |
| 90 |
%3 = OpTypeFunction %2 |
| 91 |
%4 = OpAsmTargetINTEL "spirv64-unknown-unknown" |
| 92 |
%1 = OpAsmINTEL %2 %3 %4 "nop" "" |
| 93 |
%5 = OpFunction %2 None %3 |
| 94 |
%6 = OpLabel |
| 95 |
%7 = OpAsmCallINTEL %2 %1 |
| 96 |
OpReturn |
| 97 |
OpFunctionEnd |
| 98 |
)"; |
| 99 |
CompileSuccessfully(str.c_str()); |
| 100 |
EXPECT_NE(SPV_SUCCESS, ValidateInstructions()); |
| 101 |
const std::string diag = getDiagnosticString(); |
| 102 |
EXPECT_THAT(diag, HasSubstr("Operand 2 of Decorate requires one of these " |
| 103 |
"capabilities: AsmINTEL")); |
| 104 |
EXPECT_THAT(diag, HasSubstr("OpDecorate %1 SideEffectsINTEL")); |
| 105 |
} |
| 106 |
|
| 107 |
} // namespace |
| 108 |
} // namespace val |
| 109 |
} // namespace spvtools |