summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-07-13 07:08:01 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-07-13 07:08:01 +0000
commitdda238e978f612fe43c91c7783ac174c890bfc59 (patch)
tree8ac5291d7de18c1ca511cd0016c0078aa688907c
parente7d7d8fedf98634d46ea6d1fe5b54e0d1f80a530 (diff)
Test for fp save/restore in sig handlers.
-rw-r--r--regress/lib/libm/Makefile4
-rw-r--r--regress/lib/libm/fpsig/Makefile5
-rw-r--r--regress/lib/libm/fpsig/fpsig.c54
3 files changed, 61 insertions, 2 deletions
diff --git a/regress/lib/libm/Makefile b/regress/lib/libm/Makefile
index dbe415ba541..42d2c6afad5 100644
--- a/regress/lib/libm/Makefile
+++ b/regress/lib/libm/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.4 2003/11/01 00:50:44 mickey Exp $
+# $OpenBSD: Makefile,v 1.5 2005/07/13 07:08:00 otto Exp $
-SUBDIR+= rint floor toint trivial1
+SUBDIR+= rint floor toint trivial1 fpsig
install:
diff --git a/regress/lib/libm/fpsig/Makefile b/regress/lib/libm/fpsig/Makefile
new file mode 100644
index 00000000000..1e3962033dd
--- /dev/null
+++ b/regress/lib/libm/fpsig/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2005/07/13 07:08:00 otto Exp $
+
+PROG=fpsig
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libm/fpsig/fpsig.c b/regress/lib/libm/fpsig/fpsig.c
new file mode 100644
index 00000000000..4b9fb6a0cf9
--- /dev/null
+++ b/regress/lib/libm/fpsig/fpsig.c
@@ -0,0 +1,54 @@
+/* $OpenBSD: fpsig.c,v 1.1 2005/07/13 07:08:00 otto Exp $ */
+
+/*
+ * Public domain. 2005, Otto Moerbeek
+ *
+ * Try to check if fp registers are properly saved and restored while
+ * calling a signal hander. This is not supposed to catch all that
+ * can go wrong, but trashed fp regsiters will typically get caught.
+ */
+
+#include <err.h>
+#include <signal.h>
+#include <unistd.h>
+
+#define LIMIT 10.0
+
+volatile sig_atomic_t count;
+
+double g1;
+double g2;
+
+void
+handler(int signo)
+{
+ double a, b, c = 0.0;
+
+ if (signo)
+ alarm(1);
+ for (a = 0.0; a < LIMIT; a++)
+ for (b = 0.0; b < LIMIT; b++)
+ c += a * a + b * b;
+
+ if (signo) {
+ g1 = c;
+ count++;
+ } else
+ g2 = c;
+}
+
+int
+main()
+{
+ signal(SIGALRM, handler);
+ /* initialize global vars */
+ handler(0);
+ handler(1);
+
+ while (count < 10) {
+ handler(0);
+ if (g1 != g2)
+ errx(1, "%f %f", g1, g2);
+ }
+ return (0);
+}