summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authorbluhm <>2020-01-16 13:04:02 +0000
committerbluhm <>2020-01-16 13:04:02 +0000
commit8fad58f293c47140f9e2a70b547e55d3040596cc (patch)
tree6707148acd31b3757c80d6d1b69a29c5e9fef07a /src/regress/lib
parent5d5b1ddc4dc2f18052a9f37d0985d2cbbf2110b9 (diff)
downloadopenbsd-8fad58f293c47140f9e2a70b547e55d3040596cc.tar.gz
openbsd-8fad58f293c47140f9e2a70b547e55d3040596cc.tar.bz2
openbsd-8fad58f293c47140f9e2a70b547e55d3040596cc.zip
Check fpu functions without setjmp/longjmp before testing the latter.
Use exit code 2 for setup failure and 1 for test fail. Unfortunately this regress is still failing.
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libc/setjmp-fpu/Makefile12
-rw-r--r--src/regress/lib/libc/setjmp-fpu/fpu.c51
-rw-r--r--src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c21
3 files changed, 71 insertions, 13 deletions
diff --git a/src/regress/lib/libc/setjmp-fpu/Makefile b/src/regress/lib/libc/setjmp-fpu/Makefile
index 7b9fae5f5f..c4e7196c1d 100644
--- a/src/regress/lib/libc/setjmp-fpu/Makefile
+++ b/src/regress/lib/libc/setjmp-fpu/Makefile
@@ -1,10 +1,16 @@
1# $OpenBSD: Makefile,v 1.3 2020/01/13 14:58:38 bluhm Exp $ 1# $OpenBSD: Makefile,v 1.4 2020/01/16 13:03:42 bluhm Exp $
2 2
3PROGS= _setjmp setjmp sigsetjmp 3PROGS= fpu _setjmp setjmp sigsetjmp
4 4
5LDADD= -lm 5LDADD= -lm
6 6
7.for p in ${PROGS} 7REGRESS_TARGETS = run-fpu
8run-fpu: fpu
9 @echo '======== $@ ========'
10 # check fpu functions without setjmp/longjmp before testing the latter
11 ./fpu
12
13.for p in ${PROGS:M*jmp}
8REGRESS_TARGETS += run-$p 14REGRESS_TARGETS += run-$p
9run-$p: $p 15run-$p: $p
10 @echo '======== $@ ========' 16 @echo '======== $@ ========'
diff --git a/src/regress/lib/libc/setjmp-fpu/fpu.c b/src/regress/lib/libc/setjmp-fpu/fpu.c
new file mode 100644
index 0000000000..fbfc85a8ef
--- /dev/null
+++ b/src/regress/lib/libc/setjmp-fpu/fpu.c
@@ -0,0 +1,51 @@
1/* $OpenBSD: fpu.c,v 1.1 2020/01/16 13:04:02 bluhm Exp $ */
2
3#include <err.h>
4#include <fenv.h>
5#include <stdlib.h>
6
7int
8main(int argc, char *argv[])
9{
10 fexcept_t flag;
11 int rv;
12
13 /* Set up the FPU control word register. */
14 rv = fesetround(FE_UPWARD);
15 if (rv != 0)
16 errx(2, "fesetround FE_UPWARD returned %d", rv);
17 fedisableexcept(FE_ALL_EXCEPT);
18 feenableexcept(FE_DIVBYZERO);
19
20 /* Set the FPU exception flags. */
21 flag = FE_OVERFLOW;
22 rv = fesetexceptflag(&flag, FE_ALL_EXCEPT);
23 if (rv != 0)
24 errx(2, "fesetexceptflag returned %d", rv);
25
26 /* Schedule another process, to check if kernel preserves state. */
27 rv = system("true");
28 if (rv == -1)
29 err(2, "system");
30 if (rv != 0)
31 errx(2, "true: %d", rv);
32
33 /* Verify that the FPU control word is preserved. */
34 rv = fegetround();
35 if (rv != FE_UPWARD)
36 errx(1, "fegetround returned %d, not FE_UPWARD", rv);
37 rv = fegetexcept();
38 if (rv != FE_DIVBYZERO)
39 errx(1, "fegetexcept returned %d, not FE_DIVBYZERO",
40 rv);
41
42 /* Verify that the FPU exception flags weren't clobbered. */
43 flag = 0;
44 rv = fegetexceptflag(&flag, FE_ALL_EXCEPT);
45 if (rv != 0)
46 errx(2, "fegetexceptflag returned %d", rv);
47 if (flag != FE_OVERFLOW)
48 errx(1, "except flag is %d, no FE_OVERFLOW", rv);
49
50 return (0);
51}
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
index 11d616ae71..3cdf906e97 100644
--- a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
+++ b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
@@ -1,3 +1,5 @@
1/* $OpenBSD: setjmp-fpu.c,v 1.5 2020/01/16 13:04:02 bluhm Exp $ */
2
1#include <err.h> 3#include <err.h>
2#include <fenv.h> 4#include <fenv.h>
3#include <setjmp.h> 5#include <setjmp.h>
@@ -6,12 +8,13 @@ int
6TEST_SETJMP(void) 8TEST_SETJMP(void)
7{ 9{
8 JMP_BUF env; 10 JMP_BUF env;
11 fexcept_t flag;
9 int rv; 12 int rv;
10 13
11 /* Set up the FPU control word register. */ 14 /* Set up the FPU control word register. */
12 rv = fesetround(FE_UPWARD); 15 rv = fesetround(FE_UPWARD);
13 if (rv != 0) 16 if (rv != 0)
14 errx(1, "fesetround FE_UPWARD returned %d", rv); 17 errx(2, "fesetround FE_UPWARD returned %d", rv);
15 fedisableexcept(FE_ALL_EXCEPT); 18 fedisableexcept(FE_ALL_EXCEPT);
16 feenableexcept(FE_DIVBYZERO); 19 feenableexcept(FE_DIVBYZERO);
17 20
@@ -19,25 +22,22 @@ TEST_SETJMP(void)
19 22
20 switch(rv) { 23 switch(rv) {
21 case 0: { 24 case 0: {
22 fexcept_t flag = FE_OVERFLOW;
23
24 /* Mess with the FPU control word. */ 25 /* Mess with the FPU control word. */
25 rv = fesetround(FE_DOWNWARD); 26 rv = fesetround(FE_DOWNWARD);
26 if (rv != 0) 27 if (rv != 0)
27 errx(1, "fesetround FE_DOWNWARD returned %d", rv); 28 errx(2, "fesetround FE_DOWNWARD returned %d", rv);
28 fedisableexcept(FE_DIVBYZERO); 29 fedisableexcept(FE_DIVBYZERO);
29 30
30 /* Set the FPU exception flags. */ 31 /* Set the FPU exception flags. */
32 flag = FE_OVERFLOW;
31 rv = fesetexceptflag(&flag, FE_ALL_EXCEPT); 33 rv = fesetexceptflag(&flag, FE_ALL_EXCEPT);
32 if (rv != 0) 34 if (rv != 0)
33 errx(1, "fesetexceptflag returned %d", rv); 35 errx(2, "fesetexceptflag returned %d", rv);
34 36
35 LONGJMP(env, 1); 37 LONGJMP(env, 1);
36 errx(1, "longjmp returned"); 38 errx(2, "longjmp returned");
37 } 39 }
38 case 1: { 40 case 1: {
39 fexcept_t flag = 0;
40
41 /* Verify that the FPU control word is preserved. */ 41 /* Verify that the FPU control word is preserved. */
42 rv = fegetround(); 42 rv = fegetround();
43 if (rv != FE_UPWARD) 43 if (rv != FE_UPWARD)
@@ -48,15 +48,16 @@ TEST_SETJMP(void)
48 rv); 48 rv);
49 49
50 /* Verify that the FPU exception flags weren't clobbered. */ 50 /* Verify that the FPU exception flags weren't clobbered. */
51 flag = 0;
51 rv = fegetexceptflag(&flag, FE_ALL_EXCEPT); 52 rv = fegetexceptflag(&flag, FE_ALL_EXCEPT);
52 if (rv != 0) 53 if (rv != 0)
53 errx(1, "fegetexceptflag returned %d", rv); 54 errx(2, "fegetexceptflag returned %d", rv);
54 if (flag != FE_OVERFLOW) 55 if (flag != FE_OVERFLOW)
55 errx(1, "except flag is %d, no FE_OVERFLOW", rv); 56 errx(1, "except flag is %d, no FE_OVERFLOW", rv);
56 57
57 return (0); 58 return (0);
58 } 59 }
59 default: 60 default:
60 errx(1, "setjmp returned %d", rv); 61 errx(2, "setjmp returned %d", rv);
61 } 62 }
62} 63}