[libc] Clean up errno header usage in a few math/smoke tests. (#157517) Most of the unit tests don't (or don't need to) read/write libc_errno code directly - it's cleared by the ErrnoCheckingTest harness, and is verified by framework-provided scripts such as EXPECT_MATH_ERRNO. Use the following rule of thumb for header inclusion: * if you use libc_errno in code literally, include src/__support/libc_errno.h * if you only rely on errno constants, include hdr/errno_macros.h This PR only updates a few tests for acos/asin variants, as a proof-of-concept. If it goes in, a follow-up PR would update the rest. GitOrigin-RevId: 05502de64ccf1793a49e2f7c80ca1afe5d1e0f43
diff --git a/test/src/math/smoke/CMakeLists.txt b/test/src/math/smoke/CMakeLists.txt index c9cbd8b..9c99b8a 100644 --- a/test/src/math/smoke/CMakeLists.txt +++ b/test/src/math/smoke/CMakeLists.txt
@@ -4652,7 +4652,7 @@ SRCS asinhf_test.cpp DEPENDS - libc.src.errno.errno + libc.hdr.errno_macros libc.src.math.asinhf libc.src.__support.FPUtil.fp_bits ) @@ -4664,7 +4664,7 @@ SRCS asinhf16_test.cpp DEPENDS - libc.src.errno.errno + libc.hdr.errno_macros libc.src.math.asinhf16 ) @@ -4676,8 +4676,8 @@ SRCS asinpif16_test.cpp DEPENDS + libc.hdr.errno_macros libc.src.math.asinpif16 - libc.src.errno.errno ) add_fp_unittest( @@ -4687,7 +4687,7 @@ SRCS acoshf_test.cpp DEPENDS - libc.src.errno.errno + libc.hdr.errno_macros libc.src.math.acoshf libc.src.__support.FPUtil.fp_bits ) @@ -4699,7 +4699,7 @@ SRCS acoshf16_test.cpp DEPENDS - libc.src.errno.errno + libc.hdr.errno_macros libc.src.math.acoshf16 libc.src.__support.FPUtil.cast ) @@ -4711,7 +4711,7 @@ SRCS asinf_test.cpp DEPENDS - libc.src.errno.errno + libc.hdr.errno_macros libc.src.math.asinf libc.src.__support.FPUtil.fp_bits ) @@ -4733,8 +4733,8 @@ SRCS asinf16_test.cpp DEPENDS - libc.src.errno.errno - libc.src.math.asinf16 + libc.hdr.errno_macros + libc.src.math.asinf16 ) add_fp_unittest( @@ -4744,7 +4744,7 @@ SRCS acosf_test.cpp DEPENDS - libc.src.errno.errno + libc.hdr.errno_macros libc.src.math.acosf libc.src.__support.FPUtil.fp_bits ) @@ -4756,8 +4756,8 @@ SRCS acos_test.cpp DEPENDS + libc.hdr.errno_macros libc.hdr.fenv_macros - libc.src.errno.errno libc.src.math.acos ) @@ -4768,8 +4768,8 @@ SRCS acosf16_test.cpp DEPENDS - libc.src.errno.errno - libc.src.math.acosf16 + libc.hdr.errno_macros + libc.src.math.acosf16 ) add_fp_unittest( @@ -4779,8 +4779,8 @@ SRCS acospif16_test.cpp DEPENDS - libc.src.errno.errno - libc.src.math.acospif16 + libc.hdr.errno_macros + libc.src.math.acospif16 ) add_fp_unittest(
diff --git a/test/src/math/smoke/acos_test.cpp b/test/src/math/smoke/acos_test.cpp index fe2caef..2b2fa75 100644 --- a/test/src/math/smoke/acos_test.cpp +++ b/test/src/math/smoke/acos_test.cpp
@@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "hdr/errno_macros.h" #include "hdr/fenv_macros.h" -#include "src/__support/libc_errno.h" #include "src/math/acos.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -18,10 +18,10 @@ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(sNaN), FE_INVALID); EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(aNaN)); + EXPECT_MATH_ERRNO(0); EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(zero)); EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(neg_zero)); - libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(inf), FE_INVALID); EXPECT_MATH_ERRNO(EDOM);
diff --git a/test/src/math/smoke/acosf16_test.cpp b/test/src/math/smoke/acosf16_test.cpp index 7103dc3..6cc170d 100644 --- a/test/src/math/smoke/acosf16_test.cpp +++ b/test/src/math/smoke/acosf16_test.cpp
@@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/libc_errno.h" +#include "hdr/errno_macros.h" #include "src/math/acosf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -15,7 +15,6 @@ using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; TEST_F(LlvmLibcAcosf16Test, SpecialNumbers) { - libc_errno = 0; EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acosf16(aNaN)); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/acosf_test.cpp b/test/src/math/smoke/acosf_test.cpp index 733610a..e9a90a1 100644 --- a/test/src/math/smoke/acosf_test.cpp +++ b/test/src/math/smoke/acosf_test.cpp
@@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// +#include "hdr/errno_macros.h" #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/libc_errno.h" #include "src/math/acosf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -18,8 +18,6 @@ using LlvmLibcAcosfTest = LIBC_NAMESPACE::testing::FPTest<float>; TEST_F(LlvmLibcAcosfTest, SpecialNumbers) { - libc_errno = 0; - EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acosf(sNaN), FE_INVALID); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/acoshf16_test.cpp b/test/src/math/smoke/acoshf16_test.cpp index 6b9c995..b020de4 100644 --- a/test/src/math/smoke/acoshf16_test.cpp +++ b/test/src/math/smoke/acoshf16_test.cpp
@@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "hdr/errno_macros.h" #include "src/__support/FPUtil/cast.h" -#include "src/__support/libc_errno.h" #include "src/math/acoshf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -15,7 +15,6 @@ using LlvmLibcAcoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) { - libc_errno = 0; EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acoshf16(aNaN)); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/acoshf_test.cpp b/test/src/math/smoke/acoshf_test.cpp index 19556b2..6918980 100644 --- a/test/src/math/smoke/acoshf_test.cpp +++ b/test/src/math/smoke/acoshf_test.cpp
@@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// +#include "hdr/errno_macros.h" #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/libc_errno.h" #include "src/math/acoshf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -18,8 +18,6 @@ using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>; TEST_F(LlvmLibcAcoshfTest, SpecialNumbers) { - libc_errno = 0; - EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acoshf(sNaN), FE_INVALID); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/acospif16_test.cpp b/test/src/math/smoke/acospif16_test.cpp index 4b2f6de..0669d21 100644 --- a/test/src/math/smoke/acospif16_test.cpp +++ b/test/src/math/smoke/acospif16_test.cpp
@@ -6,14 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/libc_errno.h" +#include "hdr/errno_macros.h" #include "src/math/acospif16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>; TEST_F(LlvmLibcAcospif16Test, SpecialNumbers) { - libc_errno = 0; EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(aNaN)); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/asinf16_test.cpp b/test/src/math/smoke/asinf16_test.cpp index b03f0a4..fa118bb 100644 --- a/test/src/math/smoke/asinf16_test.cpp +++ b/test/src/math/smoke/asinf16_test.cpp
@@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/libc_errno.h" +#include "hdr/errno_macros.h" #include "src/math/asinf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -15,7 +15,6 @@ using LlvmLibcAsinf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; TEST_F(LlvmLibcAsinf16Test, SpecialNumbers) { - libc_errno = 0; EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::asinf16(aNaN)); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/asinf_test.cpp b/test/src/math/smoke/asinf_test.cpp index 6195a11..2135ed3 100644 --- a/test/src/math/smoke/asinf_test.cpp +++ b/test/src/math/smoke/asinf_test.cpp
@@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// +#include "hdr/errno_macros.h" #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/libc_errno.h" #include "src/math/asinf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -18,8 +18,6 @@ using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>; TEST_F(LlvmLibcAsinfTest, SpecialNumbers) { - libc_errno = 0; - EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::asinf(sNaN), FE_INVALID); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/asinhf16_test.cpp b/test/src/math/smoke/asinhf16_test.cpp index 7f612ce..f17300c 100644 --- a/test/src/math/smoke/asinhf16_test.cpp +++ b/test/src/math/smoke/asinhf16_test.cpp
@@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/libc_errno.h" +#include "hdr/errno_macros.h" #include "src/math/asinhf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -14,7 +14,6 @@ using LlvmLibcAsinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; TEST_F(LlvmLibcAsinhf16Test, SpecialNumbers) { - libc_errno = 0; EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::asinhf16(aNaN)); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/asinhf_test.cpp b/test/src/math/smoke/asinhf_test.cpp index e6326c1..d053a50 100644 --- a/test/src/math/smoke/asinhf_test.cpp +++ b/test/src/math/smoke/asinhf_test.cpp
@@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// +#include "hdr/errno_macros.h" #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/libc_errno.h" #include "src/math/asinhf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -18,8 +18,6 @@ using LlvmLibcAsinhfTest = LIBC_NAMESPACE::testing::FPTest<float>; TEST_F(LlvmLibcAsinhfTest, SpecialNumbers) { - libc_errno = 0; - EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::asinhf(sNaN), FE_INVALID); EXPECT_MATH_ERRNO(0);
diff --git a/test/src/math/smoke/asinpif16_test.cpp b/test/src/math/smoke/asinpif16_test.cpp index 5303eed..328da7f 100644 --- a/test/src/math/smoke/asinpif16_test.cpp +++ b/test/src/math/smoke/asinpif16_test.cpp
@@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/libc_errno.h" +#include "hdr/errno_macros.h" #include "src/math/asinpif16.h" #include "test/UnitTest/FPMatcher.h" @@ -26,13 +26,12 @@ EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(FPBits::signaling_nan().get_val())); + EXPECT_MATH_ERRNO(0); // infinity inputs -> should return NaN - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(inf)); EXPECT_MATH_ERRNO(EDOM); - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(neg_inf)); EXPECT_MATH_ERRNO(EDOM); @@ -40,29 +39,24 @@ TEST_F(LlvmLibcAsinpif16Test, OutOfRange) { // Test values > 1 - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(1.5f16)); EXPECT_MATH_ERRNO(EDOM); - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(2.0f16)); EXPECT_MATH_ERRNO(EDOM); // Test values < -1 - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(-1.5f16)); EXPECT_MATH_ERRNO(EDOM); - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(-2.0f16)); EXPECT_MATH_ERRNO(EDOM); // Test maximum normal value (should be > 1 for float16) - libc_errno = 0; EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(FPBits::max_normal().get_val())); EXPECT_MATH_ERRNO(EDOM);