Handle errors in SPIRV-Reader tests.

This CL updates some EXPECT to ASSERT in the spirv-reader tests to
work around segvs when tests fail.

Bug: tint:1686
Change-Id: Icfd5a83cc71709fd351c3d5a39a9a0173056a0f8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121340
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2023-02-23 21:51:15 +00:00 committed by Dawn LUCI CQ
parent 107aa81c89
commit 65a45fdf41
1 changed files with 16 additions and 16 deletions

View File

@ -28,7 +28,7 @@ const char* kSkipReason = "This example is deliberately a SPIR-V fragment";
TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_NotAnId) { TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_NotAnId) {
auto p = parser(test::Assemble("")); auto p = parser(test::Assemble(""));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(42); auto decorations = p->GetDecorationsFor(42);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -37,7 +37,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_NotAnId) {
TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_NoDecorations) { TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_NoDecorations) {
auto p = parser(test::Assemble("%1 = OpTypeVoid")); auto p = parser(test::Assemble("%1 = OpTypeVoid"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(1); auto decorations = p->GetDecorationsFor(1);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -50,7 +50,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_OneDecoration) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%10 = OpTypeStruct %float %10 = OpTypeStruct %float
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::Block)})); EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::Block)}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -64,7 +64,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_Duplicate) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%10 = OpTypeStruct %float %10 = OpTypeStruct %float
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::Block)})); EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::Block)}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -78,7 +78,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_MultiDecoration) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%5 = OpConstant %float 3.14 %5 = OpConstant %float 3.14
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(5); auto decorations = p->GetDecorationsFor(5);
EXPECT_THAT(decorations, EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)}, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)},
@ -89,7 +89,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_MultiDecoration) {
TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_NotAnId) { TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_NotAnId) {
auto p = parser(test::Assemble("")); auto p = parser(test::Assemble(""));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsForMember(42, 9); auto decorations = p->GetDecorationsForMember(42, 9);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -98,7 +98,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_NotAnId) {
TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_NotAStruct) { TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_NotAStruct) {
auto p = parser(test::Assemble("%1 = OpTypeVoid")); auto p = parser(test::Assemble("%1 = OpTypeVoid"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(1); auto decorations = p->GetDecorationsFor(1);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -110,7 +110,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_MemberWithoutDecorat
%uint = OpTypeInt 32 0 %uint = OpTypeInt 32 0
%10 = OpTypeStruct %uint %10 = OpTypeStruct %uint
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsForMember(10, 0); auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -123,7 +123,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_RelaxedPrecision) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%10 = OpTypeStruct %float %10 = OpTypeStruct %float
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 0); auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_THAT(decorations, EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)})); UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)}));
@ -138,7 +138,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_Duplicate) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%10 = OpTypeStruct %float %10 = OpTypeStruct %float
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 0); auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_THAT(decorations, EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)})); UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)}));
@ -155,7 +155,7 @@ TEST_F(SpvParserGetDecorationsTest, DISABLED_GetDecorationsForMember_OneDecorati
%arr = OpTypeArray %uint %uint_2 %arr = OpTypeArray %uint %uint_2
%10 = OpTypeStruct %uint %arr %10 = OpTypeStruct %uint %arr
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 1); auto decorations = p->GetDecorationsForMember(10, 1);
EXPECT_THAT(decorations, EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::ArrayStride), 12})); UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::ArrayStride), 12}));
@ -179,7 +179,7 @@ TEST_F(SpvParserGetDecorationsTest, DISABLED_GetDecorationsForMember_MultiDecora
%arr = OpTypeArray %mat %uint_2 %arr = OpTypeArray %mat %uint_2
%50 = OpTypeStruct %uint %float %arr %50 = OpTypeStruct %uint %float %arr
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->GetDecorationsForMember(50, 0).empty()); EXPECT_TRUE(p->GetDecorationsForMember(50, 0).empty());
EXPECT_THAT(p->GetDecorationsForMember(50, 1), EXPECT_THAT(p->GetDecorationsForMember(50, 1),
@ -199,7 +199,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_Restrict) {
%ptr = OpTypePointer Workgroup %float %ptr = OpTypePointer Workgroup %float
%10 = OpVariable %ptr Workgroup %10 = OpVariable %ptr Workgroup
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -215,7 +215,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_Restrict) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%10 = OpTypeStruct %float %10 = OpTypeStruct %float
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsForMember(10, 0); auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -230,7 +230,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_RestrictPointer) {
%ptr = OpTypePointer Workgroup %float %ptr = OpTypePointer Workgroup %float
%10 = OpVariable %ptr Workgroup %10 = OpVariable %ptr Workgroup
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
@ -246,7 +246,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_RestrictPointer) {
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%10 = OpTypeStruct %float %10 = OpTypeStruct %float
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_TRUE(decorations.empty()); EXPECT_TRUE(decorations.empty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());