[libc-commits] [PATCH] D136731: [libc] Add a testing macro for MPFR matchers skipping `explainError` calls.
Tue Ly via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Oct 25 19:16:15 PDT 2022
lntue created this revision.
lntue added reviewers: michaelrj, sivachandra.
Herald added subscribers: ecnelises, tschuett.
Herald added projects: libc-project, All.
lntue requested review of this revision.
Adding `EXPECT_MPFR_MATCH_ROUNDING_SILENTLY` macro that does not call
`explainError` when the tests fail. This is useful to check the passing or
failing rates, such as hitting percentages of fast passes in math
implementations.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136731
Files:
libc/utils/MPFRWrapper/MPFRUtils.h
libc/utils/UnitTest/LibcTest.cpp
libc/utils/UnitTest/LibcTest.h
Index: libc/utils/UnitTest/LibcTest.h
===================================================================
--- libc/utils/UnitTest/LibcTest.h
+++ libc/utils/UnitTest/LibcTest.h
@@ -53,6 +53,8 @@
virtual void explainError(testutils::StreamWrapper &OS) {
OS << "unknown error\n";
}
+ // Override and return true to skip `explainError` step.
+ virtual bool is_silent() const { return false; }
};
template <typename T> struct Matcher : public MatcherBase { bool match(T &t); };
Index: libc/utils/UnitTest/LibcTest.cpp
===================================================================
--- libc/utils/UnitTest/LibcTest.cpp
+++ libc/utils/UnitTest/LibcTest.cpp
@@ -310,10 +310,12 @@
return true;
Ctx->markFail();
- std::cout << File << ":" << Line << ": FAILURE\n"
- << "Failed to match " << LHSStr << " against " << RHSStr << ".\n";
- testutils::StreamWrapper OutsWrapper = testutils::outs();
- Matcher.explainError(OutsWrapper);
+ if (!Matcher.is_silent()) {
+ std::cout << File << ":" << Line << ": FAILURE\n"
+ << "Failed to match " << LHSStr << " against " << RHSStr << ".\n";
+ testutils::StreamWrapper OutsWrapper = testutils::outs();
+ Matcher.explainError(OutsWrapper);
+ }
return false;
}
Index: libc/utils/MPFRWrapper/MPFRUtils.h
===================================================================
--- libc/utils/MPFRWrapper/MPFRUtils.h
+++ libc/utils/MPFRWrapper/MPFRUtils.h
@@ -176,7 +176,7 @@
Operation op, const TernaryInput<T> &input, T match_value,
double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS);
-template <Operation op, typename InputType, typename OutputType>
+template <Operation op, bool silent, typename InputType, typename OutputType>
class MPFRMatcher : public testing::Matcher<OutputType> {
InputType input;
OutputType match_value;
@@ -198,6 +198,11 @@
explain_error(input, match_value, OS);
}
+ // Whether the `explainError` step is skipped or not.
+ bool is_silent() const override {
+ return silent;
+ }
+
private:
template <typename T> bool match(T in, T out) {
return compare_unary_operation_single_output(op, in, out, ulp_tolerance,
@@ -291,11 +296,23 @@
template <Operation op, typename InputType, typename OutputType>
__attribute__((no_sanitize("address")))
cpp::enable_if_t<is_valid_operation<op, InputType, OutputType>(),
- internal::MPFRMatcher<op, InputType, OutputType>>
+ internal::MPFRMatcher<op, /*is_silent*/ false,
+ InputType, OutputType>>
get_mpfr_matcher(InputType input, OutputType output_unused,
double ulp_tolerance, RoundingMode rounding) {
- return internal::MPFRMatcher<op, InputType, OutputType>(input, ulp_tolerance,
- rounding);
+ return internal::MPFRMatcher<op, /*is_silent*/ false, InputType, OutputType>(
+ input, ulp_tolerance, rounding);
+}
+
+template <Operation op, typename InputType, typename OutputType>
+__attribute__((no_sanitize("address")))
+cpp::enable_if_t<is_valid_operation<op, InputType, OutputType>(),
+ internal::MPFRMatcher<op, /*is_silent*/ true,
+ InputType, OutputType>>
+get_silent_mpfr_matcher(InputType input, OutputType output_unused,
+ double ulp_tolerance, RoundingMode rounding) {
+ return internal::MPFRMatcher<op, /*is_silent*/ true, InputType, OutputType>(
+ input, ulp_tolerance, rounding);
}
template <typename T> T round(T x, RoundingMode mode);
@@ -346,6 +363,12 @@
mpfr::RoundingMode::TowardZero); \
}
+#define EXPECT_MPFR_MATCH_ROUNDING_SILENTLY(op, input, match_value, \
+ ulp_tolerance, rounding) \
+ EXPECT_THAT(match_value, \
+ __llvm_libc::testing::mpfr::get_silent_mpfr_matcher<op>( \
+ input, match_value, ulp_tolerance, rounding))
+
#define ASSERT_MPFR_MATCH_DEFAULT(op, input, match_value, ulp_tolerance) \
ASSERT_THAT(match_value, \
__llvm_libc::testing::mpfr::get_mpfr_matcher<op>( \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136731.470681.patch
Type: text/x-patch
Size: 4372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221026/c814b019/attachment-0001.bin>
More information about the libc-commits
mailing list