Skip to content

Commit 417ea79

Browse files
committed
[libc] Enable hermetic floating point tests
This patch enables us to run the floating point tests as hermetic. Importantly we now use the internal versions of the `fesetround` and `fegetround` functions. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D151123
1 parent e86defd commit 417ea79

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

libc/test/UnitTest/RoundingModeUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "RoundingModeUtils.h"
1010

11-
#include <fenv.h>
11+
#include "src/__support/FPUtil/FEnvImpl.h"
1212

1313
namespace __llvm_libc {
1414
namespace fputil {
@@ -34,15 +34,15 @@ int get_fe_rounding(RoundingMode mode) {
3434
}
3535

3636
ForceRoundingMode::ForceRoundingMode(RoundingMode mode) {
37-
old_rounding_mode = fegetround();
37+
old_rounding_mode = get_round();
3838
rounding_mode = get_fe_rounding(mode);
3939
if (old_rounding_mode != rounding_mode)
40-
fesetround(rounding_mode);
40+
set_round(rounding_mode);
4141
}
4242

4343
ForceRoundingMode::~ForceRoundingMode() {
4444
if (old_rounding_mode != rounding_mode)
45-
fesetround(old_rounding_mode);
45+
set_round(old_rounding_mode);
4646
}
4747

4848
} // namespace testing

libc/test/src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function(add_fp_unittest name)
22
cmake_parse_arguments(
33
"MATH_UNITTEST"
4-
"NEED_MPFR;HERMETIC_TEST_ONLY" # Optional arguments
4+
"NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
55
"" # Single value arguments
66
"LINK_LIBRARIES" # Multi-value arguments
77
${ARGN}
@@ -16,6 +16,8 @@ function(add_fp_unittest name)
1616

1717
if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
1818
set(test_type HERMETIC_TEST_ONLY)
19+
elseif(MATH_UNITTEST_UNIT_TEST_ONLY)
20+
set(test_type UNIT_TEST_ONLY)
1921
endif()
2022
if(MATH_UNITTEST_NEED_MPFR)
2123
if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
@@ -26,7 +28,7 @@ function(add_fp_unittest name)
2628
endif()
2729
list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
2830

29-
add_libc_unittest(
31+
add_libc_test(
3032
${name}
3133
${test_type}
3234
LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"

libc/test/src/fenv/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ if (NOT (LLVM_USE_SANITIZER OR (${LIBC_TARGET_OS} STREQUAL "windows")
106106
libc.src.__support.FPUtil.fenv_impl
107107
LINK_LIBRARIES
108108
LibcFPExceptionHelpers
109+
UNIT_TEST_ONLY
109110
)
110111

111112
add_fp_unittest(
@@ -120,5 +121,6 @@ if (NOT (LLVM_USE_SANITIZER OR (${LIBC_TARGET_OS} STREQUAL "windows")
120121
libc.src.__support.FPUtil.fenv_impl
121122
LINK_LIBRARIES
122123
LibcFPExceptionHelpers
124+
UNIT_TEST_ONLY
123125
)
124126
endif()

0 commit comments

Comments
 (0)