Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157772762
D57149.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D57149.diff
View Options
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -106,7 +106,7 @@
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
--- 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 @@
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 @@
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));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 26, 12:29 AM (5 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33521259
Default Alt Text
D57149.diff (2 KB)
Attached To
Mode
D57149: tests/procdesc: Use a more efficient mechanism to block
Attached
Detach File
Event Timeline
Log In to Comment