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 <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/resolver/const_eval_builtin_test.cc b/src/tint/resolver/const_eval_builtin_test.cc
index 21e6170..4b0ff0b 100644
--- a/src/tint/resolver/const_eval_builtin_test.cc
+++ b/src/tint/resolver/const_eval_builtin_test.cc
@@ -349,9 +349,9 @@
// 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 @@
// Vector tests
C({Vec(T(1.0), -T(1.0))}, Vec(T(0), kPi<T>)).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 @@
C({Vec(T(1.0), T(11.5919532755))}, Vec(T(0), kPi<T>)).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 @@
// Vector tests
C({Vec(T(0.0), T(1.0), -T(1.0))}, Vec(T(0.0), kPiOver2<T>, -kPiOver2<T>)).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 @@
template <typename T>
std::vector<Case> 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 @@
// 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( //
@@ -1473,68 +1484,6 @@
SmoothstepCases<f16>()))));
template <typename T>
-std::vector<Case> 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<AFloat>())));
-
-template <typename T>
-std::vector<Case> 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<f16>())));
-
-template <typename T>
-std::vector<Case> 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<f32>())));
-
-template <typename T>
std::vector<Case> StepCases() {
return {
C({T(0), T(0)}, T(1.0)),