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_stopped() in t_ptrace_wait.h



details:   https://anonhg.NetBSD.org/src/rev/d652ef7263ac
branches:  trunk
changeset: 363867:d652ef7263ac
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Aug 13 21:49:37 2018 +0000

description:
Add await_stopped() in t_ptrace_wait.h

This is used in tests where a process awaits for a stopped process.

diffstat:

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

diffs (44 lines):

diff -r 86fb6006128a -r d652ef7263ac tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Mon Aug 13 21:36:55 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Mon Aug 13 21:49:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.h,v 1.11 2018/05/30 17:48:13 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.h,v 1.12 2018/08/13 21:49:37 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -375,6 +375,34 @@
        await_zombie_raw(process, 1000);
 }
 
+static void __used
+await_stopped(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 becoming a zombie */
+       while(1) {
+               ATF_REQUIRE(sysctl(name, namelen, &p, &len, NULL, 0) == 0);
+
+               if (p.p_stat == LSSTOP)
+                       break;
+
+               ATF_REQUIRE(usleep(1000) == 0);
+       }
+}
+
 static pid_t __used
 await_stopped_child(pid_t process)
 {



Home | Main Index | Thread Index | Old Index