[libc-commits] [libc] c24c18b - [libc] Accommodate Fuchsia's death test framework in fenv tests.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Fri Jul 23 15:19:19 PDT 2021


Author: Siva Chandra Reddy
Date: 2021-07-23T22:19:04Z
New Revision: c24c18bba61fa4e9e5513b70cd133ec39eaf9e25

URL: https://github.com/llvm/llvm-project/commit/c24c18bba61fa4e9e5513b70cd133ec39eaf9e25
DIFF: https://github.com/llvm/llvm-project/commit/c24c18bba61fa4e9e5513b70cd133ec39eaf9e25.diff

LOG: [libc] Accommodate Fuchsia's death test framework in fenv tests.

Fuchsia's death test framework runs the closure which can die in a
different thread. Hence, the FP exceptions which cause the closure to
die should be enalbed in the closure.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D106683

Added: 
    

Modified: 
    libc/test/src/fenv/enabled_exceptions_test.cpp
    libc/test/src/fenv/feholdexcept_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/fenv/enabled_exceptions_test.cpp b/libc/test/src/fenv/enabled_exceptions_test.cpp
index 52191e00b64c..c30d6753debb 100644
--- a/libc/test/src/fenv/enabled_exceptions_test.cpp
+++ b/libc/test/src/fenv/enabled_exceptions_test.cpp
@@ -49,6 +49,17 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
       ASSERT_EQ(__llvm_libc::fetestexcept(others), others);
     }
 
-    ASSERT_RAISES_FP_EXCEPT([=] { __llvm_libc::feraiseexcept(e); });
+    ASSERT_RAISES_FP_EXCEPT([=] {
+      // In test frameworks like Fuchsia's zxtest, this translates to
+      // a death test which runs this closure in a 
diff erent thread. So,
+      // we enable the exception again inside this closure so that the
+      // exception gets enabled for the thread running this closure.
+      __llvm_libc::fputil::enableExcept(e);
+      __llvm_libc::feraiseexcept(e);
+    });
+
+    // Cleanup.
+    __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT);
+    ASSERT_EQ(__llvm_libc::feclearexcept(FE_ALL_EXCEPT), 0);
   }
 }

diff  --git a/libc/test/src/fenv/feholdexcept_test.cpp b/libc/test/src/fenv/feholdexcept_test.cpp
index 3cb305a82ce2..2f7b74178776 100644
--- a/libc/test/src/fenv/feholdexcept_test.cpp
+++ b/libc/test/src/fenv/feholdexcept_test.cpp
@@ -28,9 +28,20 @@ TEST(LlvmLibcFEnvTest, RaiseAndCrash) {
     // should not crash/invoke the exception handler.
     ASSERT_EQ(__llvm_libc::fputil::raiseExcept(e), 0);
 
-    // When we put back the saved env which has the exception enabled, it
-    // should crash with SIGFPE.
-    __llvm_libc::fputil::setEnv(&env);
-    ASSERT_RAISES_FP_EXCEPT([=] { __llvm_libc::fputil::raiseExcept(e); });
+    ASSERT_RAISES_FP_EXCEPT([=] {
+      // When we put back the saved env, which has the exception enabled, it
+      // should crash with SIGFPE. Note that we set the old environment
+      // back inside this closure because in some test frameworks like Fuchsia's
+      // zxtest, this test translates to a death test in which this closure is
+      // run in a 
diff erent thread. So, we set the old environment inside
+      // this closure so that the exception gets enabled for the thread running
+      // this closure.
+      __llvm_libc::fputil::setEnv(&env);
+      __llvm_libc::fputil::raiseExcept(e);
+    });
+
+    // Cleanup
+    __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT);
+    ASSERT_EQ(__llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT), 0);
   }
 }


        


More information about the libc-commits mailing list