diff --git a/libc/test/src/fenv/enabled_exceptions_test.cpp b/libc/test/src/fenv/enabled_exceptions_test.cpp --- a/libc/test/src/fenv/enabled_exceptions_test.cpp +++ b/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 run in a different thread. So, we enable + // the exception again so that the exception gets enabled in + // the child thread. + __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 --- a/libc/test/src/fenv/feholdexcept_test.cpp +++ b/libc/test/src/fenv/feholdexcept_test.cpp @@ -28,9 +28,19 @@ // 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 in this closure because in some test frameworks like Fuchsia's + // zxtest, this translates to a death test in which this closure is + // run in a different thread. By setting the old environment inside + // the closure sets the environment for that different thread as well. + __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); } }