diff options
| -rw-r--r-- | lib/libthr/tests/Makefile | 1 | ||||
| -rw-r--r-- | lib/libthr/tests/pthread_tryjoin_test.c | 29 |
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/libthr/tests/Makefile b/lib/libthr/tests/Makefile index 5ffcd7b046c8..f738c3268c56 100644 --- a/lib/libthr/tests/Makefile +++ b/lib/libthr/tests/Makefile @@ -40,6 +40,7 @@ ATF_TESTS_C+= pthread_tryjoin_test LIBADD+= pthread LIBADD.fpu_test+= m +LIBADD.pthread_tryjoin_test+= kvm LIBADD.sem_test+= rt BINDIR= ${TESTSDIR} diff --git a/lib/libthr/tests/pthread_tryjoin_test.c b/lib/libthr/tests/pthread_tryjoin_test.c index ba88ac2ed6f5..ca92f8e25228 100644 --- a/lib/libthr/tests/pthread_tryjoin_test.c +++ b/lib/libthr/tests/pthread_tryjoin_test.c @@ -10,6 +10,8 @@ #include <atf-c.h> #include <err.h> #include <errno.h> +#include <fcntl.h> +#include <kvm.h> #include <pthread.h> #include <pthread_np.h> #include <stdatomic.h> @@ -22,11 +24,22 @@ static void * thr_fun(void *arg) { while (atomic_load_explicit(&finish, memory_order_relaxed) != 1) - sleep(1); - atomic_store_explicit(&finish, 2, memory_order_relaxed); + usleep(1000); return (arg); } +static int +thread_count(kvm_t *kd, pid_t pid) +{ + struct kinfo_proc *kip; + int count; + + kip = kvm_getprocs(kd, KERN_PROC_PID | KERN_PROC_INC_THREAD, pid, + &count); + ATF_REQUIRE(kip != NULL); + return (count); +} + ATF_TC(pthread_tryjoin); ATF_TC_HEAD(pthread_tryjoin, tc) { @@ -37,8 +50,13 @@ ATF_TC_HEAD(pthread_tryjoin, tc) ATF_TC_BODY(pthread_tryjoin, tc) { pthread_t thr; + kvm_t *kd; void *retval; - int error, x; + int error, nthr, x; + + kd = kvm_openfiles(NULL, "/dev/null", NULL, O_RDONLY, NULL); + ATF_REQUIRE(kd != NULL); + nthr = thread_count(kd, getpid()); error = pthread_create(&thr, NULL, thr_fun, &x); ATF_REQUIRE_EQ(error, 0); @@ -47,8 +65,9 @@ ATF_TC_BODY(pthread_tryjoin, tc) ATF_REQUIRE_EQ(error, EBUSY); atomic_store_explicit(&finish, 1, memory_order_relaxed); - while (atomic_load_explicit(&finish, memory_order_relaxed) != 2) - sleep(1); + while (thread_count(kd, getpid()) != nthr) + usleep(1000); + kvm_close(kd); error = pthread_tryjoin_np(thr, &retval); ATF_REQUIRE_EQ(error, 0); |
