summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/setjmp-fpu
diff options
context:
space:
mode:
authormartynas <>2013-12-29 01:39:44 +0000
committermartynas <>2013-12-29 01:39:44 +0000
commitc057fa8b78920eb9c3f036141d89633cdb5a2626 (patch)
tree64e72dd0a9ea8ed1a7f3a56430c46d8b85760492 /src/regress/lib/libc/setjmp-fpu
parent059e8d1417ca56903c7f426e4a8a23db0b19a7e7 (diff)
downloadopenbsd-c057fa8b78920eb9c3f036141d89633cdb5a2626.tar.gz
openbsd-c057fa8b78920eb9c3f036141d89633cdb5a2626.tar.bz2
openbsd-c057fa8b78920eb9c3f036141d89633cdb5a2626.zip
Add a regression test to verify that the FPU control word state is
preserved by setjmp. Currently under REGRESS_FULL as this fails on certain archs.
Diffstat (limited to 'src/regress/lib/libc/setjmp-fpu')
-rw-r--r--src/regress/lib/libc/setjmp-fpu/Makefile8
-rw-r--r--src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c34
2 files changed, 42 insertions, 0 deletions
diff --git a/src/regress/lib/libc/setjmp-fpu/Makefile b/src/regress/lib/libc/setjmp-fpu/Makefile
new file mode 100644
index 0000000000..471de4821c
--- /dev/null
+++ b/src/regress/lib/libc/setjmp-fpu/Makefile
@@ -0,0 +1,8 @@
1# $OpenBSD: Makefile,v 1.1 2013/12/29 01:39:44 martynas Exp $
2
3PROG= setjmp-fpu
4SRCS= setjmp-fpu.c
5
6LDADD= -lm
7
8.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
new file mode 100644
index 0000000000..bbc562d6bd
--- /dev/null
+++ b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
@@ -0,0 +1,34 @@
1#include <fenv.h>
2#include <setjmp.h>
3
4int
5main(int argc, char *argv[])
6{
7 jmp_buf env;
8 int rv;
9
10 /* Set up the FPU control word register. */
11 fesetround(FE_UPWARD);
12 fedisableexcept(FE_ALL_EXCEPT);
13 feenableexcept(FE_DIVBYZERO);
14
15 rv = setjmp(env);
16
17 /* Mess with the FPU control word. */
18 if (rv == 0) {
19 fesetround(FE_DOWNWARD);
20 fedisableexcept(FE_DIVBYZERO);
21 longjmp(env, 1);
22 /* Verify that the FPU control word is preserved. */
23 } else if (rv == 1) {
24 if (fegetround() != FE_UPWARD
25 || fegetexcept() != FE_DIVBYZERO)
26 return (1);
27 return (0);
28 /* This is not supposed to happen. */
29 } else {
30 return (1);
31 }
32
33 return (1);
34}