summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2002-10-12 03:39:22 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2002-10-12 03:39:22 +0000
commitfc26f71b59603e4fefd07e144c9edecb5d4b3193 (patch)
tree555cdaf8b18da75a61623971439917f3cb81ba50
parent333fae7f03c3e71d79ad015ef2a464669ed8d235 (diff)
oops, add the test
-rw-r--r--regress/lib/libc_r/sigdeliver/sigdeliver.c66
-rw-r--r--regress/lib/libpthread/sigdeliver/sigdeliver.c66
2 files changed, 132 insertions, 0 deletions
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 <marc@snafu.org> */
+
+/*
+ * test signal delivery of pending signals
+ */
+
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#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 <marc@snafu.org> */
+
+/*
+ * test signal delivery of pending signals
+ */
+
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#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;
+}