[libc-commits] [PATCH] D151123: [libc] Enable hermetic floating point tests

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon May 22 10:28:25 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: sivachandra, lntue, michaelrj.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151123

Files:
  libc/test/UnitTest/RoundingModeUtils.cpp
  libc/test/src/CMakeLists.txt
  libc/test/src/fenv/CMakeLists.txt


Index: libc/test/src/fenv/CMakeLists.txt
===================================================================
--- libc/test/src/fenv/CMakeLists.txt
+++ libc/test/src/fenv/CMakeLists.txt
@@ -106,6 +106,7 @@
       libc.src.__support.FPUtil.fenv_impl
     LINK_LIBRARIES
       LibcFPExceptionHelpers
+    UNIT_TEST_ONLY
   )
 
   add_fp_unittest(
@@ -120,5 +121,6 @@
       libc.src.__support.FPUtil.fenv_impl
     LINK_LIBRARIES
       LibcFPExceptionHelpers
+    UNIT_TEST_ONLY
   )
 endif()
Index: libc/test/src/CMakeLists.txt
===================================================================
--- libc/test/src/CMakeLists.txt
+++ libc/test/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 function(add_fp_unittest name)
   cmake_parse_arguments(
     "MATH_UNITTEST"
-    "NEED_MPFR;HERMETIC_TEST_ONLY" # Optional arguments
+    "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
     "" # Single value arguments
     "LINK_LIBRARIES" # Multi-value arguments
     ${ARGN}
@@ -16,6 +16,8 @@
 
   if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
     set(test_type HERMETIC_TEST_ONLY)
+  elseif(MATH_UNITTEST_UNIT_TEST_ONLY)
+    set(test_type UNIT_TEST_ONLY)
   endif()
   if(MATH_UNITTEST_NEED_MPFR)
     if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
@@ -26,7 +28,7 @@
   endif()
   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
 
-  add_libc_unittest(
+  add_libc_test(
     ${name}
     ${test_type}
     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
Index: libc/test/UnitTest/RoundingModeUtils.cpp
===================================================================
--- libc/test/UnitTest/RoundingModeUtils.cpp
+++ libc/test/UnitTest/RoundingModeUtils.cpp
@@ -8,7 +8,7 @@
 
 #include "RoundingModeUtils.h"
 
-#include <fenv.h>
+#include "src/__support/FPUtil/FEnvImpl.h"
 
 namespace __llvm_libc {
 namespace fputil {
@@ -34,15 +34,15 @@
 }
 
 ForceRoundingMode::ForceRoundingMode(RoundingMode mode) {
-  old_rounding_mode = fegetround();
+  old_rounding_mode = get_round();
   rounding_mode = get_fe_rounding(mode);
   if (old_rounding_mode != rounding_mode)
-    fesetround(rounding_mode);
+    set_round(rounding_mode);
 }
 
 ForceRoundingMode::~ForceRoundingMode() {
   if (old_rounding_mode != rounding_mode)
-    fesetround(old_rounding_mode);
+    set_round(old_rounding_mode);
 }
 
 } // namespace testing


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151123.524382.patch
Type: text/x-patch
Size: 2319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230522/a4ff16e6/attachment.bin>


More information about the libc-commits mailing list