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 a new ATF ptrace(2) test: tracer_atta...



details:   https://anonhg.NetBSD.org/src/rev/9f88bad665f9
branches:  trunk
changeset: 834486:9f88bad665f9
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Aug 13 22:59:52 2018 +0000

description:
Add a new ATF ptrace(2) test: tracer_attach_to_unrelated_stopped_process

Reuse the body of tracer_sees_terminaton_before_the_parent_raw for a test
attaching to an unrelated stopped process.

This test passes.

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  47 +++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 6 deletions(-)

diffs (118 lines):

diff -r bb2310a7c30f -r 9f88bad665f9 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Mon Aug 13 22:22:59 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Mon Aug 13 22:59:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.66 2018/08/13 22:00:45 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.67 2018/08/13 22:59:52 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.66 2018/08/13 22:00:45 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.67 2018/08/13 22:59:52 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1182,11 +1182,13 @@
 
 #if defined(TWAIT_HAVE_PID)
 static void
-tracer_sees_terminaton_before_the_parent_raw(bool notimeout, bool unrelated)
+tracer_sees_terminaton_before_the_parent_raw(bool notimeout, bool unrelated,
+                                             bool stopped)
 {
        /*
         * notimeout - disable timeout in await zombie function
         * unrelated - attach from unrelated tracer reparented to initproc
+        * stopped - attach to a stopped process
         */
 
        struct msg_fds parent_tracee, parent_tracer;
@@ -1198,10 +1200,23 @@
        int status;
 #endif
 
+       /*
+        * Only a subset of options are supported.
+        */
+       ATF_REQUIRE((!notimeout && !unrelated && !stopped) ||
+                   (!notimeout && unrelated && !stopped) ||
+                   (notimeout && !unrelated && !stopped) ||
+                   (!notimeout && unrelated && stopped));
+
        DPRINTF("Spawn tracee\n");
        SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0);
        tracee = atf_utils_fork();
        if (tracee == 0) {
+               if (stopped) {
+                       DPRINTF("Stop self PID %d\n", getpid());
+                       raise(SIGSTOP);
+               }
+
                // Wait for parent to let us exit
                CHILD_FROM_PARENT("exit tracee", parent_tracee, msg);
                _exit(exitval_tracee);
@@ -1218,6 +1233,11 @@
                                _exit(exitval_tracer);
                }
 
+               if (stopped) {
+                       DPRINTF("Await for a stopped parent PID %d\n", tracee);
+                       await_stopped(tracee);
+               }
+
                DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid());
                FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
 
@@ -1316,7 +1336,7 @@
 ATF_TC_BODY(tracer_sees_terminaton_before_the_parent, tc)
 {
 
-       tracer_sees_terminaton_before_the_parent_raw(false, false);
+       tracer_sees_terminaton_before_the_parent_raw(false, false, false);
 }
 
 ATF_TC(tracer_sysctl_lookup_without_duplicates);
@@ -1342,7 +1362,8 @@
        start = time(NULL);
        while (true) {
                DPRINTF("Step: %lu\n", N);
-               tracer_sees_terminaton_before_the_parent_raw(true, false);
+               tracer_sees_terminaton_before_the_parent_raw(true, false,
+                                                            false);
                end = time(NULL);
                diff = difftime(end, start);
                if (diff >= 5.0)
@@ -1362,7 +1383,20 @@
 ATF_TC_BODY(unrelated_tracer_sees_terminaton_before_the_parent, tc)
 {
 
-       tracer_sees_terminaton_before_the_parent_raw(false, true);
+       tracer_sees_terminaton_before_the_parent_raw(false, true, false);
+}
+
+ATF_TC(tracer_attach_to_unrelated_stopped_process);
+ATF_TC_HEAD(tracer_attach_to_unrelated_stopped_process, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Assert that tracer can attach to an unrelated stopped process");
+}
+
+ATF_TC_BODY(tracer_attach_to_unrelated_stopped_process, tc)
+{
+
+       tracer_sees_terminaton_before_the_parent_raw(false, true, true);
 }
 #endif
 
@@ -5698,6 +5732,7 @@
        ATF_TP_ADD_TC_HAVE_PID(tp, tracer_sysctl_lookup_without_duplicates);
        ATF_TP_ADD_TC_HAVE_PID(tp,
                unrelated_tracer_sees_terminaton_before_the_parent);
+       ATF_TP_ADD_TC_HAVE_PID(tp, tracer_attach_to_unrelated_stopped_process);
 
        ATF_TP_ADD_TC(tp, parent_attach_to_its_child);
        ATF_TP_ADD_TC(tp, parent_attach_to_its_stopped_child);



Home | Main Index | Thread Index | Old Index