From 68124ab7d1467f74afc2edd51614c95f351aeb30 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 3 Oct 2022 20:22:47 +0000 Subject: [PATCH] Add missing robustness tests. A few of the robustness tests were missing due to lack of shadow and override support when robustness was implemented. This CL adds and enables the missing tests. Change-Id: I3e4526a21b2d0106d0756e67de258c5441c6f8b8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104468 Reviewed-by: Ben Clayton Commit-Queue: Dan Sinclair Kokoro: Kokoro --- src/tint/transform/robustness_test.cc | 149 ++++++++++++++++++-------- 1 file changed, 107 insertions(+), 42 deletions(-) diff --git a/src/tint/transform/robustness_test.cc b/src/tint/transform/robustness_test.cc index dd02d996ee..9c610d4e44 100644 --- a/src/tint/transform/robustness_test.cc +++ b/src/tint/transform/robustness_test.cc @@ -701,44 +701,95 @@ var a : mat3x2; )"; auto got = Run(src); - EXPECT_EQ(expect, str(got)); } -// TODO(dsinclair): Implement when constant_id exists -TEST_F(RobustnessTest, DISABLED_Vector_Constant_Id_Clamps) { - // @id(1300) override idx : i32; - // var a : vec3 - // var b : f32 = a[idx] - // - // ->var b : f32 = a[min(u32(idx), 2)] +TEST_F(RobustnessTest, Vector_Constant_Id_Clamps) { + auto* src = R"( +@id(1300) override idx : i32; +fn f() { + var a : vec3; + var b : f32 = a[idx]; +} +)"; + + auto* expect = R"( +@id(1300) override idx : i32; + +fn f() { + var a : vec3; + var b : f32 = a[min(u32(idx), 2u)]; +} +)"; + + auto got = Run(src); + EXPECT_EQ(expect, str(got)); } -// TODO(dsinclair): Implement when constant_id exists -TEST_F(RobustnessTest, DISABLED_Array_Constant_Id_Clamps) { - // @id(1300) override idx : i32; - // var a : array - // var b : f32 = a[idx] - // - // -> var b : f32 = a[min(u32(idx), 3)] +TEST_F(RobustnessTest, Array_Constant_Id_Clamps) { + auto* src = R"( +@id(1300) override idx : i32; +fn f() { + var a : array; + var b : f32 = a[idx]; +} +)"; + + auto* expect = R"( +@id(1300) override idx : i32; + +fn f() { + var a : array; + var b : f32 = a[min(u32(idx), 3u)]; +} +)"; + + auto got = Run(src); + EXPECT_EQ(expect, str(got)); } -// TODO(dsinclair): Implement when constant_id exists -TEST_F(RobustnessTest, DISABLED_Matrix_Column_Constant_Id_Clamps) { - // @id(1300) override idx : i32; - // var a : mat3x2 - // var b : f32 = a[idx][1] - // - // -> var b : f32 = a[min(u32(idx), 2)][1] +TEST_F(RobustnessTest, Matrix_Column_Constant_Id_Clamps) { + auto* src = R"( +@id(1300) override idx : i32; +fn f() { + var a : mat3x2; + var b : f32 = a[idx][1]; +} +)"; + + auto* expect = R"( +@id(1300) override idx : i32; + +fn f() { + var a : mat3x2; + var b : f32 = a[min(u32(idx), 2u)][1]; +} +)"; + + auto got = Run(src); + EXPECT_EQ(expect, str(got)); } -// TODO(dsinclair): Implement when constant_id exists -TEST_F(RobustnessTest, DISABLED_Matrix_Row_Constant_Id_Clamps) { - // @id(1300) override idx : i32; - // var a : mat3x2 - // var b : f32 = a[1][idx] - // - // -> var b : f32 = a[1][min(u32(idx), 0, 1)] +TEST_F(RobustnessTest, Matrix_Row_Constant_Id_Clamps) { + auto* src = R"( +@id(1300) override idx : i32; +fn f() { + var a : mat3x2; + var b : f32 = a[1][idx]; +} +)"; + + auto* expect = R"( +@id(1300) override idx : i32; + +fn f() { + var a : mat3x2; + var b : f32 = a[1][min(u32(idx), 1u)]; +} +)"; + + auto got = Run(src); + EXPECT_EQ(expect, str(got)); } TEST_F(RobustnessTest, RuntimeArray_Clamps) { @@ -1019,19 +1070,33 @@ fn f() { EXPECT_EQ(expect, str(got)); } -// TODO(dsinclair): Test for scoped variables when shadowing is implemented -TEST_F(RobustnessTest, DISABLED_Shadowed_Variable) { - // var a : array; - // var i : u32; - // { - // var a : array; - // var b : f32 = a[i]; - // } - // var c : f32 = a[i]; - // - // -> var b : f32 = a[min(u32(i), 4)]; - // var c : f32 = a[min(u32(i), 2)]; - FAIL(); +TEST_F(RobustnessTest, Shadowed_Variable) { + auto* src = R"( +fn f() { + var a : array; + var i : u32; + { + var a : array; + var b : f32 = a[i]; + } + var c : f32 = a[i]; +} +)"; + + auto* expect = R"( +fn f() { + var a : array; + var i : u32; + { + var a : array; + var b : f32 = a[min(i, 4u)]; + } + var c : f32 = a[min(i, 2u)]; +} +)"; + + auto got = Run(src); + EXPECT_EQ(expect, str(got)); } // Check that existing use of min() and arrayLength() do not get renamed.