From e9a3d7d8840b7cfaccb5137d5a056f6a16c559ac Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 18 May 2021 06:57:58 +1000 Subject: [PATCH] debug/fpe: make tests a little more robust We run each of the signal handler tests in their own thread so that state is less likely to leak across tests. --- test/debug/fpe.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/test/debug/fpe.cpp b/test/debug/fpe.cpp index 9ec5ccd7..ac3b473b 100644 --- a/test/debug/fpe.cpp +++ b/test/debug/fpe.cpp @@ -11,14 +11,14 @@ /////////////////////////////////////////////////////////////////////////////// static int volatile fpe_value = 0; -static sigjmp_buf fpe_jump; +static jmp_buf fpe_jump; //----------------------------------------------------------------------------- -static void handle_fpe (int, siginfo_t*, void *) +static void handle_fpe (int) { fpe_value = 1; - siglongjmp (fpe_jump, 1); + longjmp (fpe_jump, 1); } @@ -31,10 +31,7 @@ float volatile zero_val = 0.f; //----------------------------------------------------------------------------- int main () { - struct sigaction fpe_sigaction {}; - fpe_sigaction.sa_flags = SA_RESTART; - fpe_sigaction.sa_sigaction = handle_fpe; - sigaction (SIGFPE, &fpe_sigaction, nullptr); + signal (SIGFPE, handle_fpe); cruft::TAP::logger tap; @@ -67,7 +64,7 @@ int main () std::thread ([] () { cruft::debug::fpe::enable (); fpe_value = 0; - if (!sigsetjmp (fpe_jump, 1)) + if (!setjmp (fpe_jump)) cruft::debug::escape (inf_val - inf_val); }).join (); tap.expect_eq (fpe_value, 1, "FE_INVALID is enabled after request"); @@ -75,7 +72,7 @@ int main () std::thread ([] () { cruft::debug::fpe::enable (); fpe_value = 0; - if (!sigsetjmp (fpe_jump, 1)) + if (!setjmp (fpe_jump)) cruft::debug::escape (1.f / zero_val); }).join (); tap.expect_eq (fpe_value, 1, "FE_DIVBYZERO is enabled after request"); @@ -83,7 +80,7 @@ int main () std::thread ([] () { fpe_value = 0; cruft::debug::fpe::scoped_reset resetter; - if (!sigsetjmp (fpe_jump, 1)) + if (!setjmp (fpe_jump)) cruft::debug::escape (inf_val - inf_val); }).join (); tap.expect_eq (fpe_value, 0, "scoped_reset enables exceptions"); @@ -93,14 +90,14 @@ int main () // Do a test beforehand just in case we've forgotten to reset the // fpe_value variable properly. - if (!sigsetjmp (fpe_jump, 1)) + if (!setjmp (fpe_jump)) cruft::debug::escape (inf_val - inf_val); { cruft::debug::fpe::scoped_reset resetter; } - if (!sigsetjmp (fpe_jump, 1)) + if (!setjmp (fpe_jump)) cruft::debug::escape (inf_val - inf_val); }).join (); tap.expect_eq (fpe_value, 0, "scoped_reset disables exceptions"); @@ -113,7 +110,7 @@ int main () cruft::debug::fpe::enable (); cruft::debug::fpe::scoped_reset resetter (false); - if (!sigsetjmp (fpe_jump, 1)) + if (!setjmp (fpe_jump)) cruft::debug::escape (inf_val - inf_val); }).join ();