[libc-commits] [libc] 4c9bfec - [libc] Let exhaustive tests indicate each interval PASSED/FAILED.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Wed Mar 16 06:56:19 PDT 2022


Author: Tue Ly
Date: 2022-03-16T09:56:03-04:00
New Revision: 4c9bfec67c6269f1744cbade70b3c8053d5d5da4

URL: https://github.com/llvm/llvm-project/commit/4c9bfec67c6269f1744cbade70b3c8053d5d5da4
DIFF: https://github.com/llvm/llvm-project/commit/4c9bfec67c6269f1744cbade70b3c8053d5d5da4.diff

LOG: [libc] Let exhaustive tests indicate each interval PASSED/FAILED.

Let exhaustive tests indicate each interval PASSED/FAILED.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D121564

Added: 
    

Modified: 
    libc/test/src/math/exhaustive/exhaustive_test.cpp
    libc/test/src/math/exhaustive/exhaustive_test.h
    libc/test/src/math/exhaustive/exp2f_test.cpp
    libc/test/src/math/exhaustive/expf_test.cpp
    libc/test/src/math/exhaustive/expm1f_test.cpp
    libc/test/src/math/exhaustive/hypotf_test.cpp
    libc/test/src/math/exhaustive/log10f_test.cpp
    libc/test/src/math/exhaustive/log1pf_test.cpp
    libc/test/src/math/exhaustive/log2f_test.cpp
    libc/test/src/math/exhaustive/logf_test.cpp
    libc/utils/UnitTest/LibcTest.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/exhaustive/exhaustive_test.cpp b/libc/test/src/math/exhaustive/exhaustive_test.cpp
index 450c53bf628d7..227a9a113ba84 100644
--- a/libc/test/src/math/exhaustive/exhaustive_test.cpp
+++ b/libc/test/src/math/exhaustive/exhaustive_test.cpp
@@ -32,8 +32,7 @@ void LlvmLibcExhaustiveTest<T>::test_full_range(T start, T stop, int nthreads,
       std::cout << msg.str();
       msg.str("");
 
-      bool result;
-      check(begin, end, rounding, result);
+      bool result = check(begin, end, rounding);
 
       msg << "** Finished testing from " << std::dec << begin << " to " << end
           << " [0x" << std::hex << begin << ", 0x" << end

diff  --git a/libc/test/src/math/exhaustive/exhaustive_test.h b/libc/test/src/math/exhaustive/exhaustive_test.h
index 36f794eec9bc5..4c7d5ae1f0667 100644
--- a/libc/test/src/math/exhaustive/exhaustive_test.h
+++ b/libc/test/src/math/exhaustive/exhaustive_test.h
@@ -22,6 +22,5 @@ struct LlvmLibcExhaustiveTest : public __llvm_libc::testing::Test {
   void test_full_range(T start, T stop, int nthreads,
                        mpfr::RoundingMode rounding);
 
-  virtual void check(T start, T stop, mpfr::RoundingMode rounding,
-                     bool &result) = 0;
+  virtual bool check(T start, T stop, mpfr::RoundingMode rounding) = 0;
 };

diff  --git a/libc/test/src/math/exhaustive/exp2f_test.cpp b/libc/test/src/math/exhaustive/exp2f_test.cpp
index 48fa434ff332b..d6e4b566158b9 100644
--- a/libc/test/src/math/exhaustive/exp2f_test.cpp
+++ b/libc/test/src/math/exhaustive/exp2f_test.cpp
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcExp2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x,
+                                  __llvm_libc::exp2f(x), 0.5, rounding);
     } while (bits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/expf_test.cpp b/libc/test/src/math/exhaustive/expf_test.cpp
index a53d2aaf16b8b..e5d3924cc4fa3 100644
--- a/libc/test/src/math/exhaustive/expf_test.cpp
+++ b/libc/test/src/math/exhaustive/expf_test.cpp
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcExpfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x),
+                                  0.5, rounding);
     } while (bits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/expm1f_test.cpp b/libc/test/src/math/exhaustive/expm1f_test.cpp
index fb134b54825e0..8a4cf762b2695 100644
--- a/libc/test/src/math/exhaustive/expm1f_test.cpp
+++ b/libc/test/src/math/exhaustive/expm1f_test.cpp
@@ -17,18 +17,17 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcExpfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop, mpfr::RoundingMode rounding,
-             bool &result) override {
+  bool check(uint32_t start, uint32_t stop,
+             mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
-    result = false;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Expm1, x,
+                                  __llvm_libc::expm1f(x), 0.5, rounding);
     } while (bits++ < stop);
-    result = true;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/hypotf_test.cpp b/libc/test/src/math/exhaustive/hypotf_test.cpp
index 34ce5b0ab8f85..e07d16db1eaae 100644
--- a/libc/test/src/math/exhaustive/hypotf_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotf_test.cpp
@@ -18,7 +18,7 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcHypotfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     // Range of the second input: [2^37, 2^48).
     constexpr uint32_t Y_START = (37U + 127U) << 23;
