From fc26f71b59603e4fefd07e144c9edecb5d4b3193 Mon Sep 17 00:00:00 2001 From: Marco S Hyman Date: Sat, 12 Oct 2002 03:39:22 +0000 Subject: oops, add the test --- regress/lib/libc_r/sigdeliver/sigdeliver.c | 66 ++++++++++++++++++++++++++ regress/lib/libpthread/sigdeliver/sigdeliver.c | 66 ++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 regress/lib/libc_r/sigdeliver/sigdeliver.c create mode 100644 regress/lib/libpthread/sigdeliver/sigdeliver.c diff --git a/regress/lib/libc_r/sigdeliver/sigdeliver.c b/regress/lib/libc_r/sigdeliver/sigdeliver.c new file mode 100644 index 00000000000..b5cd76f875e --- /dev/null +++ b/regress/lib/libc_r/sigdeliver/sigdeliver.c @@ -0,0 +1,66 @@ +/* $OpenBSD: sigdeliver.c,v 1.1 2002/10/12 03:39:21 marc Exp $ */ +/* PUBLIC DOMAIN Oct 2002 */ + +/* + * test signal delivery of pending signals + */ + +#include +#include +#include + +#include "test.h" + +static pthread_mutex_t sync_mutex; + +volatile sig_atomic_t got_signal; + +/* + * sigusr1 signal handler. + */ +static void +sighandler(int signo) +{ + got_signal += 1; +} + +/* + * Install a signal handler for sigusr1 and then wait for it to + * occur. + */ +static void * +do_nothing (void *arg) +{ + SET_NAME("nothing"); + + ASSERT(signal(SIGUSR1, sighandler) != SIG_ERR); + CHECKr(pthread_mutex_lock(&sync_mutex)); + ASSERT(got_signal != 0); + CHECKr(pthread_mutex_unlock(&sync_mutex)); + return 0; +} + +int +main (int argc, char *argv[]) +{ + pthread_t pthread; + + /* Initialize and lock a mutex. */ + CHECKr(pthread_mutex_init(&sync_mutex, NULL)); + CHECKr(pthread_mutex_lock(&sync_mutex)); + + /* start a thread that will wait on the mutex we now own */ + CHECKr(pthread_create(&pthread, NULL, do_nothing, NULL)); + + /* + * Give the thread time to run and install its signal handler. + * The thread should be blocked waiting for the mutex we own. + * Give it a signal and then release the mutex and see if the + * signal is ever processed. + */ + sleep(2); + CHECKr(pthread_kill(pthread, SIGUSR1)); + CHECKr(pthread_mutex_unlock(&sync_mutex)); + CHECKr(pthread_join(pthread, NULL)); + SUCCEED; +} diff --git a/regress/lib/libpthread/sigdeliver/sigdeliver.c b/regress/lib/libpthread/sigdeliver/sigdeliver.c new file mode 100644 index 00000000000..b5cd76f875e --- /dev/null +++ b/regress/lib/libpthread/sigdeliver/sigdeliver.c @@ -0,0 +1,66 @@ +/* $OpenBSD: sigdeliver.c,v 1.1 2002/10/12 03:39:21 marc Exp $ */ +/* PUBLIC DOMAIN Oct 2002 */ + +/* + * test signal delivery of pending signals + */ + +#include +#include +#include + +#include "test.h" + +static pthread_mutex_t sync_mutex; + +volatile sig_atomic_t got_signal; + +/* + * sigusr1 signal handler. + */ +static void +sighandler(int signo) +{ + got_signal += 1; +} + +/* + * Install a signal handler for sigusr1 and then wait for it to + * occur. + */ +static void * +do_nothing (void *arg) +{ + SET_NAME("nothing"); + + ASSERT(signal(SIGUSR1, sighandler) != SIG_ERR); + CHECKr(pthread_mutex_lock(&sync_mutex)); + ASSERT(got_signal != 0); + CHECKr(pthread_mutex_unlock(&sync_mutex)); + return 0; +} + +int +main (int argc, char *argv[]) +{ + pthread_t pthread; + + /* Initialize and lock a mutex. */ + CHECKr(pthread_mutex_init(&sync_mutex, NULL)); + CHECKr(pthread_mutex_lock(&sync_mutex)); + + /* start a thread that will wait on the mutex we now own */ + CHECKr(pthread_create(&pthread, NULL, do_nothing, NULL)); + + /* + * Give the thread time to run and install its signal handler. + * The thread should be blocked waiting for the mutex we own. + * Give it a signal and then release the mutex and see if the + * signal is ever processed. + */ + sleep(2); + CHECKr(pthread_kill(pthread, SIGUSR1)); + CHECKr(pthread_mutex_unlock(&sync_mutex)); + CHECKr(pthread_join(pthread, NULL)); + SUCCEED; +} -- cgit v1.2.3