diff options
author | bluhm <> | 2020-01-16 13:04:02 +0000 |
---|---|---|
committer | bluhm <> | 2020-01-16 13:04:02 +0000 |
commit | 8fad58f293c47140f9e2a70b547e55d3040596cc (patch) | |
tree | 6707148acd31b3757c80d6d1b69a29c5e9fef07a /src/regress/lib/libc/setjmp-fpu/fpu.c | |
parent | 5d5b1ddc4dc2f18052a9f37d0985d2cbbf2110b9 (diff) | |
download | openbsd-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/libc/setjmp-fpu/fpu.c')
-rw-r--r-- | src/regress/lib/libc/setjmp-fpu/fpu.c | 51 |
1 files changed, 51 insertions, 0 deletions
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 | |||
7 | int | ||
8 | main(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 | } | ||