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 signal masked and ignored variations ...



details:   https://anonhg.NetBSD.org/src/rev/6ad68956f02d
branches:  trunk
changeset: 997133:6ad68956f02d
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Feb 23 20:46:27 2019 +0000

description:
Add signal masked and ignored variations of traceme_exec in ATF tests

All tests pass.

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  109 +++++++++++++++++++++++++++++++++---
 1 files changed, 98 insertions(+), 11 deletions(-)

diffs (165 lines):

diff -r 03279aac83c9 -r 6ad68956f02d tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Sat Feb 23 19:56:51 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Sat Feb 23 20:46:27 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.96 2019/02/23 18:07:47 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.97 2019/02/23 20:46:27 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.96 2019/02/23 18:07:47 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.97 2019/02/23 20:46:27 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -4593,22 +4593,25 @@
 
 /// ----------------------------------------------------------------------------
 
-ATF_TC(traceme_exec);
-ATF_TC_HEAD(traceme_exec, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Detect SIGTRAP TRAP_EXEC from tracee");
-}
-
-ATF_TC_BODY(traceme_exec, tc)
+static void
+traceme_exec(bool masked, bool ignored)
 {
        const int sigval = SIGTRAP;
        pid_t child, wpid;
 #if defined(TWAIT_HAVE_STATUS)
        int status;
 #endif
-
+       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;
+
        memset(&info, 0, sizeof(info));
 
        DPRINTF("Before forking process PID=%d\n", getpid());
@@ -4617,6 +4620,19 @@
                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, sigval);
+                       sigprocmask(SIG_BLOCK, &intmask, NULL);
+               }
+
+               if (ignored) {
+                       memset(&sa, 0, sizeof(sa));
+                       sa.sa_handler = SIG_IGN;
+                       sigemptyset(&sa.sa_mask);
+                       FORKEE_ASSERT(sigaction(sigval, &sa, NULL) != -1);
+               }
+
                DPRINTF("Before calling execve(2) from child\n");
                execlp("/bin/echo", "/bin/echo", NULL);
 
@@ -4629,6 +4645,55 @@
 
        validate_status_stopped(status, sigval);
 
+       name[0] = CTL_KERN,
+       name[1] = KERN_PROC2,
+       name[2] = KERN_PROC_PID;
+       name[3] = getpid();
+       name[4] = sizeof(kp);
+       name[5] = 1;
+
+       ATF_REQUIRE_EQ(sysctl(name, namelen, &kp, &len, NULL, 0), 0);
+
+       if (masked)
+               kp_sigmask = kp.p_sigmask;
+
+       if (ignored)
+               kp_sigignore = kp.p_sigignore;
+
+       name[3] = getpid();
+
+       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 calling ptrace(2) with PT_GET_SIGINFO for child\n");
        SYSCALL_REQUIRE(
            ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
@@ -4652,6 +4717,26 @@
        TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
 
+#define TRACEME_EXEC(test, masked, ignored)                            \
+ATF_TC(test);                                                          \
+ATF_TC_HEAD(test, tc)                                                  \
+{                                                                      \
+       atf_tc_set_md_var(tc, "descr",                                  \
+           "Detect SIGTRAP TRAP_EXEC from "                            \
+           "child%s%s", masked ? " with masked signal" : "",           \
+           masked ? " with ignored signal" : "");                      \
+}                                                                      \
+                                                                       \
+ATF_TC_BODY(test, tc)                                                  \
+{                                                                      \
+                                                                       \
+       traceme_exec(masked, ignored);                                  \
+}
+
+TRACEME_EXEC(traceme_exec, false, false)
+TRACEME_EXEC(traceme_signalmasked_exec, true, false)
+TRACEME_EXEC(traceme_signalignored_exec, false, true)
+
 /// ----------------------------------------------------------------------------
 
 static volatile int done;
@@ -6423,6 +6508,8 @@
        ATF_TP_ADD_TC(tp, siginfo_set_faked);
 
        ATF_TP_ADD_TC(tp, traceme_exec);
+       ATF_TP_ADD_TC(tp, traceme_signalmasked_exec);
+       ATF_TP_ADD_TC(tp, traceme_signalignored_exec);
 
        ATF_TP_ADD_TC(tp, trace_thread1);
        ATF_TP_ADD_TC(tp, trace_thread2);



Home | Main Index | Thread Index | Old Index