Source-Changes-HG archive

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

[src/trunk]: src/tests/kernel Add new test siginfo4 in t_ptrace_wait{, 3, 4, 6, i...



details:   https://anonhg.NetBSD.org/src/rev/0353f6f70620
branches:  trunk
changeset: 820307:0353f6f70620
user:      kamil <kamil%NetBSD.org@localhost>
date:      Fri Jan 06 22:40:06 2017 +0000

description:
Add new test siginfo4 in t_ptrace_wait{,3,4,6,id,pid}

siginfo4:
    Detect SIGTRAP TRAP_EXEC from tracee

This test is currently disabled and it will be enabled once
PT_[SG]ET_SIGINFO will land the sources.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/kernel/t_ptrace_wait.c |  65 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 2 deletions(-)

diffs (93 lines):

diff -r 9104b337fd8f -r 0353f6f70620 tests/kernel/t_ptrace_wait.c
--- a/tests/kernel/t_ptrace_wait.c      Fri Jan 06 20:27:19 2017 +0000
+++ b/tests/kernel/t_ptrace_wait.c      Fri Jan 06 22:40:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.49 2017/01/04 22:27:20 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.50 2017/01/06 22:40:06 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.49 2017/01/04 22:27:20 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.50 2017/01/06 22:40:06 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -4701,6 +4701,66 @@
 }
 #endif
 
+#if defined(HAVE_SIGINFO)
+ATF_TC(siginfo4);
+ATF_TC_HEAD(siginfo4, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Detect SIGTRAP TRAP_EXEC from tracee");
+}
+
+ATF_TC_BODY(siginfo4, tc)
+{
+       const int sigval = SIGTRAP;
+       pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+       int status;
+#endif
+
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
+
+       printf("Before forking process PID=%d\n", getpid());
+       ATF_REQUIRE((child = fork()) != -1);
+       if (child == 0) {
+               printf("Before calling PT_TRACE_ME from child %d\n", getpid());
+               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+               printf("Before calling execve(2) from child\n");
+               execlp("/bin/echo", "/bin/echo", NULL);
+
+               FORKEE_ASSERT(0 && "Not reached");
+       }
+       printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       validate_status_stopped(status, sigval);
+
+       printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+       ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
+
+       printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
+       printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
+           info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
+           info.psi_siginfo.si_errno);
+
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC);
+
+       printf("Before resuming the child process where it left off and "
+           "without signal to be sent\n");
+       ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+#endif
+
 ATF_TP_ADD_TCS(tp)
 {
        setvbuf(stdout, NULL, _IONBF, 0);
@@ -4786,6 +4846,7 @@
        ATF_TP_ADD_TC_HAVE_SIGINFO(tp, siginfo1);
        ATF_TP_ADD_TC_HAVE_SIGINFO(tp, siginfo2);
        ATF_TP_ADD_TC_HAVE_SIGINFO(tp, siginfo3);
+       ATF_TP_ADD_TC_HAVE_SIGINFO(tp, siginfo4);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index