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 a new ATF ptrace(2) test: child_attac...
details: https://anonhg.NetBSD.org/src/rev/6a6b495f9d7a
branches: trunk
changeset: 992099:6a6b495f9d7a
user: kamil <kamil%NetBSD.org@localhost>
date: Mon Aug 13 21:36:55 2018 +0000
description:
Add a new ATF ptrace(2) test: child_attach_to_its_stopped_parent
Reuse the body of child_attach_to_its_parent for a test attaching to a
stopped parent.
As a workaround to ATF framework (atf-run), run this test in a subprocess.
The raise(SIGSTOP) call breaks the pipe from atf-run, that is polling
whether a process is in order.
According to code inspection the poll(2) call in safe_poll() receives
EINTR and this tears down the test.
This test passes.
diffstat:
tests/lib/libc/sys/t_ptrace_wait.c | 79 ++++++++++++++++++++++++++++++++-----
1 files changed, 68 insertions(+), 11 deletions(-)
diffs (131 lines):
diff -r 6231397f5636 -r 6a6b495f9d7a tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c Mon Aug 13 20:33:35 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c Mon Aug 13 21:36:55 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.64 2018/07/17 06:13:08 martin Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.65 2018/08/13 21:36:55 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.64 2018/07/17 06:13:08 martin Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.65 2018/08/13 21:36:55 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -1429,14 +1429,8 @@
/// ----------------------------------------------------------------------------
-ATF_TC(child_attach_to_its_parent);
-ATF_TC_HEAD(child_attach_to_its_parent, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Assert that tracer child can PT_ATTACH to its parent");
-}
-
-ATF_TC_BODY(child_attach_to_its_parent, tc)
+static void
+child_attach_to_its_parent(bool stopped)
{
struct msg_fds parent_tracee;
const int exitval_tracer = 5;
@@ -1450,10 +1444,15 @@
SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0);
tracer = atf_utils_fork();
if (tracer == 0) {
-
/* Wait for message from the parent */
CHILD_FROM_PARENT("Message 1", parent_tracee, msg);
+ if (stopped) {
+ DPRINTF("Await for a stopped parent PID %d\n",
+ getppid());
+ await_stopped(getppid());
+ }
+
DPRINTF("Attach to parent PID %d with PT_ATTACH from child\n",
getppid());
FORKEE_ASSERT(ptrace(PT_ATTACH, getppid(), NULL, 0) != -1);
@@ -1477,6 +1476,12 @@
DPRINTF("Wait for the tracer to become ready\n");
PARENT_TO_CHILD("Message 1", parent_tracee, msg);
+
+ if (stopped) {
+ DPRINTF("Stop self PID %d\n", getpid());
+ SYSCALL_REQUIRE(raise(SIGSTOP) != -1);
+ }
+
DPRINTF("Allow the tracer to exit now\n");
PARENT_FROM_CHILD("Message 1", parent_tracee, msg);
@@ -1493,6 +1498,57 @@
msg_close(&parent_tracee);
}
+ATF_TC(child_attach_to_its_parent);
+ATF_TC_HEAD(child_attach_to_its_parent, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Assert that tracer child can PT_ATTACH to its parent");
+}
+
+ATF_TC_BODY(child_attach_to_its_parent, tc)
+{
+
+ child_attach_to_its_parent(false);
+}
+
+ATF_TC(child_attach_to_its_stopped_parent);
+ATF_TC_HEAD(child_attach_to_its_stopped_parent, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Assert that tracer child can PT_ATTACH to its stopped parent");
+}
+
+ATF_TC_BODY(child_attach_to_its_stopped_parent, tc)
+{
+ /*
+ * The ATF framework (atf-run) does not tolerate raise(SIGSTOP), as
+ * this causes a pipe (established from atf-run) to be broken.
+ * atf-run uses this mechanism to monitor whether a test is alive.
+ *
+ * As a workaround spawn this test as a subprocess.
+ */
+
+ const int exitval = 15;
+ pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+ int status;
+#endif
+
+ SYSCALL_REQUIRE((child = fork()) != -1);
+ if (child == 0) {
+ child_attach_to_its_parent(true);
+ _exit(exitval);
+ } else {
+ 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 exited child\n", TWAIT_FNAME);
+ TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+ }
+}
+
/// ----------------------------------------------------------------------------
#if defined(TWAIT_HAVE_PID)
@@ -5616,6 +5672,7 @@
ATF_TP_ADD_TC(tp, parent_attach_to_its_child);
ATF_TP_ADD_TC(tp, child_attach_to_its_parent);
+ ATF_TP_ADD_TC(tp, child_attach_to_its_stopped_parent);
ATF_TP_ADD_TC_HAVE_PID(tp,
tracee_sees_its_original_parent_getppid);
Home |
Main Index |
Thread Index |
Old Index