diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2004-07-22 19:29:43 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2004-07-22 19:29:43 +0000 |
commit | 4e9b35d9185c2afdaf321fb363fc0c201ac931ab (patch) | |
tree | 7bb0cf3fe8a0cc463120735f19d35287468127e5 /regress | |
parent | f6fda8bcbc7a3a2680b61d6539a306bba6d54825 (diff) |
Split and modify tests to prevent infinite loops on platforms with precise
floating-point exceptions like amd64.
ok deraadt@, david@
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libc/ieeefp/except/Makefile | 16 | ||||
-rw-r--r-- | regress/lib/libc/ieeefp/except/except.c | 65 |
2 files changed, 47 insertions, 34 deletions
diff --git a/regress/lib/libc/ieeefp/except/Makefile b/regress/lib/libc/ieeefp/except/Makefile index ff620e016bb..205331548f2 100644 --- a/regress/lib/libc/ieeefp/except/Makefile +++ b/regress/lib/libc/ieeefp/except/Makefile @@ -1,5 +1,19 @@ -# $OpenBSD: Makefile,v 1.4 2002/02/18 11:22:26 art Exp $ +# $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ PROG=except +REGRESS_TARGETS+= fltdiv fltinv fltovf fltund + +fltdiv: ${PROG} + ./${PROG} fltdiv + +fltinv: ${PROG} + ./${PROG} fltinv + +fltovf: ${PROG} + ./${PROG} fltovf + +fltund: ${PROG} + ./${PROG} fltund + .include <bsd.regress.mk> diff --git a/regress/lib/libc/ieeefp/except/except.c b/regress/lib/libc/ieeefp/except/except.c index 4e8c17d427a..f95fa1fdbda 100644 --- a/regress/lib/libc/ieeefp/except/except.c +++ b/regress/lib/libc/ieeefp/except/except.c @@ -1,4 +1,4 @@ -/* $OpenBSD: except.c,v 1.6 2004/04/02 03:06:12 mickey Exp $ */ +/* $OpenBSD: except.c,v 1.7 2004/07/22 19:29:42 kettenis Exp $ */ #include <stdio.h> #include <stdlib.h> @@ -6,8 +6,9 @@ #include <assert.h> #include <ieeefp.h> #include <float.h> +#include <err.h> -volatile sig_atomic_t signal_caught; +volatile int signal_status; volatile const double one = 1.0; volatile const double zero = 0.0; @@ -24,7 +25,7 @@ sigfpe(int sig, siginfo_t *si, void *v) si->si_addr, si->si_code); write(1, buf, strlen(buf)); } - signal_caught = 1; + _exit(signal_status); } @@ -34,6 +35,11 @@ main(int argc, char *argv[]) struct sigaction sa; volatile double x; + if (argc != 2) { + fprintf(stderr, "usage: %s condition\n", argv[0]); + exit(1); + } + /* * check to make sure that all exceptions are masked and * that the accumulated exception status is clear. @@ -45,56 +51,49 @@ main(int argc, char *argv[]) sa.sa_sigaction = sigfpe; sa.sa_flags = SA_SIGINFO; sigaction(SIGFPE, &sa, NULL); - signal_caught = 0; + signal_status = 1; /* trip divide by zero */ x = one / zero; assert(fpgetsticky() & FP_X_DZ); - assert(signal_caught == 0); fpsetsticky(0); /* trip invalid operation */ x = zero / zero; assert(fpgetsticky() & FP_X_INV); - assert(signal_caught == 0); fpsetsticky(0); /* trip overflow */ x = huge * huge; assert(fpgetsticky() & FP_X_OFL); - assert(signal_caught == 0); fpsetsticky(0); /* trip underflow */ x = tiny * tiny; assert(fpgetsticky() & FP_X_UFL); - assert(signal_caught == 0); fpsetsticky(0); - /* unmask and then trip divide by zero */ - fpsetmask(FP_X_DZ); - x = one / zero; - assert(signal_caught == 1); - signal_caught = 0; - - /* unmask and then trip invalid operation */ - fpsetmask(FP_X_INV); - x = zero / zero; - assert(signal_caught == 1); - signal_caught = 0; - - /* unmask and then trip overflow */ - fpsetmask(FP_X_OFL); - x = huge * huge; - assert(signal_caught == 1); - signal_caught = 0; - - /* unmask and then trip underflow */ - fpsetmask(FP_X_UFL); - x = tiny * tiny; - assert (signal_caught == 1); - signal_caught = 0; + signal_status = 0; + + if (strcmp(argv[1], "fltdiv") == 0) { + /* unmask and then trip divide by zero */ + fpsetmask(FP_X_DZ); + x = one / zero; + } else if (strcmp(argv[1], "fltinv") == 0) { + /* unmask and then trip invalid operation */ + fpsetmask(FP_X_INV); + x = zero / zero; + } else if (strcmp(argv[1], "fltovf") == 0) { + /* unmask and then trip overflow */ + fpsetmask(FP_X_OFL); + x = huge * huge; + } else if (strcmp(argv[1], "fltund") == 0) { + /* unmask and then trip underflow */ + fpsetmask(FP_X_UFL); + x = tiny * tiny; + } else { + errx(1, "unrecognized condition %s", argv[1]); + } - exit(0); + errx(1, "signal wasn't caught"); } - |