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>
This commit is contained in:
parent
1abd6678f6
commit
26286941d5
|
@ -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 @@ ATF_TC_BODY(step4, tc)
|
|||
}
|
||||
#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_TCS(tp)
|
|||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue