diff options
author | art <> | 2002-01-04 13:48:52 +0000 |
---|---|---|
committer | art <> | 2002-01-04 13:48:52 +0000 |
commit | 3184a232c112a73d0c6d9f16015df4924a1a666f (patch) | |
tree | c8b75932ad1d2f656c0fbc6848aa03284279b655 /src | |
parent | 327f214c26abf9d44fd57d9bf6c2cc8f2bb8e4a0 (diff) | |
download | openbsd-3184a232c112a73d0c6d9f16015df4924a1a666f.tar.gz openbsd-3184a232c112a73d0c6d9f16015df4924a1a666f.tar.bz2 openbsd-3184a232c112a73d0c6d9f16015df4924a1a666f.zip |
Test _longjmp too. (Don't hate me for the '_' option).
sigsetjmp should be tested too, but that wasn't as easy to fit in here
(and it wasn't broken on alpha anyway).
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/longjmp/Makefile | 7 | ||||
-rw-r--r-- | src/regress/lib/libc/longjmp/longjmp.c | 34 |
2 files changed, 35 insertions, 6 deletions
diff --git a/src/regress/lib/libc/longjmp/Makefile b/src/regress/lib/libc/longjmp/Makefile index 1444cd4374..d17a94182e 100644 --- a/src/regress/lib/libc/longjmp/Makefile +++ b/src/regress/lib/libc/longjmp/Makefile | |||
@@ -1,3 +1,10 @@ | |||
1 | PROG= longjmp | 1 | PROG= longjmp |
2 | 2 | ||
3 | do-longjmp: ${PROG} | ||
4 | ./longjmp | ||
5 | do-_longjmp: ${PROG} | ||
6 | ./longjmp -_ | ||
7 | |||
8 | REGRESSTARGETS=do-longjmp do-_longjmp | ||
9 | |||
3 | .include <bsd.regress.mk> | 10 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/longjmp/longjmp.c b/src/regress/lib/libc/longjmp/longjmp.c index 4d8edb4716..9940dc5b9a 100644 --- a/src/regress/lib/libc/longjmp/longjmp.c +++ b/src/regress/lib/libc/longjmp/longjmp.c | |||
@@ -1,8 +1,11 @@ | |||
1 | /* $OpenBSD: longjmp.c,v 1.2 2002/01/04 13:33:17 art Exp $ */ | 1 | /* $OpenBSD: longjmp.c,v 1.3 2002/01/04 13:48:52 art Exp $ */ |
2 | /* | 2 | /* |
3 | * Artur Grabowski <art@openbsd.org> Public Domain. | 3 | * Artur Grabowski <art@openbsd.org> Public Domain. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <unistd.h> | ||
6 | #include <setjmp.h> | 9 | #include <setjmp.h> |
7 | #include <err.h> | 10 | #include <err.h> |
8 | #include <sys/types.h> | 11 | #include <sys/types.h> |
@@ -19,10 +22,29 @@ jmp_buf buf; | |||
19 | * The rlimit is here in case we start spinning. | 22 | * The rlimit is here in case we start spinning. |
20 | */ | 23 | */ |
21 | int | 24 | int |
22 | main() | 25 | main(int argc, char **argv) |
23 | { | 26 | { |
24 | struct rlimit rl; | 27 | struct rlimit rl; |
25 | volatile int i, expect; | 28 | volatile int i, expect; |
29 | int (*sj)(jmp_buf); | ||
30 | void (*lj)(jmp_buf, int); | ||
31 | int ch; | ||
32 | extern char *__progname; | ||
33 | |||
34 | sj = setjmp; | ||
35 | lj = longjmp; | ||
36 | |||
37 | while ((ch = getopt(argc, argv, "_")) != -1) { | ||
38 | switch (ch) { | ||
39 | case '_': | ||
40 | sj = _setjmp; | ||
41 | lj = _longjmp; | ||
42 | break; | ||
43 | default: | ||
44 | fprintf(stderr, "Usage: %s [-_]\n", __progname); | ||
45 | exit(1); | ||
46 | } | ||
47 | } | ||
26 | 48 | ||
27 | rl.rlim_cur = 2; | 49 | rl.rlim_cur = 2; |
28 | rl.rlim_max = 2; | 50 | rl.rlim_max = 2; |
@@ -30,20 +52,20 @@ main() | |||
30 | err(1, "setrlimit"); | 52 | err(1, "setrlimit"); |
31 | 53 | ||
32 | expect = 0; | 54 | expect = 0; |
33 | i = setjmp(buf); | 55 | i = (*sj)(buf); |
34 | if (i == 0 && expect != 0) | 56 | if (i == 0 && expect != 0) |
35 | errx(1, "setjmp returns 0 on longjmp(.., 0)"); | 57 | errx(1, "setjmp returns 0 on longjmp(.., 0)"); |
36 | if (expect == 0) { | 58 | if (expect == 0) { |
37 | expect = -1; | 59 | expect = -1; |
38 | longjmp(buf, 0); | 60 | (*lj)(buf, 0); |
39 | } | 61 | } |
40 | 62 | ||
41 | expect = 0; | 63 | expect = 0; |
42 | i = setjmp(buf); | 64 | i = (*sj)(buf); |
43 | if (i != expect) | 65 | if (i != expect) |
44 | errx(1, "bad return from setjmp %d/%d", expect, i); | 66 | errx(1, "bad return from setjmp %d/%d", expect, i); |
45 | if (expect < 1000) | 67 | if (expect < 1000) |
46 | longjmp(buf, expect += 2); | 68 | (*lj)(buf, expect += 2); |
47 | 69 | ||
48 | return 0; | 70 | return 0; |
49 | } | 71 | } |