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 test parent_attach_to_its_s...



details:   https://anonhg.NetBSD.org/src/rev/6f43bd2067af
branches:  trunk
changeset: 992101:6f43bd2067af
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Aug 13 22:00:45 2018 +0000

description:
Add a new ATF test parent_attach_to_its_stopped_child

Reuse the body of parent_attach_to_its_child for a test attaching to a
stopped child.

This test passes.

diffstat:

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

diffs (99 lines):

diff -r a4a19be4cd4a -r 6f43bd2067af tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Mon Aug 13 21:49:37 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Mon Aug 13 22:00:45 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.65 2018/08/13 21:36:55 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.66 2018/08/13 22:00:45 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.65 2018/08/13 21:36:55 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.66 2018/08/13 22:00:45 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1368,14 +1368,8 @@
 
 /// ----------------------------------------------------------------------------
 
-ATF_TC(parent_attach_to_its_child);
-ATF_TC_HEAD(parent_attach_to_its_child, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Assert that tracer parent can PT_ATTACH to its child");
-}
-
-ATF_TC_BODY(parent_attach_to_its_child, tc)
+static void
+parent_attach_to_its_child(bool stopped)
 {
        struct msg_fds parent_tracee;
        const int exitval_tracee = 5;
@@ -1392,12 +1386,22 @@
                CHILD_FROM_PARENT("Message 1", parent_tracee, msg);
                DPRINTF("Parent should now attach to tracee\n");
 
+               if (stopped) {
+                       DPRINTF("Stop self PID %d\n", getpid());
+                       SYSCALL_REQUIRE(raise(SIGSTOP) != -1);
+               }
+
                CHILD_FROM_PARENT("Message 2", parent_tracee, msg);
                /* Wait for message from the parent */
                _exit(exitval_tracee);
        }
        PARENT_TO_CHILD("Message 1", parent_tracee, msg);
 
+       if (stopped) {
+               DPRINTF("Await for a stopped tracee PID %d\n", tracee);
+               await_stopped(tracee);
+       }
+
        DPRINTF("Before calling PT_ATTACH for tracee %d\n", tracee);
        SYSCALL_REQUIRE(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
 
@@ -1427,6 +1431,32 @@
        msg_close(&parent_tracee);
 }
 
+ATF_TC(parent_attach_to_its_child);
+ATF_TC_HEAD(parent_attach_to_its_child, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Assert that tracer parent can PT_ATTACH to its child");
+}
+
+ATF_TC_BODY(parent_attach_to_its_child, tc)
+{
+
+       parent_attach_to_its_child(false);
+}
+
+ATF_TC(parent_attach_to_its_stopped_child);
+ATF_TC_HEAD(parent_attach_to_its_stopped_child, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Assert that tracer parent can PT_ATTACH to its stopped child");
+}
+
+ATF_TC_BODY(parent_attach_to_its_stopped_child, tc)
+{
+
+       parent_attach_to_its_child(true);
+}
+
 /// ----------------------------------------------------------------------------
 
 static void
@@ -5670,6 +5700,7 @@
                unrelated_tracer_sees_terminaton_before_the_parent);
 
        ATF_TP_ADD_TC(tp, parent_attach_to_its_child);
+       ATF_TP_ADD_TC(tp, parent_attach_to_its_stopped_child);
 
        ATF_TP_ADD_TC(tp, child_attach_to_its_parent);
        ATF_TP_ADD_TC(tp, child_attach_to_its_stopped_parent);



Home | Main Index | Thread Index | Old Index