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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc24c18bba61f: [libc] Accommodate Fuchsia's death test framework in fenv tests. (authored by sivachandra).

Changed prior to commit:
  https://reviews.llvm.org/D106683?vs=361266&id=361364#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106683/new/

https://reviews.llvm.org/D106683

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


Index: libc/test/src/fenv/feholdexcept_test.cpp
===================================================================
--- libc/test/src/fenv/feholdexcept_test.cpp
+++ libc/test/src/fenv/feholdexcept_test.cpp
@@ -28,9 +28,20 @@
     // 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 different 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);
   }
 }
Index: libc/test/src/fenv/enabled_exceptions_test.cpp
===================================================================
--- libc/test/src/fenv/enabled_exceptions_test.cpp
+++ libc/test/src/fenv/enabled_exceptions_test.cpp
@@ -49,6 +49,17 @@
       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 different 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);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106683.361364.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210723/b71a5c1f/attachment.bin>


More information about the libc-commits mailing list