diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 2002-10-21 18:46:36 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 2002-10-21 18:46:36 +0000 |
commit | ae41d0613ce5e8e7a282f73df76374c910448ac1 (patch) | |
tree | 9c30bd8b0c22faef5095a7f53d7c27ed978ac54b /regress/lib | |
parent | dd46b9cbde1717e0c8e132dea11563c7e2cc2c10 (diff) |
Add test for non-deferred signal handling in threads. pthreads code
that makes this test work is being tested.
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libc_r/signodefer/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libc_r/signodefer/signodefer.c | 67 | ||||
-rw-r--r-- | regress/lib/libpthread/signodefer/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libpthread/signodefer/signodefer.c | 67 |
4 files changed, 144 insertions, 0 deletions
diff --git a/regress/lib/libc_r/signodefer/Makefile b/regress/lib/libc_r/signodefer/Makefile new file mode 100644 index 00000000000..52c04c28cd2 --- /dev/null +++ b/regress/lib/libc_r/signodefer/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/10/21 18:46:35 marc Exp $ + +PROG= signodefer + +.include <bsd.regress.mk> diff --git a/regress/lib/libc_r/signodefer/signodefer.c b/regress/lib/libc_r/signodefer/signodefer.c new file mode 100644 index 00000000000..dbc0561cac8 --- /dev/null +++ b/regress/lib/libc_r/signodefer/signodefer.c @@ -0,0 +1,67 @@ +/* $OpenBSD: signodefer.c,v 1.1 2002/10/21 18:46:35 marc Exp $ */ +/* PUBLIC DOMAIN Oct 2002 <marc@snafu.org> */ + +/* + * test signal delivery of active signals (SA_NODEFER) + */ + +#include <signal.h> +#include <stdio.h> +#include <unistd.h> + +#include "test.h" + +volatile sig_atomic_t sigactive; +volatile sig_atomic_t sigcount; +volatile sig_atomic_t was_active; + +void +act_handler(int signal, siginfo_t *siginfo, void *context) +{ + char *str; + + /* how many times has the handler been called */ + was_active += sigactive++; + sigcount += 1; + + /* verify siginfo since we asked for it. */ + ASSERT(siginfo != NULL); + + asprintf(&str, + "%sact_handler/%d, signal %d, siginfo 0x%p, context 0x%p\n", + was_active ? "[recurse] " : "", + sigcount, signal, siginfo, context); + CHECKe(write(STDOUT_FILENO, str, strlen(str))); + /* Odd times entered send ourself the same signal */ + if (sigcount & 1) + CHECKe(kill(getpid(), SIGUSR1)); + + sigactive = 0; +} + +int +main(int argc, char **argv) +{ + struct sigaction act; + + act.sa_sigaction = act_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + ASSERT(sigaction(SIGUSR1, &act, NULL) == 0); + + /* see if the signal handler recurses */ + CHECKe(kill(getpid(), SIGUSR1)); + sleep(1); + ASSERT(was_active == 0); + + /* allow recursive handlers, see that it is handled right */ + act.sa_flags |= SA_NODEFER; + ASSERT(sigaction(SIGUSR1, &act, NULL) == 0); + + /* see if the signal handler recurses */ + CHECKe(kill(getpid(), SIGUSR1)); + sleep(1); + ASSERT(was_active == 1); + + SUCCEED; +} diff --git a/regress/lib/libpthread/signodefer/Makefile b/regress/lib/libpthread/signodefer/Makefile new file mode 100644 index 00000000000..52c04c28cd2 --- /dev/null +++ b/regress/lib/libpthread/signodefer/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/10/21 18:46:35 marc Exp $ + +PROG= signodefer + +.include <bsd.regress.mk> diff --git a/regress/lib/libpthread/signodefer/signodefer.c b/regress/lib/libpthread/signodefer/signodefer.c new file mode 100644 index 00000000000..dbc0561cac8 --- /dev/null +++ b/regress/lib/libpthread/signodefer/signodefer.c @@ -0,0 +1,67 @@ +/* $OpenBSD: signodefer.c,v 1.1 2002/10/21 18:46:35 marc Exp $ */ +/* PUBLIC DOMAIN Oct 2002 <marc@snafu.org> */ + +/* + * test signal delivery of active signals (SA_NODEFER) + */ + +#include <signal.h> +#include <stdio.h> +#include <unistd.h> + +#include "test.h" + +volatile sig_atomic_t sigactive; +volatile sig_atomic_t sigcount; +volatile sig_atomic_t was_active; + +void +act_handler(int signal, siginfo_t *siginfo, void *context) +{ + char *str; + + /* how many times has the handler been called */ + was_active += sigactive++; + sigcount += 1; + + /* verify siginfo since we asked for it. */ + ASSERT(siginfo != NULL); + + asprintf(&str, + "%sact_handler/%d, signal %d, siginfo 0x%p, context 0x%p\n", + was_active ? "[recurse] " : "", + sigcount, signal, siginfo, context); + CHECKe(write(STDOUT_FILENO, str, strlen(str))); + /* Odd times entered send ourself the same signal */ + if (sigcount & 1) + CHECKe(kill(getpid(), SIGUSR1)); + + sigactive = 0; +} + +int +main(int argc, char **argv) +{ + struct sigaction act; + + act.sa_sigaction = act_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + ASSERT(sigaction(SIGUSR1, &act, NULL) == 0); + + /* see if the signal handler recurses */ + CHECKe(kill(getpid(), SIGUSR1)); + sleep(1); + ASSERT(was_active == 0); + + /* allow recursive handlers, see that it is handled right */ + act.sa_flags |= SA_NODEFER; + ASSERT(sigaction(SIGUSR1, &act, NULL) == 0); + + /* see if the signal handler recurses */ + CHECKe(kill(getpid(), SIGUSR1)); + sleep(1); + ASSERT(was_active == 1); + + SUCCEED; +} |