Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Add await_collected()



details:   https://anonhg.NetBSD.org/src/rev/0880fd96d064
branches:  trunk
changeset: 745582:0880fd96d064
user:      kamil <kamil%NetBSD.org@localhost>
date:      Fri Mar 06 17:03:35 2020 +0000

description:
Add await_collected()

This functions waits for collecting a process.

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.h |  29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diffs (43 lines):

diff -r c23198ea527f -r 0880fd96d064 tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Fri Mar 06 14:06:56 2020 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Fri Mar 06 17:03:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.h,v 1.23 2020/03/03 17:09:22 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.h,v 1.24 2020/03/06 17:03:35 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -463,6 +463,33 @@
        return child;
 }
 
+static void __used
+await_collected(pid_t process)
+{
+       struct kinfo_proc2 p;
+       size_t len = sizeof(p);
+
+       const int name[] = {
+               [0] = CTL_KERN,
+               [1] = KERN_PROC2,
+               [2] = KERN_PROC_PID,
+               [3] = process,
+               [4] = sizeof(p),
+               [5] = 1
+       };
+
+       const size_t namelen = __arraycount(name);
+
+       /* Await the process to disappear */
+       while(1) {
+               FORKEE_ASSERT_EQ(sysctl(name, namelen, &p, &len, NULL, 0), 0);
+               if (len == 0)
+                       break;
+
+               ATF_REQUIRE(usleep(1000) == 0);
+       }
+}
+
 /* Happy number sequence -- this function is used to just consume cpu cycles */
 #define        HAPPY_NUMBER    1
 



Home | Main Index | Thread Index | Old Index