Source-Changes-HG archive

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

src: Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) ...



details:   https://anonhg.NetBSD.org/src/rev/565824651b5a
branches:  trunk
changeset: 318040:565824651b5a
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Apr 11 01:52:59 2018 +0000
description:
Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.

Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
 - calling either fork(2) or vfork(2)
 - tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  298 +++++++++++++++++++++++++++++-------
 1 files changed, 234 insertions(+), 64 deletions(-)

diffs (truncated from 415 to 300 lines):

diff -r 696bef5e50f7 -r 565824651b5a tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Wed Apr 11 00:35:14 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Wed Apr 11 01:52:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.30 2018/04/10 22:45:39 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.31 2018/04/11 01:52:59 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.30 2018/04/10 22:45:39 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.31 2018/04/11 01:52:59 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1328,7 +1328,7 @@
        const int exitval = 5;
        const int exitval2 = 15;
        const int sigval = SIGSTOP;
-       pid_t child, child2, wpid;
+       pid_t child, child2 = 0, wpid;
 #if defined(TWAIT_HAVE_STATUS)
        int status;
 #endif
@@ -1388,7 +1388,7 @@
        SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
 #if defined(TWAIT_HAVE_PID)
-       if (trackfork || trackvfork) {
+       if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) {
                DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
                        child);
                TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
@@ -1398,11 +1398,11 @@
 
                SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state,
                                       slen) != -1);
-               if (trackfork) {
+               if (trackfork && fn == fork) {
                        ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK,
                               PTRACE_FORK);
                }
-               if (trackvfork) {
+               if (trackvfork && fn == vfork) {
                        ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK,
                               PTRACE_VFORK);
                }
@@ -1419,11 +1419,11 @@
 
                SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state,
                                       slen) != -1);
-               if (trackfork) {
+               if (trackfork && fn == fork) {
                        ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK,
                               PTRACE_FORK);
                }
-               if (trackvfork) {
+               if (trackvfork && fn == vfork) {
                        ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK,
                               PTRACE_VFORK);
                }
@@ -1441,7 +1441,7 @@
        }
 #endif
 
-       if (trackvforkdone) {
+       if (trackvforkdone && fn == vfork) {
                DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
                        child);
                TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
@@ -1463,7 +1463,7 @@
        }
 
 #if defined(TWAIT_HAVE_PID)
-       if (trackfork || trackvfork) {
+       if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) {
                DPRINTF("Before calling %s() for the forkee - expected exited"
                        "\n", TWAIT_FNAME);
                TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
@@ -1499,93 +1499,254 @@
        TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
 
-#if defined(TWAIT_HAVE_PID)
 ATF_TC(fork1);
 ATF_TC_HEAD(fork1, tc)
 {
        atf_tc_set_md_var(tc, "descr",
-           "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK "
-           "set to PTRACE_FORK");
+           "Verify that fork(2) is not intercepted by ptrace(2) with empty "
+           "EVENT_MASK");
 }
 
 ATF_TC_BODY(fork1, tc)
 {
 
-       fork_test(fork, true, false, false);
-}
-#endif
-
-ATF_TC(fork2);
-ATF_TC_HEAD(fork2, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify that fork(2) is not intercepted by ptrace(2) with empty "
-           "EVENT_MASK");
-}
-
-ATF_TC_BODY(fork2, tc)
-{
-
        fork_test(fork, false, false, false);
 }
 
 #if defined(TWAIT_HAVE_PID)
+ATF_TC(fork2);
+ATF_TC_HEAD(fork2, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK "
+           "set to PTRACE_FORK");
+}
+
+ATF_TC_BODY(fork2, tc)
+{
+
+       fork_test(fork, true, false, false);
+}
+#endif
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(fork3);
+ATF_TC_HEAD(fork3, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is not intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_VFORK");
+}
+
+ATF_TC_BODY(fork3, tc)
+{
+
+       fork_test(fork, false, true, false);
+}
+#endif
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(fork4);
+ATF_TC_HEAD(fork4, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_FORK|PTRACE_VFORK");
+}
+
+ATF_TC_BODY(fork4, tc)
+{
+
+       fork_test(fork, true, true, false);
+}
+#endif
+
+ATF_TC(fork5);
+ATF_TC_HEAD(fork5, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is not intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_VFORK_DONE");
+}
+
+ATF_TC_BODY(fork5, tc)
+{
+
+       fork_test(fork, false, false, true);
+}
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(fork6);
+ATF_TC_HEAD(fork6, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_FORK|PTRACE_VFORK_DONE");
+}
+
+ATF_TC_BODY(fork6, tc)
+{
+
+       fork_test(fork, true, false, true);
+}
+#endif
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(fork7);
+ATF_TC_HEAD(fork7, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is not intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_VFORK|PTRACE_VFORK_DONE");
+}
+
+ATF_TC_BODY(fork7, tc)
+{
+
+       fork_test(fork, false, true, true);
+}
+#endif
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(fork8);
+ATF_TC_HEAD(fork8, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that fork(2) is intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_FORK|PTRACE_VFORK|PTRACE_VFORK_DONE");
+}
+
+ATF_TC_BODY(fork8, tc)
+{
+
+       fork_test(fork, true, true, true);
+}
+#endif
+
+
 ATF_TC(vfork1);
 ATF_TC_HEAD(vfork1, tc)
 {
        atf_tc_set_md_var(tc, "descr",
-           "Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK "
-           "set to PTRACE_VFORK");
+           "Verify that vfork(2) is not intercepted by ptrace(2) with empty "
+           "EVENT_MASK");
 }
 
 ATF_TC_BODY(vfork1, tc)
 {
 
+       fork_test(vfork, false, false, false);
+}
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(vfork2);
+ATF_TC_HEAD(vfork2, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that vfork(2) is not intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_FORK");
+}
+
+ATF_TC_BODY(vfork2, tc)
+{
+
+       fork_test(vfork, true, false, false);
+}
+#endif
+
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(vfork3);
+ATF_TC_HEAD(vfork3, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that vfork(2) is intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_VFORK");
+}
+
+ATF_TC_BODY(vfork3, tc)
+{
+
        fork_test(vfork, false, true, false);
 }
 #endif
 
-ATF_TC(vfork2);
-ATF_TC_HEAD(vfork2, tc)
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(vfork4);
+ATF_TC_HEAD(vfork4, tc)
 {
        atf_tc_set_md_var(tc, "descr",
-           "Verify that vfork(2) is not intercepted by ptrace(2) with empty "
-           "EVENT_MASK");
-}
-
-ATF_TC_BODY(vfork2, tc)
-{
-
-       fork_test(vfork, false, false, false);
-}
-
-ATF_TC(vforkdone1);
-ATF_TC_HEAD(vforkdone1, tc)
+           "Verify that vfork(2) is intercepted by ptrace(2) with "
+           "EVENT_MASK set to PTRACE_FORK|PTRACE_VFORK");
+}
+



Home | Main Index | Thread Index | Old Index