about summary refs log tree commit diff
path: root/test/src
diff options
context:
space:
mode:
authorPjotr Prins2018-07-26 23:36:18 +0000
committerPjotr Prins2018-07-26 23:36:18 +0000
commit15cf2344547bcd4d300aba22a96e9897153e50e1 (patch)
tree7f0b29d823f56cadebd99247ea7a8e4f97f5874b /test/src
parentd42329ed84e99f9ab351af291c42dbd06ca9cb59 (diff)
downloadpangemma-15cf2344547bcd4d300aba22a96e9897153e50e1.tar.gz
Unittest: added test for forcing and catching floating point errors (this works)
Diffstat (limited to 'test/src')
-rw-r--r--test/src/unittests-math.cpp31
1 files changed, 31 insertions, 0 deletions
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 <catch.hpp>
 #include <iostream>
+#include <fenv.h>
 #include "gsl/gsl_matrix.h"
 #include <cblas.h>
 
@@ -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 <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+
+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