From f5eec817de0df46d5aa2a7205f5b2f9c02e98dd4 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Mon, 21 Nov 2022 15:29:54 +0000 Subject: [PATCH] tint: enable smoothstep error tests for f32 and f16 ...now that we correctly fail on inf/nan. Also fold separate error test functions into SmoothstepCases. Also fixed atanh, acos, acosh, and asin tests to properly test error cases for all float types, not just abstract float. Bug: tint:1581 Bug: tint:1747 Change-Id: I63bd57d36beab4cc7dde501183052aa688e2efdb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110727 Kokoro: Kokoro Reviewed-by: Ben Clayton --- src/tint/resolver/const_eval_builtin_test.cc | 89 +++++--------------- 1 file changed, 19 insertions(+), 70 deletions(-) diff --git a/src/tint/resolver/const_eval_builtin_test.cc b/src/tint/resolver/const_eval_builtin_test.cc index 21e6170f02..4b0ff0b92f 100644 --- a/src/tint/resolver/const_eval_builtin_test.cc +++ b/src/tint/resolver/const_eval_builtin_test.cc @@ -349,9 +349,9 @@ std::vector AtanhCases() { // Vector tests C({Vec(T(0.0), T(0.9), -T(0.9))}, Vec(T(0.0), T(1.4722193), -T(1.4722193))).FloatComp(), - E({1.1_a}, + E({T(1.1)}, "12:34 error: atanh must be called with a value in the range (-1 .. 1) (exclusive)"), - E({-1.1_a}, + E({-T(1.1)}, "12:34 error: atanh must be called with a value in the range (-1 .. 1) (exclusive)"), }; } @@ -375,9 +375,9 @@ std::vector AcosCases() { // Vector tests C({Vec(T(1.0), -T(1.0))}, Vec(T(0), kPi)).FloatComp(), - E({1.1_a}, + E({T(1.1)}, "12:34 error: acos must be called with a value in the range [-1 .. 1] (inclusive)"), - E({-1.1_a}, + E({-T(1.1)}, "12:34 error: acos must be called with a value in the range [-1 .. 1] (inclusive)"), }; } @@ -399,8 +399,8 @@ std::vector AcoshCases() { C({Vec(T(1.0), T(11.5919532755))}, Vec(T(0), kPi)).FloatComp(), E({T::Smallest()}, "12:34 error: acosh must be called with a value >= 1.0"), - E({-1.1_a}, "12:34 error: acosh must be called with a value >= 1.0"), - E({0_a}, "12:34 error: acosh must be called with a value >= 1.0"), + E({-T(1.1)}, "12:34 error: acosh must be called with a value >= 1.0"), + E({T(0)}, "12:34 error: acosh must be called with a value >= 1.0"), }; } INSTANTIATE_TEST_SUITE_P( // @@ -424,9 +424,9 @@ std::vector AsinCases() { // Vector tests C({Vec(T(0.0), T(1.0), -T(1.0))}, Vec(T(0.0), kPiOver2, -kPiOver2)).FloatComp(), - E({1.1_a}, + E({T(1.1)}, "12:34 error: asin must be called with a value in the range [-1 .. 1] (inclusive)"), - E({-1.1_a}, + E({-T(1.1)}, "12:34 error: asin must be called with a value in the range [-1 .. 1] (inclusive)"), }; } @@ -1452,6 +1452,10 @@ INSTANTIATE_TEST_SUITE_P( // template std::vector SmoothstepCases() { + auto error_msg = [](auto a, const char* op, auto b) { + return "12:34 error: " + OverflowErrorMessage(a, op, b) + R"( +12:34 note: when calculating smoothstep)"; + }; return { // t == 0 C({T(4), T(6), T(2)}, T(0)), @@ -1462,6 +1466,13 @@ std::vector SmoothstepCases() { // Vector tests C({Vec(T(4), T(4)), Vec(T(6), T(6)), Vec(T(2), T(8))}, Vec(T(0), T(1))), + + // `x - low` underflows + E({T::Highest(), T(1), T::Lowest()}, error_msg(T::Lowest(), "-", T::Highest())), + // `high - low` underflows + E({T::Highest(), T::Lowest(), T(0)}, error_msg(T::Lowest(), "-", T::Highest())), + // Divide by zero on `(x - low) / (high - low)` + E({T(0), T(0), T(0)}, error_msg(T(0), "/", T(0))), }; } INSTANTIATE_TEST_SUITE_P( // @@ -1472,68 +1483,6 @@ INSTANTIATE_TEST_SUITE_P( // SmoothstepCases(), SmoothstepCases())))); -template -std::vector SmoothstepAFloatErrorCases() { - auto error_msg = [](auto a, const char* op, auto b) { - return "12:34 error: " + OverflowErrorMessage(a, op, b) + R"( -12:34 note: when calculating smoothstep)"; - }; - - return {// `x - low` underflows - E({T::Highest(), T(1), T::Lowest()}, error_msg(T::Lowest(), "-", T::Highest())), - // `high - low` underflows - E({T::Highest(), T::Lowest(), T(0)}, error_msg(T::Lowest(), "-", T::Highest())), - // Divid by zero on `(x - low) / (high - low)` - E({T(0), T(0), T(0)}, error_msg(T(0), "/", T(0)))}; -} -INSTANTIATE_TEST_SUITE_P( // - SmoothstepAFloatError, - ResolverConstEvalBuiltinTest, - testing::Combine(testing::Values(sem::BuiltinType::kSmoothstep), - testing::ValuesIn(SmoothstepAFloatErrorCases()))); - -template -std::vector SmoothstepF16ErrorCases() { - auto error_msg = [](auto a, const char* op, auto b) { - return "12:34 error: " + OverflowErrorMessage(a, op, b) + R"( -12:34 note: when calculating smoothstep)"; - }; - - return {// `x - low` underflows - E({T::Highest(), T(1), T::Lowest()}, error_msg(T::Lowest(), "-", T::Highest())), - // `high - low` underflows - E({T::Highest(), T::Lowest(), T(0)}, error_msg(T::Lowest(), "-", T::Highest())), - // Divid by zero on `(x - low) / (high - low)` - E({T(0), T(0), T(0)}, error_msg(T(0), "/", T(0)))}; -} -// TODO(crbug.com/tint/1581): Enable when non-abstract math is checked. -INSTANTIATE_TEST_SUITE_P( // - DISABLED_SmoothstepF16Error, - ResolverConstEvalBuiltinTest, - testing::Combine(testing::Values(sem::BuiltinType::kSmoothstep), - testing::ValuesIn(SmoothstepF16ErrorCases()))); - -template -std::vector SmoothstepF32ErrorCases() { - auto error_msg = [](auto a, const char* op, auto b) { - return "12:34 error: " + OverflowErrorMessage(a, op, b) + R"( -12:34 note: when calculating smoothstep)"; - }; - - return {// `x - low` underflows - E({T::Highest(), T(1), T::Lowest()}, error_msg(T::Lowest(), "-", T::Highest())), - // `high - low` underflows - E({T::Highest(), T::Lowest(), T(0)}, error_msg(T::Lowest(), "-", T::Highest())), - // Divid by zero on `(x - low) / (high - low)` - E({T(0), T(0), T(0)}, error_msg(T(0), "/", T(0)))}; -} -// TODO(crbug.com/tint/1581): Enable when non-abstract math is checked. -INSTANTIATE_TEST_SUITE_P( // - DISABLED_SmoothstepF32Error, - ResolverConstEvalBuiltinTest, - testing::Combine(testing::Values(sem::BuiltinType::kSmoothstep), - testing::ValuesIn(SmoothstepF32ErrorCases()))); - template std::vector StepCases() { return {