Skip to content

Commit 4c9bfec

Browse files
committed
[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
1 parent 190f385 commit 4c9bfec

File tree

11 files changed

+48
-40
lines changed

11 files changed

+48
-40
lines changed

libc/test/src/math/exhaustive/exhaustive_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ void LlvmLibcExhaustiveTest<T>::test_full_range(T start, T stop, int nthreads,
3232
std::cout << msg.str();
3333
msg.str("");
3434

35-
bool result;
36-
check(begin, end, rounding, result);
35+
bool result = check(begin, end, rounding);
3736

3837
msg << "** Finished testing from " << std::dec << begin << " to " << end
3938
<< " [0x" << std::hex << begin << ", 0x" << end

libc/test/src/math/exhaustive/exhaustive_test.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ struct LlvmLibcExhaustiveTest : public __llvm_libc::testing::Test {
2222
void test_full_range(T start, T stop, int nthreads,
2323
mpfr::RoundingMode rounding);
2424

25-
virtual void check(T start, T stop, mpfr::RoundingMode rounding,
26-
bool &result) = 0;
25+
virtual bool check(T start, T stop, mpfr::RoundingMode rounding) = 0;
2726
};

libc/test/src/math/exhaustive/exp2f_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibcExp2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop,
20+
bool check(uint32_t start, uint32_t stop,
2121
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24+
bool result = true;
2425
do {
2526
FPBits xbits(bits);
2627
float x = float(xbits);
27-
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 0.5,
28-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x,
29+
__llvm_libc::exp2f(x), 0.5, rounding);
2930
} while (bits++ < stop);
31+
return result;
3032
}
3133
};
3234

libc/test/src/math/exhaustive/expf_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibcExpfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop,
20+
bool check(uint32_t start, uint32_t stop,
2121
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24+
bool result = true;
2425
do {
2526
FPBits xbits(bits);
2627
float x = float(xbits);
27-
EXPECT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 0.5,
28-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x),
29+
0.5, rounding);
2930
} while (bits++ < stop);
31+
return result;
3032
}
3133
};
3234

libc/test/src/math/exhaustive/expm1f_test.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibcExpfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop, mpfr::RoundingMode rounding,
21-
bool &result) override {
20+
bool check(uint32_t start, uint32_t stop,
21+
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24-
result = false;
24+
bool result = true;
2525
do {
2626
FPBits xbits(bits);
2727
float x = float(xbits);
28-
EXPECT_MPFR_MATCH(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 0.5,
29-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Expm1, x,
29+
__llvm_libc::expm1f(x), 0.5, rounding);
3030
} while (bits++ < stop);
31-
result = true;
3231
}
3332
};
3433

libc/test/src/math/exhaustive/hypotf_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,30 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1818
namespace mpfr = __llvm_libc::testing::mpfr;
1919

2020
struct LlvmLibcHypotfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
21-
void check(uint32_t start, uint32_t stop,
21+
bool check(uint32_t start, uint32_t stop,
2222
mpfr::RoundingMode rounding) override {
2323
// Range of the second input: [2^37, 2^48).
2424
constexpr uint32_t Y_START = (37U + 127U) << 23;
2525
constexpr uint32_t Y_STOP = (48U + 127U) << 23;
2626

2727
mpfr::ForceRoundingMode r(rounding);
2828
uint32_t xbits = start;
29+
bool result = true;
2930
do {
3031
float x = float(FPBits(xbits));
3132
uint32_t ybits = Y_START;
3233
do {
3334
float y = float(FPBits(ybits));
34-
EXPECT_FP_EQ(__llvm_libc::fputil::hypot(x, y),
35-
__llvm_libc::hypotf(x, y));
35+
result &= EXPECT_FP_EQ(__llvm_libc::fputil::hypot(x, y),
36+
__llvm_libc::hypotf(x, y));
3637
// Using MPFR will be much slower.
3738
// mpfr::BinaryInput<float> input{x, y};
3839
// EXPECT_MPFR_MATCH(mpfr::Operation::Hypot, input,
3940
// __llvm_libc::hypotf(x, y), 0.5,
4041
// rounding);
4142
} while (ybits++ < Y_STOP);
4243
} while (xbits++ < stop);
44+
return result;
4345
}
4446
};
4547

