diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc_r/TEST/test_sigsuspend.c (renamed from lib/libc_r/test/sigsuspend/sigsuspend.c) | 126 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_sigwait.c (renamed from lib/libc_r/test/sigwait/sigwait.c) | 147 | ||||
-rw-r--r-- | lib/libc_r/test/Makefile | 8 | ||||
-rw-r--r-- | lib/libc_r/test/sigsuspend/Makefile | 8 | ||||
-rw-r--r-- | lib/libc_r/test/sigwait/Makefile | 8 |
5 files changed, 102 insertions, 195 deletions
diff --git a/lib/libc_r/test/sigsuspend/sigsuspend.c b/lib/libc_r/TEST/test_sigsuspend.c index 894b0926333..da345f8d0bc 100644 --- a/lib/libc_r/test/sigsuspend/sigsuspend.c +++ b/lib/libc_r/TEST/test_sigsuspend.c @@ -39,9 +39,8 @@ #include <stdio.h> #include <string.h> -#if defined(__FreeBSD__) #include <pthread_np.h> -#endif +#include "test.h" static int sigcounts[NSIG + 1]; static int sigfifo[NSIG + 1]; @@ -58,7 +57,7 @@ sigsuspender (void *arg) /* Run with all signals blocked. */ sigfillset (&run_mask); - sigprocmask (SIG_SETMASK, &run_mask, NULL); + CHECKe(sigprocmask (SIG_SETMASK, &run_mask, NULL)); /* Allow these signals to wake us up during a sigsuspend. */ sigfillset (&suspender_mask); /* Default action */ @@ -74,19 +73,17 @@ sigsuspender (void *arg) status = sigsuspend (&suspender_mask); if ((status == 0) || (errno != EINTR)) { - printf ("Unable to suspend for signals, " - "errno %d, return value %d\n", - errno, status); - exit (1); + DIE(errno, "Unable to suspend for signals, " + "return value %d\n", + status); } for (i = 0; i < fifo_depth; i++) - printf ("Sigsuspend woke up by signal %d\n", - sigfifo[i]); + printf ("Sigsuspend woke up by signal %d (%s)\n", + sigfifo[i], strsignal(sigfifo[i])); fifo_depth = 0; } - pthread_exit (arg); - return (NULL); + return (arg); } @@ -107,43 +104,20 @@ sighandler (int signo) if (self == suspender_tid) { sigfifo[fifo_depth] = signo; fifo_depth++; - printf (" -> Suspender thread signal handler caught signal %d\n", - signo); + printf (" -> Suspender thread signal handler caught " + "signal %d (%s)\n", signo, strsignal(signo)); sigprocmask (SIG_SETMASK, NULL, &set); - if (set != suspender_mask) - printf (" >>> FAIL: sigsuspender signal handler running " - "with incorrect mask.\n"); + ASSERT(set == suspender_mask); } else - printf (" -> Main thread signal handler caught signal %d\n", - signo); -} - - -static void -send_thread_signal (pthread_t tid, int signo) -{ - if (pthread_kill (tid, signo) != 0) { - printf ("Unable to send thread signal, errno %d.\n", errno); - exit (1); - } -} - - -static void -send_process_signal (int signo) -{ - if (kill (getpid (), signo) != 0) { - printf ("Unable to send process signal, errno %d.\n", errno); - exit (1); - } + printf (" -> Main thread signal handler caught " + "signal %d (%s)\n", signo, strsignal(signo)); } int main (int argc, char *argv[]) { pthread_attr_t pattr; - void * exit_status; struct sigaction act; sigset_t oldset; sigset_t newset; @@ -156,28 +130,28 @@ int main (int argc, char *argv[]) sigaddset (&act.sa_mask, SIGIO); act.sa_handler = SIG_IGN; act.sa_flags = 0; - sigaction (SIGIO, &act, NULL); + CHECKe(sigaction (SIGIO, &act, NULL)); /* Install a signal handler for SIGURG. */ sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, SIGURG); act.sa_handler = sighandler; act.sa_flags = SA_RESTART; - sigaction (SIGURG, &act, NULL); + CHECKe(sigaction (SIGURG, &act, NULL)); /* Install a signal handler for SIGXCPU */ sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, SIGXCPU); - sigaction (SIGXCPU, &act, NULL); + CHECKe(sigaction (SIGXCPU, &act, NULL)); /* Get our current signal mask. */ - sigprocmask (SIG_SETMASK, NULL, &oldset); + CHECKe(sigprocmask (SIG_SETMASK, NULL, &oldset)); /* Mask out SIGUSR1 and SIGUSR2. */ newset = oldset; sigaddset (&newset, SIGUSR1); sigaddset (&newset, SIGUSR2); - sigprocmask (SIG_SETMASK, &newset, NULL); + CHECKe(sigprocmask (SIG_SETMASK, &newset, NULL)); /* Install a signal handler for SIGUSR1 and SIGUSR2 */ sigemptyset (&act.sa_mask); @@ -185,89 +159,79 @@ int main (int argc, char *argv[]) sigaddset (&act.sa_mask, SIGUSR2); act.sa_handler = sighandler; act.sa_flags = SA_RESTART; - sigaction (SIGUSR1, &act, NULL); - sigaction (SIGUSR2, &act, NULL); + CHECKe(sigaction (SIGUSR1, &act, NULL)); + CHECKe(sigaction (SIGUSR2, &act, NULL)); /* * Initialize the thread attribute. */ - if ((pthread_attr_init (&pattr) != 0) || - (pthread_attr_setdetachstate (&pattr, - PTHREAD_CREATE_JOINABLE) != 0)) { - printf ("Unable to initialize thread attributes.\n"); - exit (1); - } + CHECKr(pthread_attr_init (&pattr)); + CHECKr(pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE)); /* * Create the sigsuspender thread. */ - if (pthread_create (&suspender_tid, &pattr, sigsuspender, NULL) != 0) { - printf ("Unable to create thread, errno %d.\n", errno); - exit (1); - } -#if defined(__FreeBSD__) + CHECKr(pthread_create (&suspender_tid, &pattr, sigsuspender, NULL)); pthread_set_name_np (suspender_tid, "sigsuspender"); -#endif /* * Verify that an ignored signal doesn't cause a wakeup. * We don't have a handler installed for SIGIO. */ - send_thread_signal (suspender_tid, SIGIO); + CHECKr(pthread_kill (suspender_tid, SIGIO)); sleep (1); - send_process_signal (SIGIO); + CHECKe(kill (getpid (), SIGIO)); sleep (1); - if (sigcounts[SIGIO] != 0) - printf ("FAIL: sigsuspend wakes up for ignored signal " - "SIGIO.\n"); + /* sigsuspend should not wake up for ignored signal SIGIO */ + ASSERT(sigcounts[SIGIO] == 0); /* * Verify that a signal with a default action of ignore, for * which we have a signal handler installed, will release a * sigsuspend. */ - send_thread_signal (suspender_tid, SIGURG); + CHECKr(pthread_kill (suspender_tid, SIGURG)); sleep (1); - send_process_signal (SIGURG); + CHECKe(kill (getpid (), SIGURG)); sleep (1); - if (sigcounts[SIGURG] != 3) - printf ("FAIL: sigsuspend doesn't wake up for SIGURG.\n"); + /* sigsuspend should wake up for SIGURG */ + ASSERT(sigcounts[SIGURG] == 3); /* * Verify that a SIGUSR2 signal will release a sigsuspended * thread. */ - send_thread_signal (suspender_tid, SIGUSR2); + CHECKr(pthread_kill (suspender_tid, SIGUSR2)); sleep (1); - send_process_signal (SIGUSR2); + CHECKe(kill (getpid (), SIGUSR2)); sleep (1); - if (sigcounts[SIGUSR2] != 2) - printf ("FAIL: sigsuspend doesn't wake up for SIGUSR2.\n"); + /* sigsuspend should wake yp for SIGUSR2 */ + ASSERT(sigcounts[SIGUSR2] == 2); /* * Verify that a signal, blocked in both the main and * sigsuspender threads, does not cause the signal handler * to be called. */ - send_thread_signal (suspender_tid, SIGUSR1); + CHECKr(pthread_kill (suspender_tid, SIGUSR1)); sleep (1); - send_process_signal (SIGUSR1); + CHECKe(kill (getpid (), SIGUSR1)); sleep (1); - if (sigcounts[SIGUSR1] != 0) - printf ("FAIL: signal hander called for SIGUSR1.\n"); - + /* signal handler should not be called for USR1 */ + ASSERT(sigcounts[SIGUSR1] == 0); +#if 0 /* * Verify that we can still kill the process for a signal * not being waited on by sigwait. */ - send_process_signal (SIGPIPE); - printf ("FAIL: SIGPIPE did not terminate process.\n"); + CHECKe(kill (getpid (), SIGPIPE)); + PANIC("SIGPIPE did not terminate process"); /* * Wait for the thread to finish. */ - pthread_join (suspender_tid, &exit_status); - - return (0); + CHECKr(pthread_join (suspender_tid, NULL)); +#endif + SUCCEED; } diff --git a/lib/libc_r/test/sigwait/sigwait.c b/lib/libc_r/TEST/test_sigwait.c index 6dd31087a6e..2f0f66619aa 100644 --- a/lib/libc_r/test/sigwait/sigwait.c +++ b/lib/libc_r/TEST/test_sigwait.c @@ -39,9 +39,8 @@ #include <stdio.h> #include <string.h> -#if defined(__FreeBSD__) #include <pthread_np.h> -#endif +#include "test.h" static int sigcounts[NSIG + 1]; static sigset_t wait_mask; @@ -57,61 +56,39 @@ sigwaiter (void *arg) /* Block SIGHUP */ sigemptyset (&mask); sigaddset (&mask, SIGHUP); - sigprocmask (SIG_BLOCK, &mask, NULL); + CHECKe(sigprocmask (SIG_BLOCK, &mask, NULL)); while (sigcounts[SIGINT] == 0) { - if (sigwait (&wait_mask, &signo) != 0) { - printf ("Unable to wait for signal, errno %d\n", - errno); - exit (1); - } + printf("Sigwait waiting (thread %p)\n", pthread_self()); + CHECKe(sigwait (&wait_mask, &signo)); sigcounts[signo]++; - printf ("Sigwait caught signal %d\n", signo); + printf ("Sigwait caught signal %d (%s)\n", signo, + strsignal(signo)); /* Allow the main thread to prevent the sigwait. */ - pthread_mutex_lock (&waiter_mutex); - pthread_mutex_unlock (&waiter_mutex); + CHECKr(pthread_mutex_lock (&waiter_mutex)); + CHECKr(pthread_mutex_unlock (&waiter_mutex)); } - pthread_exit (arg); - return (NULL); + return (arg); } static void sighandler (int signo) { - printf (" -> Signal handler caught signal %d\n", signo); + printf (" -> Signal handler caught signal %d (%s) in thread %p\n", + signo, strsignal(signo), pthread_self()); if ((signo >= 0) && (signo <= NSIG)) sigcounts[signo]++; } -static void -send_thread_signal (pthread_t tid, int signo) -{ - if (pthread_kill (tid, signo) != 0) { - printf ("Unable to send thread signal, errno %d.\n", errno); - exit (1); - } -} - -static void -send_process_signal (int signo) -{ - if (kill (getpid (), signo) != 0) { - printf ("Unable to send process signal, errno %d.\n", errno); - exit (1); - } -} - - int main (int argc, char *argv[]) { pthread_mutexattr_t mattr; pthread_attr_t pattr; pthread_t tid; - void * exit_status; struct sigaction act; /* Initialize our signal counts. */ @@ -132,80 +109,68 @@ int main (int argc, char *argv[]) sigaddset (&act.sa_mask, SIGIO); act.sa_handler = SIG_IGN; act.sa_flags = 0; - sigaction (SIGHUP, &act, NULL); - sigaction (SIGIO, &act, NULL); + CHECKe(sigaction (SIGHUP, &act, NULL)); + CHECKe(sigaction (SIGIO, &act, NULL)); /* Install a signal handler for SIGURG */ sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, SIGURG); act.sa_handler = sighandler; act.sa_flags = SA_RESTART; - sigaction (SIGURG, &act, NULL); + CHECKe(sigaction (SIGURG, &act, NULL)); /* Install a signal handler for SIGXCPU */ sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, SIGXCPU); - sigaction (SIGXCPU, &act, NULL); + CHECKe(sigaction (SIGXCPU, &act, NULL)); /* * Initialize the thread attribute. */ - if ((pthread_attr_init (&pattr) != 0) || - (pthread_attr_setdetachstate (&pattr, - PTHREAD_CREATE_JOINABLE) != 0)) { - printf ("Unable to initialize thread attributes.\n"); - exit (1); - } + CHECKr(pthread_attr_init (&pattr)); + CHECKr(pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE)); /* * Initialize and create a mutex. */ - if ((pthread_mutexattr_init (&mattr) != 0) || - (pthread_mutex_init (&waiter_mutex, &mattr) != 0)) { - printf ("Unable to create waiter mutex.\n"); - exit (1); - } + CHECKr(pthread_mutexattr_init (&mattr)); + CHECKr(pthread_mutex_init (&waiter_mutex, &mattr)); /* * Create the sigwaiter thread. */ - if (pthread_create (&tid, &pattr, sigwaiter, NULL) != 0) { - printf ("Unable to create thread.\n"); - exit (1); - } -#if defined(__FreeBSD__) + CHECKr(pthread_create (&tid, &pattr, sigwaiter, NULL)); pthread_set_name_np (tid, "sigwaiter"); -#endif /* * Verify that an ignored signal doesn't cause a wakeup. * We don't have a handler installed for SIGIO. */ - send_thread_signal (tid, SIGIO); + CHECKr(pthread_kill (tid, SIGIO)); sleep (1); - send_process_signal (SIGIO); + CHECKe(kill(getpid(), SIGIO)); sleep (1); - if (sigcounts[SIGIO] != 0) - printf ("FAIL: sigwait wakes up for ignored signal SIGIO.\n"); + /* sigwait should not wake up for ignored signal SIGIO */ + ASSERT(sigcounts[SIGIO] == 0); /* * Verify that a signal with a default action of ignore, for * which we have a signal handler installed, will release a sigwait. */ - send_thread_signal (tid, SIGURG); + CHECKr(pthread_kill (tid, SIGURG)); sleep (1); - send_process_signal (SIGURG); + CHECKe(kill(getpid(), SIGURG)); sleep (1); - if (sigcounts[SIGURG] != 2) - printf ("FAIL: sigwait doesn't wake up for SIGURG.\n"); + /* sigwait should wake up for SIGURG */ + ASSERT(sigcounts[SIGURG] == 2); /* * Verify that a signal with a default action that terminates * the process will release a sigwait. */ - send_thread_signal (tid, SIGUSR1); + CHECKr(pthread_kill (tid, SIGUSR1)); sleep (1); - send_process_signal (SIGUSR1); + CHECKe(kill(getpid(), SIGUSR1)); sleep (1); if (sigcounts[SIGUSR1] != 2) printf ("FAIL: sigwait doesn't wake up for SIGUSR1.\n"); @@ -221,15 +186,15 @@ int main (int argc, char *argv[]) sigaddset (&act.sa_mask, SIGHUP); act.sa_handler = sighandler; act.sa_flags = SA_RESTART; - sigaction (SIGHUP, &act, NULL); + CHECKe(sigaction (SIGHUP, &act, NULL)); /* Sending SIGHUP should release the sigwait. */ - send_process_signal (SIGHUP); + CHECKe(kill(getpid(), SIGHUP)); sleep (1); - send_thread_signal (tid, SIGHUP); + CHECKr(pthread_kill (tid, SIGHUP)); sleep (1); - if (sigcounts[SIGHUP] != 2) - printf ("FAIL: sigwait doesn't wake up for SIGHUP.\n"); + /* sigwait should wake up for SIGHUP */ + ASSERT(sigcounts[SIGHUP] == 2); /* * Verify that a pending signal in the waiters mask will @@ -242,54 +207,56 @@ int main (int argc, char *argv[]) * return with the pending signal. */ sigcounts[SIGHUP] = 0; - pthread_mutex_lock (&waiter_mutex); + CHECKr(pthread_mutex_lock (&waiter_mutex)); /* Release the waiter from sigwait. */ - send_process_signal (SIGHUP); + CHECKe(kill(getpid(), SIGHUP)); sleep (1); - if (sigcounts[SIGHUP] != 1) - printf ("FAIL: sigwait doesn't wake up for SIGHUP.\n"); + /* sigwait should wake up for SIGHUP */ + ASSERT(sigcounts[SIGHUP] == 1); /* * Add SIGHUP to all threads pending signals. Since there is * a signal handler installed for SIGHUP and this signal is * blocked from the waiter thread and unblocked in the main * thread, the signal handler should be called once for SIGHUP. */ - send_process_signal (SIGHUP); + CHECKe(kill(getpid(), SIGHUP)); /* Release the waiter thread and allow him to run. */ - pthread_mutex_unlock (&waiter_mutex); + CHECKr(pthread_mutex_unlock (&waiter_mutex)); sleep (1); - if (sigcounts[SIGHUP] != 3) - printf ("FAIL: sigwait doesn't return for pending SIGHUP.\n"); + /* sigwait should return for pending SIGHUP */ + ASSERT(sigcounts[SIGHUP] == 3); /* * Repeat the above test using pthread_kill and SIGUSR1 */ sigcounts[SIGUSR1] = 0; - pthread_mutex_lock (&waiter_mutex); + CHECKr(pthread_mutex_lock (&waiter_mutex)); /* Release the waiter from sigwait. */ - send_thread_signal (tid, SIGUSR1); + CHECKr(pthread_kill (tid, SIGUSR1)); sleep (1); - if (sigcounts[SIGUSR1] != 1) - printf ("FAIL: sigwait doesn't wake up for SIGUSR1.\n"); + /* sigwait should wake up for SIGUSR1 */ + ASSERT(sigcounts[SIGUSR1] == 1); /* Add SIGHUP to the waiters pending signals. */ - send_thread_signal (tid, SIGUSR1); + CHECKr(pthread_kill (tid, SIGUSR1)); /* Release the waiter thread and allow him to run. */ - pthread_mutex_unlock (&waiter_mutex); + CHECKe(pthread_mutex_unlock (&waiter_mutex)); sleep (1); - if (sigcounts[SIGUSR1] != 2) - printf ("FAIL: sigwait doesn't return for pending SIGUSR1.\n"); + /* sigwait should return for pending SIGUSR1 */ + ASSERT(sigcounts[SIGUSR1] == 2); +#if 0 /* * Verify that we can still kill the process for a signal * not being waited on by sigwait. */ - send_process_signal (SIGPIPE); - printf ("FAIL: SIGPIPE did not terminate process.\n"); + CHECKe(kill(getpid(), SIGPIPE)); + PANIC("SIGPIPE did not terminate process"); /* * Wait for the thread to finish. */ - pthread_join (tid, &exit_status); + CHECKr(pthread_join (tid, NULL)); +#endif - return (0); + SUCCEED; } diff --git a/lib/libc_r/test/Makefile b/lib/libc_r/test/Makefile deleted file mode 100644 index e5962f61357..00000000000 --- a/lib/libc_r/test/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $Id: Makefile,v 1.1 1998/11/09 03:13:17 d Exp $ -# -# Tests for libc_r functionality. -# - -SUBDIR= sigsuspend sigwait - -.include <bsd.subdir.mk> diff --git a/lib/libc_r/test/sigsuspend/Makefile b/lib/libc_r/test/sigsuspend/Makefile deleted file mode 100644 index 796ffdf97e1..00000000000 --- a/lib/libc_r/test/sigsuspend/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $Id: Makefile,v 1.1 1998/11/09 03:13:17 d Exp $ - -PROG= sigsuspend -SRCS= sigsuspend.c -NOMAN= 1 -LDFLAGS= -pthread - -.include <bsd.prog.mk> diff --git a/lib/libc_r/test/sigwait/Makefile b/lib/libc_r/test/sigwait/Makefile deleted file mode 100644 index 86f70c9a4ab..00000000000 --- a/lib/libc_r/test/sigwait/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $Id: Makefile,v 1.1 1998/11/09 03:13:18 d Exp $ - -PROG= sigwait -SRCS= sigwait.c -NOMAN= 1 -LDFLAGS= -pthread - -.include <bsd.prog.mk> |