[libc-commits] [libc] [libc] Make a couple of math smoke tests more robust. (PR #120808)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Fri Dec 20 15:42:16 PST 2024


https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/120808

Make sure to clear out all FE_ALL_EXCEPT bits both before and after invoking function under test -- otherwise the very first check for the exception bits in the unit test may fail due to bits set prior to test invocation.

>From 7f435b77b6a21c2a028bfdd9d08ab5e81d958750 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Fri, 20 Dec 2024 15:38:21 -0800
Subject: [PATCH] [libc] Make a couple of math smoke tests more robust.

Make sure to clear out all FE_ALL_EXCEPT bits both before and after
invoking function under test -- otherwise the very first check for
the exception bits in the unit test may fail due to bits set prior
to test invocation.
---
 libc/test/src/math/smoke/CanonicalizeTest.h | 1 +
 libc/test/src/math/smoke/FModTest.h         | 1 +
 2 files changed, 2 insertions(+)

diff --git a/libc/test/src/math/smoke/CanonicalizeTest.h b/libc/test/src/math/smoke/CanonicalizeTest.h
index ef75f568b8275b..e500bc38f98524 100644
--- a/libc/test/src/math/smoke/CanonicalizeTest.h
+++ b/libc/test/src/math/smoke/CanonicalizeTest.h
@@ -19,6 +19,7 @@
 #include "hdr/math_macros.h"
 
 #define TEST_SPECIAL(x, y, expected, expected_exception)                       \
+  LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);                         \
   EXPECT_EQ(expected, f(&x, &y));                                              \
   EXPECT_FP_EXCEPTION(expected_exception);                                     \
   LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT)
diff --git a/libc/test/src/math/smoke/FModTest.h b/libc/test/src/math/smoke/FModTest.h
index ad9688fc01e7c1..387ed29b350c55 100644
--- a/libc/test/src/math/smoke/FModTest.h
+++ b/libc/test/src/math/smoke/FModTest.h
@@ -18,6 +18,7 @@
 #include "hdr/fenv_macros.h"
 
 #define TEST_SPECIAL(x, y, expected, dom_err, expected_exception)              \
+  LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);			       \
   EXPECT_FP_EQ(expected, f(x, y));                                             \
   EXPECT_MATH_ERRNO((dom_err) ? EDOM : 0);                                     \
   EXPECT_FP_EXCEPTION(expected_exception);                                     \



More information about the libc-commits mailing list