Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 May 2026 14:57:10 +0000
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: c9546bb61910 - main - tests/procdesc: Use a more efficient mechanism to block
Message-ID:  <6a106ec6.1df0b.241bdf1d@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=c9546bb61910d40f4cb0dfb9716ba6eba44d1a0d

commit c9546bb61910d40f4cb0dfb9716ba6eba44d1a0d
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-05-22 14:56:47 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-05-22 14:56:47 +0000

    tests/procdesc: Use a more efficient mechanism to block
    
    Reviewed by:    kib
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D57149
---
 tests/sys/kern/Makefile   |  2 +-
 tests/sys/kern/procdesc.c | 41 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index d7a6af905b7e..dcaeb8d2f1fa 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -106,7 +106,7 @@ LIBADD.kcov+=				pthread
 CFLAGS.ktls_test+=			-DOPENSSL_API_COMPAT=0x10100000L
 LIBADD.ktls_test+=			crypto util
 LIBADD.listener_wakeup+=		pthread
-LIBADD.procdesc+=			pthread
+LIBADD.procdesc+=			kvm pthread
 LIBADD.shutdown_dgram+=			pthread
 LIBADD.socket_msg_waitall+=		pthread
 LIBADD.socket_splice+=			pthread
diff --git a/tests/sys/kern/procdesc.c b/tests/sys/kern/procdesc.c
index 2d710ef057f2..2fe50be45bf7 100644
--- a/tests/sys/kern/procdesc.c
+++ b/tests/sys/kern/procdesc.c
@@ -33,15 +33,50 @@
 #include <sys/sysctl.h>
 #include <sys/wait.h>
 
+#include <fcntl.h>
 #include <poll.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
 
 #include <atf-c.h>
+#include <kvm.h>
 
 /* Tests for procdesc(4) that aren't specific to any one syscall */
 
+/*
+ * Block until a thread in the specified process is sleeping in the specified
+ * wait message.
+ */
+static void
+wait_for_naptime(pid_t pid, const char *wmesg)
+{
+	kvm_t *kd;
+	int count;
+
+	kd = kvm_openfiles(NULL, "/dev/null", NULL, O_RDONLY, NULL);
+	ATF_REQUIRE(kd != NULL);
+	for (;;) {
+		struct kinfo_proc *kip;
+		int i;
+
+		usleep(1000);
+		kip = kvm_getprocs(kd, KERN_PROC_PID | KERN_PROC_INC_THREAD,
+		    pid, &count);
+		ATF_REQUIRE(kip != NULL);
+		for (i = 0; i < count; i++) {
+			ATF_REQUIRE(kip[i].ki_stat != SZOMB);
+			if (kip[i].ki_stat == SSLEEP &&
+			    strcmp(kip[i].ki_wmesg, wmesg) == 0)
+				break;
+		}
+		if (i < count)
+			break;
+	}
+
+	kvm_close(kd);
+}
+
 /*
  * Even after waiting on a process descriptor with waitpid(2), the kernel will
  * not recycle the pid until after the process descriptor is closed.  That is
@@ -128,8 +163,7 @@ ATF_TC_BODY(poll_close_race, tc)
 	error = pthread_create(&thr, NULL, poll_procdesc, &pd);
 	ATF_REQUIRE_MSG(error == 0, "pthread_create: %s", strerror(error));
 
-	/* Wait for the thread to block in poll(2). */
-	usleep(250000);
+	wait_for_naptime(getpid(), "select");
 
 	ATF_REQUIRE_MSG(close(pd) == 0, "close: %s", strerror(errno));
 
@@ -159,8 +193,7 @@ ATF_TC_BODY(poll_exit_wakeup, tc)
 	error = pthread_create(&thr, NULL, poll_procdesc, &pd);
 	ATF_REQUIRE_MSG(error == 0, "pthread_create: %s", strerror(error));
 
-	/* Wait for the thread to block in poll(2). */
-	usleep(250000);
+	wait_for_naptime(getpid(), "select");
 
 	ATF_REQUIRE_MSG(pdkill(pd, SIGKILL) == 0,
 	    "pdkill: %s", strerror(errno));


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a106ec6.1df0b.241bdf1d>