MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / TEST_P

Function TEST_P

test/ext_inst.glsl_test.cpp:42–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40using ExtInstGLSLstd450RoundTripTest = ::testing::TestWithParam<ExtInstContext>;
41
42TEST_P(ExtInstGLSLstd450RoundTripTest, ParameterizedExtInst) {
43 spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_0);
44 const std::string spirv = R"(
45OpCapability Shader
46%1 = OpExtInstImport "GLSL.std.450"
47OpMemoryModel Logical Simple
48OpEntryPoint Vertex %2 "main"
49%3 = OpTypeVoid
50%4 = OpTypeFunction %3
51%2 = OpFunction %3 None %5
52%6 = OpLabel
53%8 = OpExtInst %7 %1 )" + std::string(GetParam().extInstOpName) +
54 " " + GetParam().extInstOperandVars + R"(
55OpReturn
56OpFunctionEnd
57)";
58 const std::string spirv_header =
59 R"(; SPIR-V
60; Version: 1.0
61; Generator: Khronos SPIR-V Tools Assembler; 0
62; Bound: 9
63; Schema: 0)";
64 spv_binary binary = nullptr;
65 spv_diagnostic diagnostic;
66 spv_result_t error = spvTextToBinary(context, spirv.c_str(), spirv.size(),
67 &binary, &diagnostic);
68 if (error) {
69 spvDiagnosticPrint(diagnostic);
70 spvDiagnosticDestroy(diagnostic);
71 ASSERT_EQ(SPV_SUCCESS, error)
72 << "Source was: " << std::endl
73 << spirv << std::endl
74 << "Test case for : " << GetParam().extInstOpName << std::endl;
75 }
76
77 // Check we do have the extended instruction's corresponding binary code in
78 // the generated SPIR-V binary.
79 std::vector<uint32_t> expected_contains(
80 {12 /*OpExtInst*/ | GetParam().extInstLength << 16, 7 /*return type*/,
81 8 /*result id*/, 1 /*glsl450 import*/, GetParam().extInstOpcode});
82 for (uint32_t operand : GetParam().extInstOperandIds) {
83 expected_contains.push_back(operand);
84 }
85 EXPECT_NE(binary->code + binary->wordCount,
86 std::search(binary->code, binary->code + binary->wordCount,
87 expected_contains.begin(), expected_contains.end()))
88 << "Cannot find\n"
89 << spvtest::WordVector(expected_contains).str() << "in\n"
90 << spvtest::WordVector(*binary).str();
91
92 // Check round trip gives the same text.
93 spv_text output_text = nullptr;
94 error = spvBinaryToText(context, binary->code, binary->wordCount,
95 SPV_BINARY_TO_TEXT_OPTION_NONE, &output_text,
96 &diagnostic);
97
98 if (error) {
99 spvDiagnosticPrint(diagnostic);

Callers

nothing calls this directly

Calls 15

spvContextCreateFunction · 0.85
spvTextToBinaryFunction · 0.85
spvDiagnosticPrintFunction · 0.85
spvDiagnosticDestroyFunction · 0.85
WordVectorClass · 0.85
spvBinaryToTextFunction · 0.85
spvTextDestroyFunction · 0.85
spvBinaryDestroyFunction · 0.85
spvContextDestroyFunction · 0.85
c_strMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected