diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2010-10-20 13:53:07 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2010-12-17 16:57:18 -0500 |
commit | de2e51dacb1ccd312c0461088b942ef4e93e2731 (patch) | |
tree | beef075a1c991fab129c545ae56e01c564ded619 | |
parent | a2afcc9ba4ed5a2843fd133ca23704960846185b (diff) |
Add enable_fp_exceptions() function in utils.[ch]
This function enables floating point traps if possible.
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | test/utils.c | 26 | ||||
-rw-r--r-- | test/utils.h | 3 |
3 files changed, 37 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 147e1bfb..2570c840 100644 --- a/configure.ac +++ b/configure.ac @@ -639,6 +639,14 @@ if test x$have_getpagesize = xyes; then AC_DEFINE(HAVE_GETPAGESIZE, 1, [Whether we have getpagesize()]) fi +AC_CHECK_HEADER([fenv.h], + [AC_DEFINE(HAVE_FENV_H, [1], [Define to 1 if we have <fenv.h>])]) + +AC_CHECK_LIB(m, feenableexcept, have_feenableexcept=yes, have_feenableexcept=no) +if test x$have_feenableexcept = xyes; then + AC_DEFINE(HAVE_FEENABLEEXCEPT, 1, [Whether we have feenableexcept()]) +fi + AC_CHECK_FUNC(gettimeofday, have_gettimeofday=yes, have_gettimeofday=no) AC_CHECK_HEADER(sys/time.h, have_sys_time_h=yes, have_sys_time_h=no) if test x$have_gettimeofday = xyes && test x$have_sys_time_h = xyes; then diff --git a/test/utils.c b/test/utils.c index f6278fec..a7c55f6d 100644 --- a/test/utils.c +++ b/test/utils.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include "utils.h" #include <signal.h> @@ -15,6 +17,10 @@ #include <sys/mman.h> #endif +#ifdef HAVE_FENV_H +#include <fenv.h> +#endif + /* Random number seed */ @@ -469,6 +475,26 @@ fail_after (int seconds, const char *msg) #endif } +void +enable_fp_exceptions (void) +{ +#ifdef HAVE_FENV_H +#ifdef HAVE_FEENABLEEXCEPT + /* Note: we don't enable the FE_INEXACT trap because + * that happens quite commonly. It is possible that + * over- and underflow should similarly be considered + * okay, but for now the test suite passes with them + * enabled, and it's useful to know if they start + * occuring. + */ + feenableexcept (FE_DIVBYZERO | + FE_INVALID | + FE_OVERFLOW | + FE_UNDERFLOW); +#endif +#endif +} + void * aligned_malloc (size_t align, size_t size) { diff --git a/test/utils.h b/test/utils.h index 2ea41705..bac29169 100644 --- a/test/utils.h +++ b/test/utils.h @@ -82,6 +82,9 @@ fuzzer_test_main (const char *test_name, void fail_after (int seconds, const char *msg); +/* If possible, enable traps for floating point exceptions */ +void enable_fp_exceptions(void); + /* A pair of macros which can help to detect corruption of * floating point registers after a function call. This may * happen if _mm_empty() call is forgotten in MMX/SSE2 fast |