From bb19d4a24b8326d278f61e68c6a09a3411e7cdde Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Thu, 7 Apr 2022 16:42:24 +0000 Subject: [PATCH] spirv: Remove AssembleFailure() tests These really test spirv-val, and by relying on its output, often fail when we upgrade spirv-tools. Change-Id: I146a2bf517328b5ef1945247c9ce0b1094ff6122 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86044 Reviewed-by: James Price Commit-Queue: Antonio Maiorano Reviewed-by: Ben Clayton --- src/tint/reader/spirv/function_memory_test.cc | 19 ---- .../reader/spirv/parser_impl_handle_test.cc | 32 ------- .../spirv/parser_impl_module_var_test.cc | 89 ------------------- .../reader/spirv/spirv_tools_helpers_test.cc | 20 ----- .../reader/spirv/spirv_tools_helpers_test.h | 5 -- 5 files changed, 165 deletions(-) diff --git a/src/tint/reader/spirv/function_memory_test.cc b/src/tint/reader/spirv/function_memory_test.cc index 4bbf9e5667..8e722bdf84 100644 --- a/src/tint/reader/spirv/function_memory_test.cc +++ b/src/tint/reader/spirv/function_memory_test.cc @@ -262,25 +262,6 @@ TEST_F(SpvParserMemoryTest, EXPECT_THAT(got, HasSubstr(expected)); } -TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_NoOperands) { - auto err = test::AssembleFailure(Preamble() + R"( - %void = OpTypeVoid - %voidfn = OpTypeFunction %void - %ty = OpTypeInt 32 0 - %val = OpConstant %ty 42 - %ptr_ty = OpTypePointer Private %ty - %1 = OpVariable %ptr_ty Private - %100 = OpFunction %void None %voidfn - %entry = OpLabel - - %2 = OpAccessChain %ptr_ty ; Needs a base operand - OpStore %1 %val - OpReturn - )"); - EXPECT_THAT(err, - Eq("16:5: Expected operand, found next instruction instead.")); -} - TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_BaseIsNotPointer) { auto p = parser(test::Assemble(Preamble() + R"( %void = OpTypeVoid diff --git a/src/tint/reader/spirv/parser_impl_handle_test.cc b/src/tint/reader/spirv/parser_impl_handle_test.cc index 8906eec9f5..a2e99adaec 100644 --- a/src/tint/reader/spirv/parser_impl_handle_test.cc +++ b/src/tint/reader/spirv/parser_impl_handle_test.cc @@ -2571,38 +2571,6 @@ TEST_F(SpvParserHandleTest, ImageWrite_TooFewSrcTexelComponents_1_vs_4) { << p->error(); } -TEST_F(SpvParserHandleTest, ImageWrite_ThreeComponentStorageTexture_IsError) { - // SPIR-V doesn't allow a 3-element storage texture format. - const auto assembly = Preamble() + R"( - OpEntryPoint Fragment %main "main" - OpExecutionMode %main OriginUpperLeft - OpName %vf123 "vf123" - OpName %coords12 "coords12" - OpDecorate %20 DescriptorSet 2 - OpDecorate %20 Binding 1 -)" + CommonBasicTypes() + - R"( - %im_ty = OpTypeImage %void 2D 0 0 0 2 Rgb32f - %ptr_im_ty = OpTypePointer UniformConstant %im_ty - - %20 = OpVariable %ptr_im_ty UniformConstant - - %main = OpFunction %void None %voidfn - %entry = OpLabel - - %vf123 = OpCopyObject %v3float %the_vf123 - - %coords12 = OpCopyObject %v2float %the_vf12 - - %im = OpLoad %im_ty %20 - OpImageWrite %im %coords12 %vf123 - OpReturn - OpFunctionEnd - )"; - auto error = test::AssembleFailure(assembly); - EXPECT_THAT(error, HasSubstr("Invalid image format 'Rgb32f'")); -} - INSTANTIATE_TEST_SUITE_P( // The texel operand signedness must match the channel type signedness. // SPIR-V validation checks that. diff --git a/src/tint/reader/spirv/parser_impl_module_var_test.cc b/src/tint/reader/spirv/parser_impl_module_var_test.cc index 714822d3f0..236840b263 100644 --- a/src/tint/reader/spirv/parser_impl_module_var_test.cc +++ b/src/tint/reader/spirv/parser_impl_module_var_test.cc @@ -1255,34 +1255,6 @@ TEST_F(SpvModuleScopeVarParserTest, StructUndefInitializer) { p->DeliberatelyInvalidSpirv(); } -TEST_F(SpvModuleScopeVarParserTest, - LocationDecoration_MissingOperandWontAssemble) { - const auto assembly = Preamble() + FragMain() + R"( - OpName %myvar "myvar" - OpDecorate %myvar Location -)" + CommonTypes() + R"( - %ptr = OpTypePointer Input %uint - %myvar = OpVariable %ptr Input - )" + MainBody(); - EXPECT_THAT(test::AssembleFailure(assembly), - Eq("10:4: Expected operand, found next instruction instead.")); -} - -TEST_F(SpvModuleScopeVarParserTest, - LocationDecoration_TwoOperandsWontAssemble) { - const auto assembly = Preamble() + FragMain() + R"( - OpName %myvar "myvar" - OpDecorate %myvar Location 3 4 -)" + CommonTypes() + R"( - %ptr = OpTypePointer Input %uint - %myvar = OpVariable %ptr Input - )" + MainBody(); - EXPECT_THAT( - test::AssembleFailure(assembly), - Eq("8:34: Expected or at the beginning of an " - "instruction, found '4'.")); -} - TEST_F(SpvModuleScopeVarParserTest, DescriptorGroupDecoration_Valid) { auto p = parser(test::Assemble(Preamble() + FragMain() + CommonLayout() + R"( OpDecorate %1 DescriptorSet 3 @@ -1302,36 +1274,6 @@ TEST_F(SpvModuleScopeVarParserTest, DescriptorGroupDecoration_Valid) { << module_str; } -TEST_F(SpvModuleScopeVarParserTest, - DescriptorGroupDecoration_MissingOperandWontAssemble) { - const auto assembly = Preamble() + FragMain() + CommonLayout() + R"( - OpDecorate %1 DescriptorSet - OpDecorate %strct Block -)" + CommonTypes() + StructTypes() + - R"( - %ptr_sb_strct = OpTypePointer StorageBuffer %strct - %1 = OpVariable %ptr_sb_strct StorageBuffer - )" + MainBody(); - EXPECT_THAT(test::AssembleFailure(assembly), - Eq("13:5: Expected operand, found next instruction instead.")); -} - -TEST_F(SpvModuleScopeVarParserTest, - DescriptorGroupDecoration_TwoOperandsWontAssemble) { - const auto assembly = Preamble() + FragMain() + R"( - OpName %myvar "myvar" - OpDecorate %myvar DescriptorSet 3 4 - OpDecorate %strct Block -)" + CommonTypes() + StructTypes() + - R"( - %ptr_sb_strct = OpTypePointer StorageBuffer %strct - %myvar = OpVariable %ptr_sb_strct StorageBuffer - )" + MainBody(); - EXPECT_THAT( - test::AssembleFailure(assembly), - Eq("8:39: Expected or at the beginning of an " - "instruction, found '4'.")); -} TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_Valid) { auto p = parser(test::Assemble(Preamble() + FragMain() + R"( @@ -1353,37 +1295,6 @@ TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_Valid) { << module_str; } -TEST_F(SpvModuleScopeVarParserTest, - BindingDecoration_MissingOperandWontAssemble) { - const auto assembly = Preamble() + FragMain() + R"( - OpName %myvar "myvar" - OpDecorate %myvar Binding - OpDecorate %strct Block -)" + CommonTypes() + StructTypes() + - R"( - %ptr_sb_strct = OpTypePointer StorageBuffer %strct - %myvar = OpVariable %ptr_sb_strct StorageBuffer - )" + MainBody(); - EXPECT_THAT(test::AssembleFailure(assembly), - Eq("9:5: Expected operand, found next instruction instead.")); -} - -TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_TwoOperandsWontAssemble) { - const auto assembly = Preamble() + FragMain() + R"( - OpName %myvar "myvar" - OpDecorate %myvar Binding 3 4 - OpDecorate %strct Block -)" + CommonTypes() + StructTypes() + - R"( - %ptr_sb_strct = OpTypePointer StorageBuffer %strct - %myvar = OpVariable %ptr_sb_strct StorageBuffer - )" + MainBody(); - EXPECT_THAT( - test::AssembleFailure(assembly), - Eq("8:33: Expected or at the beginning of an " - "instruction, found '4'.")); -} - TEST_F(SpvModuleScopeVarParserTest, StructMember_NonReadableDecoration_Dropped) { auto p = parser(test::Assemble(Preamble() + FragMain() + R"( diff --git a/src/tint/reader/spirv/spirv_tools_helpers_test.cc b/src/tint/reader/spirv/spirv_tools_helpers_test.cc index cb8b9cf9a4..a4862d0d83 100644 --- a/src/tint/reader/spirv/spirv_tools_helpers_test.cc +++ b/src/tint/reader/spirv/spirv_tools_helpers_test.cc @@ -43,26 +43,6 @@ std::vector Assemble(const std::string& spirv_assembly) { return result; } -std::string AssembleFailure(const std::string& spirv_assembly) { - // TODO(dneto): Use ScopedTrace? - - // (The target environment doesn't affect assembly. - spvtools::SpirvTools tools(SPV_ENV_UNIVERSAL_1_0); - std::stringstream errors; - std::vector result; - tools.SetMessageConsumer([&errors](spv_message_level_t, const char*, - const spv_position_t& position, - const char* message) { - errors << position.line << ":" << position.column << ": " << message; - }); - - const auto success = tools.Assemble( - spirv_assembly, &result, SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - EXPECT_FALSE(success); - - return errors.str(); -} - std::string Disassemble(const std::vector& spirv_module) { spvtools::SpirvTools tools(SPV_ENV_UNIVERSAL_1_0); std::stringstream errors; diff --git a/src/tint/reader/spirv/spirv_tools_helpers_test.h b/src/tint/reader/spirv/spirv_tools_helpers_test.h index 342ce2c0f4..929efd61ab 100644 --- a/src/tint/reader/spirv/spirv_tools_helpers_test.h +++ b/src/tint/reader/spirv/spirv_tools_helpers_test.h @@ -28,11 +28,6 @@ namespace test { /// are preserved. std::vector Assemble(const std::string& spirv_assembly); -/// Attempts to assemble given SPIR-V assembly text. Expect it to fail. -/// @param spirv_assembly the SPIR-V assembly -/// @returns the failure message. -std::string AssembleFailure(const std::string& spirv_assembly); - /// @param spirv_module a SPIR-V binary module /// @returns the disassembled module std::string Disassemble(const std::vector& spirv_module);