diff options
author | David Leonard <d@cvs.openbsd.org> | 1999-03-10 09:23:56 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1999-03-10 09:23:56 +0000 |
commit | 65d96f11b240382a9a3438788ac574063ea13f03 (patch) | |
tree | ee3259ad027a49d0abef6ceebbd818a345d51da3 /lib/libc_r | |
parent | 7b835a298b0b450e6af3d563b4f601ed753e04de (diff) |
define and use a SET_NAME macro so that these tests work under other thread implementations
Diffstat (limited to 'lib/libc_r')
-rw-r--r-- | lib/libc_r/TEST/Makefile | 7 | ||||
-rw-r--r-- | lib/libc_r/TEST/test.h | 8 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_cancel.c | 8 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_pthread_mutex.c | 3 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_select.c | 4 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_sigsuspend.c | 3 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_sigwait.c | 3 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_sock_2.c | 4 | ||||
-rw-r--r-- | lib/libc_r/TEST/test_switch.c | 3 |
9 files changed, 27 insertions, 16 deletions
diff --git a/lib/libc_r/TEST/Makefile b/lib/libc_r/TEST/Makefile index 2f671d92f00..24700307033 100644 --- a/lib/libc_r/TEST/Makefile +++ b/lib/libc_r/TEST/Makefile @@ -10,11 +10,10 @@ LIBC_R?= /usr/lib/libc_r.a -CPPFLAGS += -pthread -LDFLAGS += -pthread -CFLAGS += -ggdb -Wall # -Werror +CFLAGS += -Wall # -Werror +DEBUG = -ggdb CFLAGS += -DSRCDIR='"${.CURDIR}"' -LDLIBS += -lm +LDLIBS += -lpthread -lm ${LDSTATIC} DPADD += ${LIBC_R} MKDEP = -p diff --git a/lib/libc_r/TEST/test.h b/lib/libc_r/TEST/test.h index f945092fe66..990526fb98c 100644 --- a/lib/libc_r/TEST/test.h +++ b/lib/libc_r/TEST/test.h @@ -17,6 +17,14 @@ static __dead void __vpanic __P((const char *, const char *, const char *, static __dead void __panic __P((const char *, const char *, const char *, int, const char *, ...)) __attribute__((noreturn)); +#if defined(__OpenBSD__) || defined(__FreeBSD__) +#include <pthread.h> +#include <pthread_np.h> +#define SET_NAME(x) pthread_set_name_np(pthread_self(), x) +#else +#define SET_NAME(x) /* nada */ +#endif + static void __vpanic(type, errstr, filenm, lineno, fmt, ap) const char *type; diff --git a/lib/libc_r/TEST/test_cancel.c b/lib/libc_r/TEST/test_cancel.c index 74ecaf317d9..fe8aa18a8fa 100644 --- a/lib/libc_r/TEST/test_cancel.c +++ b/lib/libc_r/TEST/test_cancel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_cancel.c,v 1.1 1999/01/17 23:57:26 d Exp $ */ +/* $OpenBSD: test_cancel.c,v 1.2 1999/03/10 09:23:55 d Exp $ */ /* David Leonard <d@openbsd.org>, 1999. Public Domain. */ #include <pthread.h> @@ -48,7 +48,7 @@ child1fn(arg) char buf[1024]; int len; - pthread_set_name_np(pthread_self(), "c1"); + SET_NAME("c1"); CHECKr(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)); /* something that will block */ CHECKe(fd = open("/dev/tty", O_RDONLY)); @@ -74,7 +74,7 @@ void * child2fn(arg) void *arg; { - pthread_set_name_np(pthread_self(), "c2"); + SET_NAME("c2"); CHECKr(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)); pthread_cleanup_push(c2handler, NULL); @@ -124,7 +124,7 @@ void * child3fn(arg) void *arg; { - pthread_set_name_np(pthread_self(), "c3"); + SET_NAME("c3"); pthread_cleanup_push(c3handler, NULL); /* Cancel myself */ diff --git a/lib/libc_r/TEST/test_pthread_mutex.c b/lib/libc_r/TEST/test_pthread_mutex.c index 00d5616d0d4..1e86fe89368 100644 --- a/lib/libc_r/TEST/test_pthread_mutex.c +++ b/lib/libc_r/TEST/test_pthread_mutex.c @@ -20,6 +20,8 @@ thread_contention(arg) { pthread_mutex_t *mutex = arg; + SET_NAME("cntntn"); + CHECKr(pthread_mutex_lock(mutex)); ASSERT(contention_variable == 1); contention_variable = 2; @@ -37,7 +39,6 @@ test_contention_lock(mutex) CHECKr(pthread_mutex_lock(mutex)); contention_variable = 0; CHECKr(pthread_create(&thread, NULL, thread_contention, mutex)); - pthread_set_name_np(thread, "cntntn"); pthread_yield(); contention_variable = 1; CHECKr(pthread_mutex_unlock(mutex)); diff --git a/lib/libc_r/TEST/test_select.c b/lib/libc_r/TEST/test_select.c index fedd8295318..4202a06439c 100644 --- a/lib/libc_r/TEST/test_select.c +++ b/lib/libc_r/TEST/test_select.c @@ -16,7 +16,7 @@ bg_routine(arg) void *arg; { char dot = '.'; - pthread_set_name_np(pthread_self(), "bg"); + SET_NAME("bg"); write(STDOUT_FILENO,"bg routine running\n",19); /*pthread_dump_state();*/ while (1) { @@ -39,7 +39,7 @@ fg_routine(arg) int n; fd_set r; - pthread_set_name_np(pthread_self(), "fg"); + SET_NAME("fg"); flags = fcntl(STDIN_FILENO, F_GETFL); CHECKr(fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK)); diff --git a/lib/libc_r/TEST/test_sigsuspend.c b/lib/libc_r/TEST/test_sigsuspend.c index da345f8d0bc..a4978df7997 100644 --- a/lib/libc_r/TEST/test_sigsuspend.c +++ b/lib/libc_r/TEST/test_sigsuspend.c @@ -55,6 +55,8 @@ sigsuspender (void *arg) int save_count, status, i; sigset_t run_mask; + SET_NAME("sigsuspender"); + /* Run with all signals blocked. */ sigfillset (&run_mask); CHECKe(sigprocmask (SIG_SETMASK, &run_mask, NULL)); @@ -172,7 +174,6 @@ int main (int argc, char *argv[]) * Create the sigsuspender thread. */ CHECKr(pthread_create (&suspender_tid, &pattr, sigsuspender, NULL)); - pthread_set_name_np (suspender_tid, "sigsuspender"); /* * Verify that an ignored signal doesn't cause a wakeup. diff --git a/lib/libc_r/TEST/test_sigwait.c b/lib/libc_r/TEST/test_sigwait.c index 2f0f66619aa..a13235414a8 100644 --- a/lib/libc_r/TEST/test_sigwait.c +++ b/lib/libc_r/TEST/test_sigwait.c @@ -53,6 +53,8 @@ sigwaiter (void *arg) int signo; sigset_t mask; + SET_NAME("sigwaiter"); + /* Block SIGHUP */ sigemptyset (&mask); sigaddset (&mask, SIGHUP); @@ -140,7 +142,6 @@ int main (int argc, char *argv[]) * Create the sigwaiter thread. */ CHECKr(pthread_create (&tid, &pattr, sigwaiter, NULL)); - pthread_set_name_np (tid, "sigwaiter"); /* * Verify that an ignored signal doesn't cause a wakeup. diff --git a/lib/libc_r/TEST/test_sock_2.c b/lib/libc_r/TEST/test_sock_2.c index 59c240e6ac6..7f4bdf8c736 100644 --- a/lib/libc_r/TEST/test_sock_2.c +++ b/lib/libc_r/TEST/test_sock_2.c @@ -30,7 +30,7 @@ sock_write(arg) { int fd = *(int *)arg; - pthread_set_name_np(pthread_self(), "writer"); + SET_NAME("writer"); CHECKe(write(fd, MESSAGE5, sizeof(MESSAGE5))); return(NULL); } @@ -43,7 +43,7 @@ waiter(sig) int status; pid_t pid; - pthread_set_name_np(pthread_self(), "waiter"); + SET_NAME("waiter"); CHECKr(pthread_mutex_lock(&waiter_mutex)); printf("waiting for child\n"); CHECKe(pid = wait(&status)); diff --git a/lib/libc_r/TEST/test_switch.c b/lib/libc_r/TEST/test_switch.c index 5d637bda041..311f00df362 100644 --- a/lib/libc_r/TEST/test_switch.c +++ b/lib/libc_r/TEST/test_switch.c @@ -32,6 +32,7 @@ void * new_thread(arg) void *arg; { + SET_NAME("writer"); while(1) { CHECKe(write (fd, (char *) arg, 1)); x[(char *)arg - buf] = 1; @@ -83,7 +84,7 @@ main(argc, argv) (void*)(buf+i))); /* give all threads a chance to run */ - sleep (2); + sleep (6); for (i = 0; i < count; i++) ASSERT(x[i]); /* make sure each thread ran */ |