TEST_F(OperandTypeTest, OptionalTypedLiteralNumber) { const std::string input = "%1 = OpTypeInt 32 0\n" "%2 = OpConstant %1 42\n" "OpSwitch %2 %3 100 %4\n"; EXPECT_EQ(input, EncodeAndDecodeSuccessfully(input)); }
TEST_F(IndentTest, Sample) { const std::string input = R"( OpCapability Shader OpMemoryModel Logical GLSL450 %1 = OpTypeInt 32 0 %2 = OpTypeStruct %1 %3 %4 %5 %6 %7 %8 %9 %10 ; force IDs into double digits %11 = OpConstant %1 42 OpStore %2 %3 Aligned|Volatile 4 ; bogus, but not indented )"; const std::string expected = R"( OpCapability Shader OpMemoryModel Logical GLSL450 %1 = OpTypeInt 32 0 %2 = OpTypeStruct %1 %3 %4 %5 %6 %7 %8 %9 %10 %11 = OpConstant %1 42 OpStore %2 %3 Volatile|Aligned 4 )"; EXPECT_THAT( EncodeAndDecodeSuccessfully(input, SPV_BINARY_TO_TEXT_OPTION_INDENT), expected); } TEST_F(TextToBinaryTest, ShowByteOffsetsWhenRequested) { const std::string input = R"( OpCapability Shader OpMemoryModel Logical GLSL450 %1 = OpTypeInt 32 0 %2 = OpTypeVoid )"; const std::string expected = R"(OpCapability Shader ; 0x00000014 OpMemoryModel Logical GLSL450 ; 0x0000001c %1 = OpTypeInt 32 0 ; 0x00000028 %2 = OpTypeVoid ; 0x00000038 )"; EXPECT_THAT(EncodeAndDecodeSuccessfully( input, SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET), expected); } // Test version string. TEST_F(TextToBinaryTest, VersionString) { auto words = CompileSuccessfully(""); spv_text decoded_text = nullptr; EXPECT_THAT(spvBinaryToText(ScopedContext().context, words.data(), words.size(), SPV_BINARY_TO_TEXT_OPTION_NONE, &decoded_text, &diagnostic), Eq(SPV_SUCCESS)); EXPECT_EQ(nullptr, diagnostic); EXPECT_THAT(decoded_text->str, HasSubstr("Version: 1.0\n")) << EncodeAndDecodeSuccessfully(""); spvTextDestroy(decoded_text); }
TEST_F(MaskSorting, MasksAreSortedFromLSBToMSB) { EXPECT_THAT(EncodeAndDecodeSuccessfully( "OpStore %1 %2 Nontemporal|Aligned|Volatile 32"), Eq("OpStore %1 %2 Volatile|Aligned|Nontemporal 32\n")); EXPECT_THAT( EncodeAndDecodeSuccessfully( "OpDecorate %1 FPFastMathMode NotInf|Fast|AllowRecip|NotNaN|NSZ"), Eq("OpDecorate %1 FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|Fast\n")); EXPECT_THAT( EncodeAndDecodeSuccessfully("OpLoopMerge %1 %2 DontUnroll|Unroll"), Eq("OpLoopMerge %1 %2 Unroll|DontUnroll\n")); EXPECT_THAT( EncodeAndDecodeSuccessfully("OpSelectionMerge %1 DontFlatten|Flatten"), Eq("OpSelectionMerge %1 Flatten|DontFlatten\n")); EXPECT_THAT(EncodeAndDecodeSuccessfully( "%2 = OpFunction %1 DontInline|Const|Pure|Inline %3"), Eq("%2 = OpFunction %1 Inline|DontInline|Pure|Const %3\n")); EXPECT_THAT(EncodeAndDecodeSuccessfully( "%2 = OpImageFetch %1 %3 %4" " MinLod|Sample|Offset|Lod|Grad|ConstOffsets|ConstOffset|Bias" " %5 %6 %7 %8 %9 %10 %11 %12 %13\n"), Eq("%2 = OpImageFetch %1 %3 %4" " Bias|Lod|Grad|ConstOffset|Offset|ConstOffsets|Sample|MinLod" " %5 %6 %7 %8 %9 %10 %11 %12 %13\n")); }
TEST_F(TextToBinaryTest, StringSpace) { const std::string code = ("OpSourceExtension \"string with spaces\"\n"); EXPECT_EQ(code, EncodeAndDecodeSuccessfully(code)); }