Page MenuHomeFreeBSD

tests/procdesc: Add some test cases for pdopenpid()
ClosedPublic

Authored by markj on Fri, Jul 3, 3:08 PM.
Tags
None
Referenced Files
F162081095: D58023.diff
Thu, Jul 9, 1:37 PM
Unknown Object (File)
Thu, Jul 9, 1:56 AM
Unknown Object (File)
Thu, Jul 9, 1:45 AM
Unknown Object (File)
Wed, Jul 8, 11:51 PM
Unknown Object (File)
Tue, Jul 7, 9:57 PM
Unknown Object (File)
Tue, Jul 7, 9:17 PM
Unknown Object (File)
Tue, Jul 7, 7:21 PM
Unknown Object (File)
Tue, Jul 7, 5:16 AM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Fri, Jul 3, 3:08 PM

i will check this against my branch later. Could you please mail me the git-format patch?

tests/sys/kern/procdesc.c
257

It would be more holistic to loop around the pause()

355
markj marked 2 inline comments as done.

Review feedback, fix the capmode test, add a new test which triggers EMFILE.

Take kib's patch for the self test

Do we want some test to ensure that pdopenpid() has no effect on the target? I mean, ptrace(PT_ATTACH) might cause spurious wakeups (partially mitigated now).

tests/sys/kern/procdesc.c
228

I intended that pause() is covered by loop in all tests.

350

You are using sleep() there to eventually exit the child, am I correct?
You should still loop around the sleep(), otherwise the test is flaky. In the loop, it is possible to check the parent pid with getppid() to note that the parent changed because original parent exited, and then exit the child.

tests/sys/kern/procdesc.c
350
diff --git a/tests/sys/kern/procdesc.c b/tests/sys/kern/procdesc.c
index 6258ecd6e8d8..2f54f138f12e 100644
--- a/tests/sys/kern/procdesc.c
+++ b/tests/sys/kern/procdesc.c
@@ -342,12 +342,14 @@ ATF_TC_BODY(pdopenpid_esrch, tc)
 ATF_TC_WITHOUT_HEAD(pdopenpid_capmode);
 ATF_TC_BODY(pdopenpid_capmode, tc)
 {
- pid_t child;
+  pid_t child, parent;
 
+  parent = getpid();
   child = fork();
   ATF_REQUIRE_MSG(child >= 0, "fork: %s", strerror(errno));
   if (child == 0) {
-    sleep(1);
+     while (getppid() == parent)
+        sleep(1);
      _exit(0);
   }

worked for me

markj marked 3 inline comments as done.

Address review feedback, add procdesc_no_wakeup

In D58023#1331065, @kib wrote:

Do we want some test to ensure that pdopenpid() has no effect on the target? I mean, ptrace(PT_ATTACH) might cause spurious wakeups (partially mitigated now).

Like, we should check that pdopenpid() does not result in a spurious wakeup of the target? That's a good idea.

tests/sys/kern/procdesc.c
350

Right, since the parent is in capability mode here it can't use kill().

tests/sys/kern/procdesc.c
299

Loop there?

651

This is racy, and I think that it would typically cause the test to succeed even for the interrupting pdopenpid(). The child might not yet exit.

The proper test would be to re-check that the child is still sleeping in "piperd" after pdopen().

markj marked 2 inline comments as done.

Re-check that the child is sleeping.

This revision is now accepted and ready to land.Mon, Jul 6, 2:29 PM