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 Replace signal4 (PT_STEP) test with refac...



details:   https://anonhg.NetBSD.org/src/rev/431ecdaaafac
branches:  trunk
changeset: 449051:431ecdaaafac
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Feb 20 09:25:11 2019 +0000

description:
Replace signal4 (PT_STEP) test with refactored ones with extra asserts

New tests: step_signalmasked and step_signalignored.

Assert that signal context is not reset upon PT_STEP trap.

Mark new tests as expecting to fail.

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  189 +++++++++++++++++++++---------------
 1 files changed, 108 insertions(+), 81 deletions(-)

diffs (279 lines):

diff -r 962469ae3e00 -r 431ecdaaafac tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Wed Feb 20 08:03:58 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Wed Feb 20 09:25:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.94 2019/02/20 07:18:18 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.95 2019/02/20 09:25:11 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.94 2019/02/20 07:18:18 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.95 2019/02/20 09:25:11 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -3724,7 +3724,7 @@
 
 #if defined(PT_STEP)
 static void
-ptrace_step(int N, int setstep)
+ptrace_step(int N, int setstep, bool masked, bool ignored)
 {
        const int exitval = 5;
        const int sigval = SIGSTOP;
@@ -3733,19 +3733,45 @@
        int status;
 #endif
        int happy;
+       struct sigaction sa;
        struct ptrace_siginfo info;
+       sigset_t intmask;
+       struct kinfo_proc2 kp;
+       size_t len = sizeof(kp);
+
+       int name[6];
+       const size_t namelen = __arraycount(name);
+       ki_sigset_t kp_sigmask;
+       ki_sigset_t kp_sigignore;
 
 #if defined(__arm__)
        /* PT_STEP not supported on arm 32-bit */
        atf_tc_expect_fail("PR kern/52119");
 #endif
 
+       if (masked || ignored)
+               atf_tc_expect_fail("Unexpected sigmask reset on crash under "
+                   "debugger");
+
        DPRINTF("Before forking process PID=%d\n", getpid());
        SYSCALL_REQUIRE((child = fork()) != -1);
        if (child == 0) {
                DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
                FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
 
+               if (masked) {
+                       sigemptyset(&intmask);
+                       sigaddset(&intmask, SIGTRAP);
+                       sigprocmask(SIG_BLOCK, &intmask, NULL);
+               }
+
+               if (ignored) {
+                       memset(&sa, 0, sizeof(sa));
+                       sa.sa_handler = SIG_IGN;
+                       sigemptyset(&sa.sa_mask);
+                       FORKEE_ASSERT(sigaction(SIGTRAP, &sa, NULL) != -1);
+               }
+
                happy = check_happy(999);
 
                DPRINTF("Before raising %s from child\n", strsignal(sigval));
@@ -3771,6 +3797,21 @@
        ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
        ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
 
+       name[0] = CTL_KERN,
+       name[1] = KERN_PROC2,
+       name[2] = KERN_PROC_PID;
+       name[3] = child;
+       name[4] = sizeof(kp);
+       name[5] = 1;
+
+       FORKEE_ASSERT_EQ(sysctl(name, namelen, &kp, &len, NULL, 0), 0);
+
+       if (masked)
+               kp_sigmask = kp.p_sigmask;
+
+       if (ignored)
+               kp_sigignore = kp.p_sigignore;
+
        while (N --> 0) {
                if (setstep) {
                        DPRINTF("Before resuming the child process where it "
@@ -3804,6 +3845,42 @@
                if (setstep) {
                        SYSCALL_REQUIRE(ptrace(PT_CLEARSTEP, child, 0, 0) != -1);
                }
+
+               ATF_REQUIRE_EQ(sysctl(name, namelen, &kp, &len, NULL, 0), 0);
+
+               if (masked) {
+                       DPRINTF("kp_sigmask="
+                           "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
+                           PRIx32 "\n",
+                           kp_sigmask.__bits[0], kp_sigmask.__bits[1],
+                           kp_sigmask.__bits[2], kp_sigmask.__bits[3]);
+
+                       DPRINTF("kp.p_sigmask="
+                           "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
+                           PRIx32 "\n",
+                           kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1],
+                           kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]);
+
+                       ATF_REQUIRE(!memcmp(&kp_sigmask, &kp.p_sigmask,
+                           sizeof(kp_sigmask)));
+               }
+
+               if (ignored) {
+                       DPRINTF("kp_sigignore="
+                           "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
+                           PRIx32 "\n",
+                           kp_sigignore.__bits[0], kp_sigignore.__bits[1],
+                           kp_sigignore.__bits[2], kp_sigignore.__bits[3]);
+
+                       DPRINTF("kp.p_sigignore="
+                           "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
+                           PRIx32 "\n",
+                           kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1],
+                           kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]);
+
+                       ATF_REQUIRE(!memcmp(&kp_sigignore, &kp.p_sigignore,
+                           sizeof(kp_sigignore)));
+               }
        }
 
        DPRINTF("Before resuming the child process where it left off and "
@@ -3830,7 +3907,7 @@
 ATF_TC_BODY(test, tc)                                                  \
 {                                                                      \
                                                                        \
-        ptrace_step(N, setstep);                                       \
+        ptrace_step(N, setstep, false, false);                         \
 }
 
 PTRACE_STEP(step1, 1, 0)
@@ -3841,6 +3918,30 @@
 PTRACE_STEP(setstep2, 2, 1)
 PTRACE_STEP(setstep3, 3, 1)
 PTRACE_STEP(setstep4, 4, 1)
+
+ATF_TC(step_signalmasked);
+ATF_TC_HEAD(step_signalmasked, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Verify PT_STEP with masked SIGTRAP");
+}
+
+ATF_TC_BODY(step_signalmasked, tc)
+{
+
+       ptrace_step(1, 0, true, false);
+}
+
+ATF_TC(step_signalignored);
+ATF_TC_HEAD(step_signalignored, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Verify PT_STEP with ignored SIGTRAP");
+}
+
+ATF_TC_BODY(step_signalignored, tc)
+{
+
+       ptrace_step(1, 0, false, true);
+}
 #endif
 
 /// ----------------------------------------------------------------------------
@@ -4755,82 +4856,6 @@
 
 /// ----------------------------------------------------------------------------
 
-#if defined(PT_STEP)
-ATF_TC(signal4);
-ATF_TC_HEAD(signal4, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify that masking SIGTRAP in tracee does not stop tracer from "
-           "catching single step trap");
-}
-
-ATF_TC_BODY(signal4, tc)
-{
-       const int exitval = 5;
-       const int sigval = SIGSTOP;
-       const int sigmasked = SIGTRAP;
-       pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-       int status;
-#endif
-       sigset_t intmask;
-       int happy;
-
-#if defined(__arm__)
-       /* PT_STEP not supported on arm 32-bit */
-       atf_tc_expect_fail("PR kern/51918 PR kern/52119");
-#endif
-
-       DPRINTF("Before forking process PID=%d\n", getpid());
-       SYSCALL_REQUIRE((child = fork()) != -1);
-       if (child == 0) {
-               DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
-               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-               happy = check_happy(100);
-
-               sigemptyset(&intmask);
-               sigaddset(&intmask, sigmasked);
-               sigprocmask(SIG_BLOCK, &intmask, NULL);
-
-               DPRINTF("Before raising %s from child\n", strsignal(sigval));
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               FORKEE_ASSERT_EQ(happy, check_happy(100));
-
-               DPRINTF("Before exiting of the child process\n");
-               _exit(exitval);
-       }
-       DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-       validate_status_stopped(status, sigval);
-
-       DPRINTF("Before resuming the child process where it left off and "
-           "without signal to be sent\n");
-       SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-       validate_status_stopped(status, sigmasked);
-
-       DPRINTF("Before resuming the child process where it left off and "
-           "without signal to be sent\n");
-       SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-       validate_status_exited(status, exitval);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-#endif
-
 ATF_TC(signal5);
 ATF_TC_HEAD(signal5, tc)
 {
@@ -6290,6 +6315,9 @@
        ATF_TP_ADD_TC_PT_STEP(tp, setstep3);
        ATF_TP_ADD_TC_PT_STEP(tp, setstep4);
 
+       ATF_TP_ADD_TC_PT_STEP(tp, step_signalmasked);
+       ATF_TP_ADD_TC_PT_STEP(tp, step_signalignored);
+
        ATF_TP_ADD_TC(tp, kill1);
        ATF_TP_ADD_TC(tp, kill2);
        ATF_TP_ADD_TC(tp, kill3);
@@ -6316,7 +6344,6 @@
 
        ATF_TP_ADD_TC(tp, signal_mask_unrelated);
 
-       ATF_TP_ADD_TC_PT_STEP(tp, signal4);
        ATF_TP_ADD_TC(tp, signal5);
        ATF_TP_ADD_TC_HAVE_PID(tp, signal6);
        ATF_TP_ADD_TC_HAVE_PID(tp, signal7);



Home | Main Index | Thread Index | Old Index