#include <string>
#include "gmock/gmock.h"
#include "test/val/val_fixtures.h"
namespace spvtools {
namespace val {
namespace {
using ::testing::HasSubstr;
using ValidateSpvINTELInlineAssembly = spvtest::ValidateBase<bool>;
TEST_F(ValidateSpvINTELInlineAssembly, Valid) {
const std::string str = R"(
OpCapability Kernel
OpCapability Addresses
OpCapability Linkage
OpCapability AsmINTEL
OpExtension "SPV_INTEL_inline_assembly"
OpMemoryModel Physical32 OpenCL
OpDecorate %1 SideEffectsINTEL
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%4 = OpAsmTargetINTEL "spirv64-unknown-unknown"
%1 = OpAsmINTEL %2 %3 %4 "nop" ""
%5 = OpFunction %2 None %3
%6 = OpLabel
%7 = OpAsmCallINTEL %2 %1
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str.c_str());
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateSpvINTELInlineAssembly, RequiresExtension) {
const std::string str = R"(
OpCapability Kernel
OpCapability Addresses
OpCapability Linkage
OpCapability AsmINTEL
OpMemoryModel Physical32 OpenCL
OpDecorate %1 SideEffectsINTEL
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%4 = OpAsmTargetINTEL "spirv64-unknown-unknown"
%1 = OpAsmINTEL %2 %3 %4 "nop" ""
%5 = OpFunction %2 None %3
%6 = OpLabel
%7 = OpAsmCallINTEL %2 %1
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str.c_str());
EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
const std::string diag = getDiagnosticString();
EXPECT_THAT(
diag,
HasSubstr("1st operand of Capability: operand AsmINTEL(5606) requires "
"one of these extensions: SPV_INTEL_inline_assembly"));
EXPECT_THAT(diag, HasSubstr("OpCapability AsmINTEL"));
}
TEST_F(ValidateSpvINTELInlineAssembly, RequiresCapability) {
const std::string str = R"(
OpCapability Kernel
OpCapability Addresses
OpCapability Linkage
OpExtension "SPV_INTEL_inline_assembly"
OpMemoryModel Physical32 OpenCL
OpDecorate %1 SideEffectsINTEL
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%4 = OpAsmTargetINTEL "spirv64-unknown-unknown"
%1 = OpAsmINTEL %2 %3 %4 "nop" ""
%5 = OpFunction %2 None %3
%6 = OpLabel
%7 = OpAsmCallINTEL %2 %1
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str.c_str());
EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
const std::string diag = getDiagnosticString();
EXPECT_THAT(diag, HasSubstr("Operand 2 of Decorate requires one of these "
"capabilities: AsmINTEL"));
EXPECT_THAT(diag, HasSubstr("OpDecorate %1 SideEffectsINTEL"));
}
}
}
}