@@ -26,13 +26,14 @@ struct LlvmLibcHypotfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
 
     mpfr::ForceRoundingMode r(rounding);
     uint32_t xbits = start;
+    bool result = true;
     do {
       float x = float(FPBits(xbits));
       uint32_t ybits = Y_START;
       do {
         float y = float(FPBits(ybits));
-        EXPECT_FP_EQ(__llvm_libc::fputil::hypot(x, y),
-                     __llvm_libc::hypotf(x, y));
+        result &= EXPECT_FP_EQ(__llvm_libc::fputil::hypot(x, y),
+                               __llvm_libc::hypotf(x, y));
         // Using MPFR will be much slower.
         // mpfr::BinaryInput<float> input{x, y};
         // EXPECT_MPFR_MATCH(mpfr::Operation::Hypot, input,
@@ -40,6 +41,7 @@ struct LlvmLibcHypotfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
         //                   rounding);
       } while (ybits++ < Y_STOP);
     } while (xbits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/log10f_test.cpp b/libc/test/src/math/exhaustive/log10f_test.cpp
index f8739ef0de7ca..830f21308057f 100644
--- a/libc/test/src/math/exhaustive/log10f_test.cpp
+++ b/libc/test/src/math/exhaustive/log10f_test.cpp
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcLog10fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Log10, x, __llvm_libc::log10f(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log10, x,
+                                  __llvm_libc::log10f(x), 0.5, rounding);
     } while (bits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/log1pf_test.cpp b/libc/test/src/math/exhaustive/log1pf_test.cpp
index 5f2705a522dea..8fa26b0f933f3 100644
--- a/libc/test/src/math/exhaustive/log1pf_test.cpp
+++ b/libc/test/src/math/exhaustive/log1pf_test.cpp
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibclog1pfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, x, __llvm_libc::log1pf(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, x,
+                                  __llvm_libc::log1pf(x), 0.5, rounding);
     } while (bits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/log2f_test.cpp b/libc/test/src/math/exhaustive/log2f_test.cpp
index c15be03c51e94..a6a544caae487 100644
--- a/libc/test/src/math/exhaustive/log2f_test.cpp
+++ b/libc/test/src/math/exhaustive/log2f_test.cpp
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcLog2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Log2, x, __llvm_libc::log2f(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log2, x,
+                                  __llvm_libc::log2f(x), 0.5, rounding);
     } while (bits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/test/src/math/exhaustive/logf_test.cpp b/libc/test/src/math/exhaustive/logf_test.cpp
index 85827a48d0bff..459c60d001479 100644
--- a/libc/test/src/math/exhaustive/logf_test.cpp
+++ b/libc/test/src/math/exhaustive/logf_test.cpp
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 struct LlvmLibcLogfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
-  void check(uint32_t start, uint32_t stop,
+  bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = start;
+    bool result = true;
     do {
       FPBits xbits(bits);
       float x = float(xbits);
-      EXPECT_MPFR_MATCH(mpfr::Operation::Log, x, __llvm_libc::logf(x), 0.5,
-                        rounding);
+      result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log, x, __llvm_libc::logf(x),
+                                  0.5, rounding);
     } while (bits++ < stop);
+    return result;
   }
 };
 

diff  --git a/libc/utils/UnitTest/LibcTest.h b/libc/utils/UnitTest/LibcTest.h
index a9dfbcbb4966a..e9a18cf84094e 100644
--- a/libc/utils/UnitTest/LibcTest.h
+++ b/libc/utils/UnitTest/LibcTest.h
@@ -387,19 +387,16 @@ template <typename... Types> using TypeList = internal::TypeList<Types...>;
 #define UNIQUE_VAR(prefix) __CAT(prefix, __LINE__)
 
 #define EXPECT_THAT(MATCH, MATCHER)                                            \
-  do {                                                                         \
+  [&]() -> bool {                                                              \
     auto UNIQUE_VAR(__matcher) = (MATCHER);                                    \
-    this->testMatch(UNIQUE_VAR(__matcher).match((MATCH)),                      \
-                    UNIQUE_VAR(__matcher), #MATCH, #MATCHER, __FILE__,         \
-                    __LINE__);                                                 \
-  } while (0)
+    return this->testMatch(UNIQUE_VAR(__matcher).match((MATCH)),               \
+                           UNIQUE_VAR(__matcher), #MATCH, #MATCHER, __FILE__,  \
+                           __LINE__);                                          \
+  }()
 
 #define ASSERT_THAT(MATCH, MATCHER)                                            \
   do {                                                                         \
-    auto UNIQUE_VAR(__matcher) = (MATCHER);                                    \
-    if (!this->testMatch(UNIQUE_VAR(__matcher).match((MATCH)),                 \
-                         UNIQUE_VAR(__matcher), #MATCH, #MATCHER, __FILE__,    \
-                         __LINE__))                                            \
+    if (!EXPECT_THAT(MATCH, MATCHER))                                          \
       return;                                                                  \
   } while (0)
 


        


More information about the libc-commits mailing list