git: d510a58af69c - stable/15 - tests/sys/kern: adjust tests for the new reaping behavior

Konstantin Belousov <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a8124b7.423d2.7b3eb42e__10623.6674518854$1786848884$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by kib:

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

commit d510a58af69cc6a06909595275526ad185972347
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-07-29 05:29:21 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-08-16 02:41:38 +0000

    tests/sys/kern: adjust tests for the new reaping behavior
    
    (cherry picked from commit a96f285b5953f6ff3adb3ab43433ba9e15a9aa46)
---
 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 79e0f77a0aa7..4f38f354c1c1 100644
--- a/tests/sys/kern/ptrace_test.c
+++ b/tests/sys/kern/ptrace_test.c
@@ -4234,7 +4234,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);
@@ -4307,12 +4307,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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.