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 tests kill[12] in t_ptrace_wait{, 3, 4, 6, ...



details:   https://anonhg.NetBSD.org/src/rev/c62fbc0454d7
branches:  trunk
changeset: 349216:c62fbc0454d7
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Nov 30 21:12:53 2016 +0000

description:
Add new tests kill[12] in t_ptrace_wait{,3,4,6,id,pid}

New tests verify that PT_CONTINUE with SIGKILL is equivalent to PT_KILL.

kill1:
    Verify that PT_CONTINUE with SIGKILL terminates child

kill2:
    Verify that PT_KILL terminates child

Sponsored by <The NetBSD Foundation>

diffstat:

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

diffs (130 lines):

diff -r df5265c09dc5 -r c62fbc0454d7 tests/kernel/t_ptrace_wait.c
--- a/tests/kernel/t_ptrace_wait.c      Wed Nov 30 20:25:23 2016 +0000
+++ b/tests/kernel/t_ptrace_wait.c      Wed Nov 30 21:12:53 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.35 2016/11/29 21:58:13 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.36 2016/11/30 21:12:53 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.35 2016/11/29 21:58:13 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.36 2016/11/30 21:12:53 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -4875,6 +4875,102 @@
 }
 #endif
 
+ATF_TC(kill1);
+ATF_TC_HEAD(kill1, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that PT_CONTINUE with SIGKILL terminates child");
+}
+
+ATF_TC_BODY(kill1, tc)
+{
+       const int sigval = SIGSTOP, sigsent = SIGKILL;
+       pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+       int status;
+#endif
+
+       printf("Before forking process PID=%d\n", getpid());
+       child = atf_utils_fork();
+       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 raising %s from child\n", strsignal(sigval));
+               FORKEE_ASSERT(raise(sigval) == 0);
+
+               /* NOTREACHED */
+               FORKEE_ASSERTX(0 &&
+                   "Child should be terminated by a signal from its parent");
+       }
+       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 resuming the child process where it left off and "
+           "without signal to be sent\n");
+       ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       validate_status_signaled(status, sigsent, 0);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+
+ATF_TC(kill2);
+ATF_TC_HEAD(kill2, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that PT_KILL terminates child");
+}
+
+ATF_TC_BODY(kill2, tc)
+{
+       const int sigval = SIGSTOP;
+       pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+       int status;
+#endif
+
+       printf("Before forking process PID=%d\n", getpid());
+       child = atf_utils_fork();
+       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 raising %s from child\n", strsignal(sigval));
+               FORKEE_ASSERT(raise(sigval) == 0);
+
+               /* NOTREACHED */
+               FORKEE_ASSERTX(0 &&
+                   "Child should be terminated by a signal from its parent");
+       }
+       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 resuming the child process where it left off and "
+           "without signal to be sent\n");
+       ATF_REQUIRE(ptrace(PT_KILL, 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);
+
+       validate_status_signaled(status, SIGKILL, 0);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+
 #if defined(TWAIT_HAVE_PID)
 #define ATF_TP_ADD_TC_HAVE_PID(a,b)    ATF_TP_ADD_TC(a,b)
 #else
@@ -4984,5 +5080,8 @@
        ATF_TP_ADD_TC_PT_STEP(tp, step3);
        ATF_TP_ADD_TC_PT_STEP(tp, step4);
 
+       ATF_TP_ADD_TC_PT_STEP(tp, kill1);
+       ATF_TP_ADD_TC_PT_STEP(tp, kill2);
+
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index