diff options
| author | cvs2svn <admin@example.com> | 1998-10-19 21:47:12 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 1998-10-19 21:47:12 +0000 |
| commit | 5170039cf1df2194faa85741f0733977525cd5c0 (patch) | |
| tree | c667406046ddb1efca5ed4316b02e43494241660 /src/regress/lib/libc/setjmp | |
| parent | 536c76cbb863bab152f19842ab88772c01e922c7 (diff) | |
| download | openbsd-OPENBSD_2_4_BASE.tar.gz openbsd-OPENBSD_2_4_BASE.tar.bz2 openbsd-OPENBSD_2_4_BASE.zip | |
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_4_BASE'.OPENBSD_2_4_BASE
Diffstat (limited to 'src/regress/lib/libc/setjmp')
| -rw-r--r-- | src/regress/lib/libc/setjmp/Makefile | 16 | ||||
| -rw-r--r-- | src/regress/lib/libc/setjmp/jmptest.c | 135 |
2 files changed, 151 insertions, 0 deletions
diff --git a/src/regress/lib/libc/setjmp/Makefile b/src/regress/lib/libc/setjmp/Makefile new file mode 100644 index 0000000000..25bf99d4cb --- /dev/null +++ b/src/regress/lib/libc/setjmp/Makefile | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:13 cgd Exp $ | ||
| 2 | |||
| 3 | PROG= setjmptest | ||
| 4 | SRCS= jmptest.c | ||
| 5 | NOMAN= noman, no way, man | ||
| 6 | |||
| 7 | CFLAGS+= -DTEST_SETJMP | ||
| 8 | |||
| 9 | .PATH: ${.CURDIR}/../setjmp | ||
| 10 | |||
| 11 | install: | ||
| 12 | |||
| 13 | regress: ${PROG} | ||
| 14 | ./${PROG} | ||
| 15 | |||
| 16 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c new file mode 100644 index 0000000000..16a482640a --- /dev/null +++ b/src/regress/lib/libc/setjmp/jmptest.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1994 Christopher G. Demetriou | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * 3. All advertising materials mentioning features or use of this software | ||
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed by Christopher G. Demetriou | ||
| 18 | * for the NetBSD Project. | ||
| 19 | * 4. The name of the author may not be used to endorse or promote products | ||
| 20 | * derived from this software without specific prior written permission | ||
| 21 | * | ||
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | */ | ||
| 33 | |||
| 34 | #include <sys/types.h> | ||
| 35 | #include <err.h> | ||
| 36 | #include <setjmp.h> | ||
| 37 | #include <signal.h> | ||
| 38 | #include <stdio.h> | ||
| 39 | #include <stdlib.h> | ||
| 40 | #include <unistd.h> | ||
| 41 | |||
| 42 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 | ||
| 43 | #error one of TEST_SETJMP, TEST_U_SETJMP, or TEST_SIGSETJMP must be defined | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #ifdef TEST_SETJMP | ||
| 47 | #define BUF jmp_buf | ||
| 48 | #define SET(b, m) setjmp(b) | ||
| 49 | #define JMP(b, v) longjmp(b, v) | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #ifdef TEST_U_SETJMP | ||
| 53 | #define BUF jmp_buf | ||
| 54 | #define SET(b, m) _setjmp(b) | ||
| 55 | #define JMP(b, v) _longjmp(b, v) | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #ifdef TEST_SIGSETJMP | ||
| 59 | #define BUF sigjmp_buf | ||
| 60 | #define SET(b, m) sigsetjmp(b, m) | ||
| 61 | #define JMP(b, v) siglongjmp(b, v) | ||
| 62 | #endif | ||
| 63 | |||
| 64 | int expectsignal; | ||
| 65 | |||
| 66 | void | ||
| 67 | aborthandler(signo) | ||
| 68 | int signo; | ||
| 69 | { | ||
| 70 | |||
| 71 | if (expectsignal) | ||
| 72 | exit(0); | ||
| 73 | else | ||
| 74 | errx(1, "kill(SIGABRT) succeeded"); | ||
| 75 | } | ||
| 76 | |||
| 77 | int | ||
| 78 | main(argc, argv) | ||
| 79 | int argc; | ||
| 80 | char *argv[]; | ||
| 81 | { | ||
| 82 | struct sigaction sa; | ||
| 83 | BUF jb; | ||
| 84 | sigset_t ss; | ||
| 85 | int i, x; | ||
| 86 | |||
| 87 | i = getpid(); | ||
| 88 | |||
| 89 | #ifdef TEST_SETJMP | ||
| 90 | expectsignal = 0; | ||
| 91 | #endif | ||
| 92 | #ifdef TEST_U_SETJMP | ||
| 93 | expectsignal = 1; | ||
| 94 | #endif | ||
| 95 | #ifdef TEST_SIGSETJMP | ||
| 96 | if (argc != 2 || | ||
| 97 | (strcmp(argv[1], "save") && strcmp(argv[1], "nosave"))) { | ||
| 98 | fprintf(stderr, "usage: %s [save|nosave]\n", argv[0]); | ||
| 99 | exit(1); | ||
| 100 | } | ||
| 101 | expectsignal = (strcmp(argv[1], "save") != 0); | ||
| 102 | #endif | ||
| 103 | |||
| 104 | sa.sa_handler = aborthandler; | ||
| 105 | sigemptyset(&sa.sa_mask); | ||
| 106 | sa.sa_flags = 0; | ||
| 107 | if (sigaction(SIGABRT, &sa, NULL) == -1) | ||
| 108 | err(1, "sigaction failed"); | ||
| 109 | |||
| 110 | if (sigemptyset(&ss) == -1) | ||
| 111 | err(1, "sigemptyset failed"); | ||
| 112 | if (sigaddset(&ss, SIGABRT) == -1) | ||
| 113 | err(1, "sigaddset failed"); | ||
| 114 | if (sigprocmask(SIG_BLOCK, &ss, NULL) == -1) | ||
| 115 | err(1, "sigprocmask (1) failed"); | ||
| 116 | |||
| 117 | x = SET(jb, !expectsignal); | ||
| 118 | if (x != 0) { | ||
| 119 | if (x != i) | ||
| 120 | errx(1, "setjmp returned wrong value"); | ||
| 121 | |||
| 122 | kill(i, SIGABRT); | ||
| 123 | if (expectsignal) | ||
| 124 | errx(1, "kill(SIGABRT) failed"); | ||
| 125 | else | ||
| 126 | exit(0); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1) | ||
| 130 | err(1, "sigprocmask (2) failed"); | ||
| 131 | |||
| 132 | JMP(jb, i); | ||
| 133 | |||
| 134 | errx(1, "jmp failed"); | ||
| 135 | } | ||
