diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/Makefile | 16 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/except.c | 65 |
2 files changed, 47 insertions, 34 deletions
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 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:22:26 art Exp $ | 1 | # $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ |
| 2 | 2 | ||
| 3 | PROG=except | 3 | PROG=except |
| 4 | 4 | ||
| 5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund | ||
| 6 | |||
| 7 | fltdiv: ${PROG} | ||
| 8 | ./${PROG} fltdiv | ||
| 9 | |||
| 10 | fltinv: ${PROG} | ||
| 11 | ./${PROG} fltinv | ||
| 12 | |||
| 13 | fltovf: ${PROG} | ||
| 14 | ./${PROG} fltovf | ||
| 15 | |||
| 16 | fltund: ${PROG} | ||
| 17 | ./${PROG} fltund | ||
| 18 | |||
| 5 | .include <bsd.regress.mk> | 19 | .include <bsd.regress.mk> |
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 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.6 2004/04/02 03:06:12 mickey Exp $ */ | 1 | /* $OpenBSD: except.c,v 1.7 2004/07/22 19:29:42 kettenis Exp $ */ |
| 2 | 2 | ||
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| @@ -6,8 +6,9 @@ | |||
| 6 | #include <assert.h> | 6 | #include <assert.h> |
| 7 | #include <ieeefp.h> | 7 | #include <ieeefp.h> |
| 8 | #include <float.h> | 8 | #include <float.h> |
| 9 | #include <err.h> | ||
| 9 | 10 | ||
| 10 | volatile sig_atomic_t signal_caught; | 11 | volatile int signal_status; |
| 11 | 12 | ||
| 12 | volatile const double one = 1.0; | 13 | volatile const double one = 1.0; |
| 13 | volatile const double zero = 0.0; | 14 | volatile const double zero = 0.0; |
| @@ -24,7 +25,7 @@ sigfpe(int sig, siginfo_t *si, void *v) | |||
| 24 | si->si_addr, si->si_code); | 25 | si->si_addr, si->si_code); |
| 25 | write(1, buf, strlen(buf)); | 26 | write(1, buf, strlen(buf)); |
| 26 | } | 27 | } |
| 27 | signal_caught = 1; | 28 | _exit(signal_status); |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | 31 | ||
| @@ -34,6 +35,11 @@ main(int argc, char *argv[]) | |||
| 34 | struct sigaction sa; | 35 | struct sigaction sa; |
| 35 | volatile double x; | 36 | volatile double x; |
| 36 | 37 | ||
| 38 | if (argc != 2) { | ||
| 39 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
| 40 | exit(1); | ||
| 41 | } | ||
| 42 | |||
| 37 | /* | 43 | /* |
| 38 | * check to make sure that all exceptions are masked and | 44 | * check to make sure that all exceptions are masked and |
| 39 | * that the accumulated exception status is clear. | 45 | * that the accumulated exception status is clear. |
| @@ -45,56 +51,49 @@ main(int argc, char *argv[]) | |||
| 45 | sa.sa_sigaction = sigfpe; | 51 | sa.sa_sigaction = sigfpe; |
| 46 | sa.sa_flags = SA_SIGINFO; | 52 | sa.sa_flags = SA_SIGINFO; |
| 47 | sigaction(SIGFPE, &sa, NULL); | 53 | sigaction(SIGFPE, &sa, NULL); |
| 48 | signal_caught = 0; | 54 | signal_status = 1; |
| 49 | 55 | ||
| 50 | /* trip divide by zero */ | 56 | /* trip divide by zero */ |
| 51 | x = one / zero; | 57 | x = one / zero; |
| 52 | assert(fpgetsticky() & FP_X_DZ); | 58 | assert(fpgetsticky() & FP_X_DZ); |
| 53 | assert(signal_caught == 0); | ||
| 54 | fpsetsticky(0); | 59 | fpsetsticky(0); |
| 55 | 60 | ||
| 56 | /* trip invalid operation */ | 61 | /* trip invalid operation */ |
| 57 | x = zero / zero; | 62 | x = zero / zero; |
| 58 | assert(fpgetsticky() & FP_X_INV); | 63 | assert(fpgetsticky() & FP_X_INV); |
| 59 | assert(signal_caught == 0); | ||
| 60 | fpsetsticky(0); | 64 | fpsetsticky(0); |
| 61 | 65 | ||
| 62 | /* trip overflow */ | 66 | /* trip overflow */ |
| 63 | x = huge * huge; | 67 | x = huge * huge; |
| 64 | assert(fpgetsticky() & FP_X_OFL); | 68 | assert(fpgetsticky() & FP_X_OFL); |
| 65 | assert(signal_caught == 0); | ||
| 66 | fpsetsticky(0); | 69 | fpsetsticky(0); |
| 67 | 70 | ||
| 68 | /* trip underflow */ | 71 | /* trip underflow */ |
| 69 | x = tiny * tiny; | 72 | x = tiny * tiny; |
| 70 | assert(fpgetsticky() & FP_X_UFL); | 73 | assert(fpgetsticky() & FP_X_UFL); |
| 71 | assert(signal_caught == 0); | ||
| 72 | fpsetsticky(0); | 74 | fpsetsticky(0); |
| 73 | 75 | ||
| 74 | /* unmask and then trip divide by zero */ | 76 | signal_status = 0; |
| 75 | fpsetmask(FP_X_DZ); | 77 | |
| 76 | x = one / zero; | 78 | if (strcmp(argv[1], "fltdiv") == 0) { |
| 77 | assert(signal_caught == 1); | 79 | /* unmask and then trip divide by zero */ |
| 78 | signal_caught = 0; | 80 | fpsetmask(FP_X_DZ); |
| 79 | 81 | x = one / zero; | |
| 80 | /* unmask and then trip invalid operation */ | 82 | } else if (strcmp(argv[1], "fltinv") == 0) { |
| 81 | fpsetmask(FP_X_INV); | 83 | /* unmask and then trip invalid operation */ |
| 82 | x = zero / zero; | 84 | fpsetmask(FP_X_INV); |
| 83 | assert(signal_caught == 1); | 85 | x = zero / zero; |
| 84 | signal_caught = 0; | 86 | } else if (strcmp(argv[1], "fltovf") == 0) { |
| 85 | 87 | /* unmask and then trip overflow */ | |
| 86 | /* unmask and then trip overflow */ | 88 | fpsetmask(FP_X_OFL); |
| 87 | fpsetmask(FP_X_OFL); | 89 | x = huge * huge; |
| 88 | x = huge * huge; | 90 | } else if (strcmp(argv[1], "fltund") == 0) { |
| 89 | assert(signal_caught == 1); | 91 | /* unmask and then trip underflow */ |
| 90 | signal_caught = 0; | 92 | fpsetmask(FP_X_UFL); |
| 91 | 93 | x = tiny * tiny; | |
| 92 | /* unmask and then trip underflow */ | 94 | } else { |
| 93 | fpsetmask(FP_X_UFL); | 95 | errx(1, "unrecognized condition %s", argv[1]); |
| 94 | x = tiny * tiny; | 96 | } |
| 95 | assert (signal_caught == 1); | ||
| 96 | signal_caught = 0; | ||
| 97 | 97 | ||
| 98 | exit(0); | 98 | errx(1, "signal wasn't caught"); |
| 99 | } | 99 | } |
| 100 | |||
