From 399e1958904c4c167e3bc4f17daca5a4926f5edf Mon Sep 17 00:00:00 2001 From: kettenis <> Date: Thu, 22 Jul 2004 19:29:42 +0000 Subject: Split and modify tests to prevent infinite loops on platforms with precise floating-point exceptions like amd64. ok deraadt@, david@ --- src/regress/lib/libc/ieeefp/except/Makefile | 16 ++++++- src/regress/lib/libc/ieeefp/except/except.c | 65 ++++++++++++++--------------- 2 files changed, 47 insertions(+), 34 deletions(-) (limited to 'src/regress/lib/libc') diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile index ff620e016b..205331548f 100644 --- a/src/regress/lib/libc/ieeefp/except/Makefile +++ b/src/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 diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c index 4e8c17d427..f95fa1fdbd 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/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 #include @@ -6,8 +6,9 @@ #include #include #include +#include -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"); } - -- cgit v1.2.3-55-g6feb