summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-04-30 23:22:59 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-04-30 23:22:59 +0000
commit485c6543a8b04887611c18c42b2597ab490bc6f1 (patch)
treea61444446bab5bb14c8d0965b3fa1a032874bac3
parent9a914f88f9747f57ce1abd2e5d750713b433b65b (diff)
Test some floating point exception problems when SIG_IGN is in effect.
-rw-r--r--regress/sys/kern/signal/sigfpe/Makefile16
-rw-r--r--regress/sys/kern/signal/sigfpe/sigfpe.c84
2 files changed, 100 insertions, 0 deletions
diff --git a/regress/sys/kern/signal/sigfpe/Makefile b/regress/sys/kern/signal/sigfpe/Makefile
new file mode 100644
index 00000000000..346dd041ffb
--- /dev/null
+++ b/regress/sys/kern/signal/sigfpe/Makefile
@@ -0,0 +1,16 @@
+# $OpenBSD: Makefile,v 1.1 2002/04/30 23:22:58 millert Exp $
+
+PROG= sigfpe
+
+# XXX - don't want the compiler to optimize away our tests
+CFLAGS= -O0 ${PIPE} ${DEBUG}
+
+REGRESSTARGETS= divzero oflow
+
+divzero:
+ ./${PROG} -z
+
+oflow:
+ ./${PROG} -o
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/signal/sigfpe/sigfpe.c b/regress/sys/kern/signal/sigfpe/sigfpe.c
new file mode 100644
index 00000000000..5c6e6d9794e
--- /dev/null
+++ b/regress/sys/kern/signal/sigfpe/sigfpe.c
@@ -0,0 +1,84 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+void check_oflow(void);
+void check_div0(void);
+void timedout(int);
+__dead void usage(void);
+
+/*
+ * Check signal(SIGFPE, SIG_IGN) for overflow and divide by zero.
+ */
+
+int
+main(int argc, char **argv)
+{
+ int ch, oflag, zflag;
+
+ oflag = zflag = 0;
+ while ((ch = getopt(argc, argv, "oz")) != -1) {
+ switch (ch) {
+ case 'o':
+ oflag = 1;
+ break;
+ case 'z':
+ zflag = 1;
+ break;
+ }
+ }
+
+ if (oflag && zflag)
+ usage();
+
+ signal(SIGFPE, SIG_IGN);
+ signal(SIGALRM, timedout);
+
+ if (oflag)
+ check_oflow();
+ else
+ check_div0();
+
+ exit(0);
+}
+
+void
+check_oflow(void)
+{
+ double d, od;
+
+ od = 0;
+ d = 256;
+ do {
+ od = d;
+ alarm(10);
+ d *= d;
+ alarm(0);
+ } while (d != od);
+}
+
+void
+check_div0(void)
+{
+ int i;
+
+ alarm(10);
+ i = 1 / 0;
+ alarm(0);
+}
+
+void
+timedout(int sig)
+{
+ _exit(1);
+}
+
+__dead void
+usage(void)
+{
+ extern char *__progname;
+
+ (void)fprintf(stderr, "usage: %s -o | -z\n", __progname);
+ exit(1);
+}