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 signal2 in t_ptrace_wait* with ne...
details: https://anonhg.NetBSD.org/src/rev/898b5f63793d
branches: trunk
changeset: 448927:898b5f63793d
user: kamil <kamil%NetBSD.org@localhost>
date: Thu Feb 14 06:47:32 2019 +0000
description:
Replace signal2 in t_ptrace_wait* with new tests
Add new tests traceme_raisesignal_masked[1-8].
New tests to verify that masking (with SIG_BLOCK) signal in tracee
stops tracer from catching this raised signal. Masked crash signals are
invisible to tracer as well.
All tests pass.
diffstat:
tests/lib/libc/sys/t_ptrace_wait.c | 166 +++++++++++++++++++++++-------------
1 files changed, 104 insertions(+), 62 deletions(-)
diffs (208 lines):
diff -r e399aaef063c -r 898b5f63793d tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 14 05:38:45 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 14 06:47:32 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.85 2019/02/14 05:38:45 kamil Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.86 2019/02/14 06:47:32 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.85 2019/02/14 05:38:45 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.86 2019/02/14 06:47:32 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -188,6 +188,99 @@
/// ----------------------------------------------------------------------------
static void
+traceme_raisesignal_masked(int sigmasked)
+{
+ const int exitval = 5;
+ const int sigval = SIGSTOP;
+ pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+ int status;
+#endif
+ sigset_t intmask;
+ struct ptrace_siginfo info;
+
+ memset(&info, 0, sizeof(info));
+
+ 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);
+
+ sigemptyset(&intmask);
+ sigaddset(&intmask, sigmasked);
+ sigprocmask(SIG_BLOCK, &intmask, NULL);
+
+ DPRINTF("Before raising %s from child\n", strsignal(sigval));
+ FORKEE_ASSERT(raise(sigval) == 0);
+
+ DPRINTF("Before raising %s breakpoint from child\n",
+ strsignal(sigmasked));
+ FORKEE_ASSERT(raise(sigmasked) == 0);
+
+ 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 calling ptrace(2) with PT_GET_SIGINFO for child\n");
+ SYSCALL_REQUIRE(
+ ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
+
+ DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+ DPRINTF("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, SI_LWP);
+
+ 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));
+}
+
+#define TRACEME_RAISESIGNAL_MASKED(test, sig) \
+ATF_TC(test); \
+ATF_TC_HEAD(test, tc) \
+{ \
+ atf_tc_set_md_var(tc, "descr", \
+ "Verify that masking (with SIG_BLOCK) " #sig " in tracee " \
+ "stops tracer from catching this raised signal"); \
+} \
+ \
+ATF_TC_BODY(test, tc) \
+{ \
+ \
+ traceme_raisesignal_masked(sig); \
+}
+
+// A signal handler for SIGKILL and SIGSTOP cannot be masked.
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked1, SIGABRT) /* abort trap */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked2, SIGHUP) /* hangup */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked3, SIGCONT) /* continued? */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked4, SIGTRAP) /* crash sig. */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked5, SIGBUS) /* crash sig. */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked6, SIGILL) /* crash sig. */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked7, SIGFPE) /* crash sig. */
+TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked8, SIGSEGV) /* crash sig. */
+
+/// ----------------------------------------------------------------------------
+
+static void
traceme_crash(int sig)
{
pid_t child, wpid;
@@ -3849,65 +3942,6 @@
/// ----------------------------------------------------------------------------
-ATF_TC(signal2);
-ATF_TC_HEAD(signal2, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that masking SIGTRAP in tracee stops tracer from "
- "catching this raised signal");
-}
-
-ATF_TC_BODY(signal2, 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;
-
- 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);
-
- sigemptyset(&intmask);
- sigaddset(&intmask, sigmasked);
- sigprocmask(SIG_BLOCK, &intmask, NULL);
-
- DPRINTF("Before raising %s from child\n", strsignal(sigval));
- FORKEE_ASSERT(raise(sigval) == 0);
-
- DPRINTF("Before raising %s breakpoint from child\n",
- strsignal(sigmasked));
- FORKEE_ASSERT(raise(sigmasked) == 0);
-
- 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_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));
-}
-
ATF_TC(signal3);
ATF_TC_HEAD(signal3, tc)
{
@@ -5256,6 +5290,15 @@
ATF_TP_ADD_TC(tp, traceme_raise9);
ATF_TP_ADD_TC(tp, traceme_raise10);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked1);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked2);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked3);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked4);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked5);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked6);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked7);
+ ATF_TP_ADD_TC(tp, traceme_raisesignal_masked8);
+
ATF_TP_ADD_TC(tp, traceme_crash_trap);
ATF_TP_ADD_TC(tp, traceme_crash_segv);
ATF_TP_ADD_TC(tp, traceme_crash_ill);
@@ -5473,7 +5516,6 @@
ATF_TP_ADD_TC(tp, signal_mask_unrelated);
- ATF_TP_ADD_TC(tp, signal2);
ATF_TP_ADD_TC(tp, signal3);
ATF_TP_ADD_TC_PT_STEP(tp, signal4);
ATF_TP_ADD_TC(tp, signal5);
Home |
Main Index |
Thread Index |
Old Index