libc/test/src/math/exhaustive/log10f_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibcLog10fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop,
20+
bool check(uint32_t start, uint32_t stop,
2121
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24+
bool result = true;
2425
do {
2526
FPBits xbits(bits);
2627
float x = float(xbits);
27-
EXPECT_MPFR_MATCH(mpfr::Operation::Log10, x, __llvm_libc::log10f(x), 0.5,
28-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log10, x,
29+
__llvm_libc::log10f(x), 0.5, rounding);
2930
} while (bits++ < stop);
31+
return result;
3032
}
3133
};
3234

libc/test/src/math/exhaustive/log1pf_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibclog1pfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop,
20+
bool check(uint32_t start, uint32_t stop,
2121
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24+
bool result = true;
2425
do {
2526
FPBits xbits(bits);
2627
float x = float(xbits);
27-
EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, x, __llvm_libc::log1pf(x), 0.5,
28-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, x,
29+
__llvm_libc::log1pf(x), 0.5, rounding);
2930
} while (bits++ < stop);
31+
return result;
3032
}
3133
};
3234

libc/test/src/math/exhaustive/log2f_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibcLog2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop,
20+
bool check(uint32_t start, uint32_t stop,
2121
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24+
bool result = true;
2425
do {
2526
FPBits xbits(bits);
2627
float x = float(xbits);
27-
EXPECT_MPFR_MATCH(mpfr::Operation::Log2, x, __llvm_libc::log2f(x), 0.5,
28-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log2, x,
29+
__llvm_libc::log2f(x), 0.5, rounding);
2930
} while (bits++ < stop);
31+
return result;
3032
}
3133
};
3234

libc/test/src/math/exhaustive/logf_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ using FPBits = __llvm_libc::fputil::FPBits<float>;
1717
namespace mpfr = __llvm_libc::testing::mpfr;
1818

1919
struct LlvmLibcLogfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20-
void check(uint32_t start, uint32_t stop,
20+
bool check(uint32_t start, uint32_t stop,
2121
mpfr::RoundingMode rounding) override {
2222
mpfr::ForceRoundingMode r(rounding);
2323
uint32_t bits = start;
24+
bool result = true;
2425
do {
2526
FPBits xbits(bits);
2627
float x = float(xbits);
27-
EXPECT_MPFR_MATCH(mpfr::Operation::Log, x, __llvm_libc::logf(x), 0.5,
28-
rounding);
28+
result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log, x, __llvm_libc::logf(x),
29+
0.5, rounding);
2930
} while (bits++ < stop);
31+
return result;
3032
}
3133
};
3234

libc/utils/UnitTest/LibcTest.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,16 @@ template <typename... Types> using TypeList = internal::TypeList<Types...>;
387387
#define UNIQUE_VAR(prefix) __CAT(prefix, __LINE__)
388388

389389
#define EXPECT_THAT(MATCH, MATCHER) \
390-
do { \
390+
[&]() -> bool { \
391391
auto UNIQUE_VAR(__matcher) = (MATCHER); \
392-
this->testMatch(UNIQUE_VAR(__matcher).match((MATCH)), \
393-
UNIQUE_VAR(__matcher), #MATCH, #MATCHER, __FILE__, \
394-
__LINE__); \
395-
} while (0)
392+
return this->testMatch(UNIQUE_VAR(__matcher).match((MATCH)), \
393+
UNIQUE_VAR(__matcher), #MATCH, #MATCHER, __FILE__, \
394+
__LINE__); \
395+
}()
396396

397397
#define ASSERT_THAT(MATCH, MATCHER) \
398398
do { \
399-
auto UNIQUE_VAR(__matcher) = (MATCHER); \
400-
if (!this->testMatch(UNIQUE_VAR(__matcher).match((MATCH)), \
401-
UNIQUE_VAR(__matcher), #MATCH, #MATCHER, __FILE__, \
402-
__LINE__)) \
399+
if (!EXPECT_THAT(MATCH, MATCHER)) \
403400
return; \
404401
} while (0)
405402

0 commit comments

Comments
 (0)