git: a96f285b5953 - main - tests/sys/kern: adjust tests for the new reaping behavior
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 01 Aug 2026 12:19:29 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=a96f285b5953f6ff3adb3ab43433ba9e15a9aa46
commit a96f285b5953f6ff3adb3ab43433ba9e15a9aa46
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-29 05:29:21 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-01 10:42:01 +0000
tests/sys/kern: adjust tests for the new reaping behavior
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D58530
---
tests/sys/kern/pdwait.c | 19 +++++++++++--------
tests/sys/kern/procdesc.c | 6 ++++--
tests/sys/kern/ptrace_test.c | 9 ++++-----
tests/sys/kern/reaper.c | 1 +
4 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/tests/sys/kern/pdwait.c b/tests/sys/kern/pdwait.c
index c7b2c40a87ba..92c8c1b2b3ca 100644
--- a/tests/sys/kern/pdwait.c
+++ b/tests/sys/kern/pdwait.c
@@ -216,8 +216,8 @@ ATF_TC_BODY(enotcap, tc)
}
/*
- * Even though the process descriptor is still open, there is no more process
- * to signal after pdwait() has returned.
+ * Zombie is reaped only after the last process descriptor closed. So
+ * the child still can be signalled after pdwait().
*/
ATF_TC_WITHOUT_HEAD(pdkill_after_pdwait);
ATF_TC_BODY(pdkill_after_pdwait, tc)
@@ -226,7 +226,7 @@ ATF_TC_BODY(pdkill_after_pdwait, tc)
pid_t pid;
int r, status;
- pid = pdfork(&fdp, 0);
+ pid = pdfork(&fdp, PD_NOWAITPID);
if (pid == 0)
_exit(42);
ATF_REQUIRE_MSG(pid >= 0, "pdfork failed: %s", strerror(errno));
@@ -236,13 +236,13 @@ ATF_TC_BODY(pdkill_after_pdwait, tc)
ATF_CHECK_EQ(r, 0);
ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
- ATF_REQUIRE_ERRNO(ESRCH, pdkill(fdp, SIGTERM) < 0);
+ ATF_REQUIRE_EQ(pdkill(fdp, SIGTERM), 0);
close(fdp);
}
/*
- * Even though the process descriptor is still open, there is no more status to
+ * While the process descriptor is still open, there is still the status to
* return after a pid-based wait() function has already returned it.
*/
ATF_TC_WITHOUT_HEAD(pdwait_after_waitpid);
@@ -263,12 +263,13 @@ ATF_TC_BODY(pdwait_after_waitpid, tc)
ATF_CHECK_EQ(pid, waited_pid);
ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
- ATF_REQUIRE_ERRNO(ESRCH, pdwait(fdp, NULL, WEXITED, NULL, NULL) < 0);
+ ATF_REQUIRE_EQ(pdwait(fdp, &status, WEXITED, NULL, NULL), 0);
+ ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
close(fdp);
}
-/* Called twice, waitpid should return ESRCH the second time */
+/* Called twice, waitpid should work second time */
ATF_TC_WITHOUT_HEAD(twice);
ATF_TC_BODY(twice, tc)
{
@@ -286,7 +287,9 @@ ATF_TC_BODY(twice, tc)
ATF_CHECK_EQ(r, 0);
ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
- ATF_REQUIRE_ERRNO(ESRCH, pdwait(fdp, NULL, WEXITED, NULL, NULL) < 0);
+ r = pdwait(fdp, &status, WEXITED, NULL, NULL);
+ ATF_CHECK_EQ(r, 0);
+ ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
close(fdp);
}
diff --git a/tests/sys/kern/procdesc.c b/tests/sys/kern/procdesc.c
index 1feaef34e2cb..b78e903adb7c 100644
--- a/tests/sys/kern/procdesc.c
+++ b/tests/sys/kern/procdesc.c
@@ -547,8 +547,10 @@ ATF_TC_BODY(pdopenpid_pdwait_only_one, tc)
"pdwait(fd1): %s", strerror(errno));
ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
- /* The second fd should no longer be able to collect. */
- ATF_REQUIRE_ERRNO(ESRCH, pdwait(fd2, &status, WEXITED, NULL, NULL) < 0);
+ /* The second fd should be able to collect as well. */
+ ATF_REQUIRE_MSG(pdwait(fd2, &status, WEXITED, NULL, NULL) == 0,
+ "pdwait(fd2): %s", strerror(errno));
+ ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
ATF_REQUIRE(close(fd1) == 0);
ATF_REQUIRE(close(fd2) == 0);
diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c
index 478e787d129b..be808a2286d9 100644
--- a/tests/sys/kern/ptrace_test.c
+++ b/tests/sys/kern/ptrace_test.c
@@ -4232,7 +4232,7 @@ ATF_TC_BODY(ptrace__proc_reparent, tc)
pid_t traced, debuger, wpid;
int pd, status;
- traced = pdfork(&pd, 0);
+ traced = pdfork(&pd, PD_NOWAITPID);
ATF_REQUIRE(traced >= 0);
if (traced == 0) {
raise(SIGSTOP);
@@ -4305,12 +4305,11 @@ ATF_TC_BODY(ptrace__procdesc_wait_child, tc)
ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
/*
- * If process was created by pdfork, the return code have to
- * be collected through process descriptor.
+ * If process was created by pdfork but without PD_NOWAITPID,
+ * the return code is available for wait().
*/
wpid = wait(&status);
- REQUIRE_EQ(wpid, -1);
- REQUIRE_EQ(errno, ECHILD);
+ REQUIRE_EQ(wpid, child);
ATF_REQUIRE(close(pd) != -1);
}
diff --git a/tests/sys/kern/reaper.c b/tests/sys/kern/reaper.c
index fb5eeb9b324b..0d3a9a4ba5cf 100644
--- a/tests/sys/kern/reaper.c
+++ b/tests/sys/kern/reaper.c
@@ -764,6 +764,7 @@ ATF_TC_BODY(reaper_pdfork, tc)
ATF_REQUIRE_EQ(pid, child);
r = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
ATF_REQUIRE_EQ(r, 0);
+ close(pd);
r = procctl(P_PID, parent, PROC_REAP_STATUS, &st);
ATF_REQUIRE_EQ(r, 0);