From 15cf2344547bcd4d300aba22a96e9897153e50e1 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Thu, 26 Jul 2018 23:36:18 +0000 Subject: Unittest: added test for forcing and catching floating point errors (this works) --- test/src/unittests-math.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test') diff --git a/test/src/unittests-math.cpp b/test/src/unittests-math.cpp index 757c2dc..18e00f6 100644 --- a/test/src/unittests-math.cpp +++ b/test/src/unittests-math.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "gsl/gsl_matrix.h" #include @@ -166,3 +167,33 @@ TEST_CASE("fast_dgemm", "[math]") { REQUIRE(trunc(C[2003]) == -10627000400.0 ); } + +// The following code is normally disabled as it stops the unit tests! + +#ifdef TEST_SIGFPE + +#include +#include +#include +#include + +void sighandler(int signum) +{ + printf("Process %d got signal %d\n", getpid(), signum); + signal(signum, SIG_DFL); + kill(getpid(), signum); +} + +TEST_CASE("NaN handlers", "[math]") { + + signal(SIGFPE, sighandler); + feenableexcept(FE_INVALID | + FE_DIVBYZERO | + FE_OVERFLOW | + FE_UNDERFLOW); + double dirty = 0.0; + double nanval= 0.0/dirty; + printf("Succeeded! dirty=%lf, nanval=%lf\n",dirty,nanval); +} + +#endif // TEST_SIGFPE -- cgit v1.2.3