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 new ATF ptrace(2) tests for posix_spa...
details: https://anonhg.NetBSD.org/src/rev/0ee28234c80a
branches: trunk
changeset: 457133:0ee28234c80a
user: kamil <kamil%NetBSD.org@localhost>
date: Wed Jun 12 17:07:11 2019 +0000
description:
Add new ATF ptrace(2) tests for posix_spawn, reusing tests for fork/vfork
New tests:
- posix_spawn_detach_spawner
- posix_spawn_kill_spawner
- posix_spawn_singalmasked
- posix_spawn_singalignored
All test pass.
diffstat:
tests/lib/libc/sys/t_ptrace_wait.c | 192 +++++++++++++++++++++---------------
1 files changed, 113 insertions(+), 79 deletions(-)
diffs (truncated from 410 to 300 lines):
diff -r 3d8679d8ca49 -r 0ee28234c80a tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c Wed Jun 12 17:04:35 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c Wed Jun 12 17:07:11 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.125 2019/06/11 23:30:05 kamil Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.126 2019/06/12 17:07:11 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.125 2019/06/11 23:30:05 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.126 2019/06/12 17:07:11 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -3195,7 +3195,7 @@
{ \
atf_tc_set_md_var(tc, "descr", "Verify " fun "() " \
"called with 0%s%s%s%s in EVENT_MASK", \
- tspawn ? "|PTRACE_FORK" : "", \
+ tspawn ? "|PTRACE_POSIX_SPAWN" : "", \
tfork ? "|PTRACE_FORK" : "", \
tvfork ? "|PTRACE_VFORK" : "", \
tvforkdone ? "|PTRACE_VFORK_DONE" : ""); \
@@ -3282,11 +3282,10 @@
#if defined(TWAIT_HAVE_PID)
static void
-fork_detach_forker_body(bool detachfork, bool detachvfork,
- bool detachvforkdone, bool kill_process)
+fork_detach_forker_body(const char *fn, bool kill_process)
{
const int exitval = 5;
- const int exitval2 = 15;
+ const int exitval2 = 0; /* Matches exit value from /bin/echo */
const int sigval = SIGSTOP;
pid_t child, child2 = 0, wpid;
#if defined(TWAIT_HAVE_STATUS)
@@ -3297,17 +3296,9 @@
ptrace_event_t event;
const int elen = sizeof(event);
- pid_t (*fn)(void);
int op;
- ATF_REQUIRE((detachfork && !detachvfork && !detachvforkdone) ||
- (!detachfork && detachvfork && !detachvforkdone) ||
- (!detachfork && !detachvfork && detachvforkdone));
-
- if (detachfork)
- fn = fork;
- else
- fn = vfork;
+ char * const arg[] = { __UNCONST("/bin/echo"), NULL };
DPRINTF("Before forking process PID=%d\n", getpid());
SYSCALL_REQUIRE((child = fork()) != -1);
@@ -3318,10 +3309,19 @@
DPRINTF("Before raising %s from child\n", strsignal(sigval));
FORKEE_ASSERT(raise(sigval) == 0);
- FORKEE_ASSERT((child2 = (fn)()) != -1);
-
- if (child2 == 0)
- _exit(exitval2);
+ if (strcmp(fn, "spawn") == 0) {
+ FORKEE_ASSERT_EQ(posix_spawn(&child2,
+ arg[0], NULL, NULL, arg, NULL), 0);
+ } else {
+ if (strcmp(fn, "fork") == 0) {
+ FORKEE_ASSERT((child2 = fork()) != -1);
+ } else {
+ FORKEE_ASSERT((child2 = vfork()) != -1);
+ }
+
+ if (child2 == 0)
+ _exit(exitval2);
+ }
FORKEE_REQUIRE_SUCCESS
(wpid = TWAIT_GENERIC(child2, &status, 0), child2);
@@ -3339,7 +3339,8 @@
validate_status_stopped(status, sigval);
DPRINTF("Set EVENT_MASK for the child %d\n", child);
- event.pe_set_event = PTRACE_FORK | PTRACE_VFORK | PTRACE_VFORK_DONE;
+ event.pe_set_event = PTRACE_POSIX_SPAWN | PTRACE_FORK | PTRACE_VFORK
+ | PTRACE_VFORK_DONE;
SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
DPRINTF("Before resuming the child process where it left off and "
@@ -3353,13 +3354,21 @@
SYSCALL_REQUIRE(
ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
- op = (fn == fork) ? PTRACE_FORK : PTRACE_VFORK;
+
+ if (strcmp(fn, "spawn") == 0)
+ op = PTRACE_POSIX_SPAWN;
+ else if (strcmp(fn, "fork") == 0)
+ op = PTRACE_FORK;
+ else
+ op = PTRACE_VFORK;
+
ATF_REQUIRE_EQ(state.pe_report_event & op, op);
child2 = state.pe_other_pid;
DPRINTF("Reported ptrace event with forkee %d\n", child2);
- if (detachfork || detachvfork)
+ if (strcmp(fn, "spawn") == 0 || strcmp(fn, "fork") == 0 ||
+ strcmp(fn, "vfork") == 0)
op = kill_process ? PT_KILL : PT_DETACH;
else
op = PT_CONTINUE;
@@ -3373,7 +3382,13 @@
SYSCALL_REQUIRE(
ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
- op = (fn == fork) ? PTRACE_FORK : PTRACE_VFORK;
+ if (strcmp(fn, "spawn") == 0)
+ op = PTRACE_POSIX_SPAWN;
+ else if (strcmp(fn, "fork") == 0)
+ op = PTRACE_FORK;
+ else
+ op = PTRACE_VFORK;
+
ATF_REQUIRE_EQ(state.pe_report_event & op, op);
ATF_REQUIRE_EQ(state.pe_other_pid, child);
@@ -3382,7 +3397,7 @@
SYSCALL_REQUIRE(
ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
- if (detachvforkdone && fn == vfork) {
+ if (strcmp(fn, "vforkdone") == 0) {
DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
child);
TWAIT_REQUIRE_SUCCESS(
@@ -3429,33 +3444,32 @@
TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
}
-#define FORK_DETACH_FORKER(name,detfork,detvfork,detvforkdone,kprocess) \
+#define FORK_DETACH_FORKER(name,event,kprocess) \
ATF_TC(name); \
ATF_TC_HEAD(name, tc) \
{ \
- atf_tc_set_md_var(tc, "descr", "Verify %s %s%s%s", \
- kprocess ? "killed" : "detached", \
- detfork ? "forker" : "", \
- detvfork ? "vforker" : "", \
- detvforkdone ? "vforker done" : ""); \
+ atf_tc_set_md_var(tc, "descr", "Verify %s " event, \
+ kprocess ? "killed" : "detached"); \
} \
\
ATF_TC_BODY(name, tc) \
{ \
\
- fork_detach_forker_body(detfork, detvfork, detvforkdone, \
- kprocess); \
+ fork_detach_forker_body(event, kprocess); \
}
-FORK_DETACH_FORKER(fork_detach_forker, true, false, false, false)
+FORK_DETACH_FORKER(posix_spawn_detach_spawner, "spawn", false)
+FORK_DETACH_FORKER(fork_detach_forker, "fork", false)
#if TEST_VFORK_ENABLED
-FORK_DETACH_FORKER(vfork_detach_vforker, false, true, false, false)
-FORK_DETACH_FORKER(vfork_detach_vforkerdone, false, false, true, false)
-#endif
-FORK_DETACH_FORKER(fork_kill_forker, true, false, false, true)
+FORK_DETACH_FORKER(vfork_detach_vforker, "vfork", false)
+FORK_DETACH_FORKER(vfork_detach_vforkerdone, "vforkdone", false)
+#endif
+
+FORK_DETACH_FORKER(posix_spawn_kill_spawner, "spawn", true)
+FORK_DETACH_FORKER(fork_kill_forker, "fork", true)
#if TEST_VFORK_ENABLED
-FORK_DETACH_FORKER(vfork_kill_vforker, false, true, false, true)
-FORK_DETACH_FORKER(vfork_kill_vforkerdone, false, false, true, true)
+FORK_DETACH_FORKER(vfork_kill_vforker, "vfork", true)
+FORK_DETACH_FORKER(vfork_kill_vforkerdone, "vforkdone", true)
#endif
#endif
@@ -5694,11 +5708,10 @@
#if defined(TWAIT_HAVE_PID)
static void
-fork2_body(bool trackfork, bool trackvfork, bool trackvforkdone, bool masked,
- bool ignored)
+fork2_body(const char *fn, bool masked, bool ignored)
{
const int exitval = 5;
- const int exitval2 = 15;
+ const int exitval2 = 0; /* Match exit status from /bin/echo */
const int sigval = SIGSTOP;
pid_t child, child2 = 0, wpid;
#if defined(TWAIT_HAVE_STATUS)
@@ -5708,7 +5721,6 @@
const int slen = sizeof(state);
ptrace_event_t event;
const int elen = sizeof(event);
- pid_t (*fn)(void);
struct sigaction sa;
struct ptrace_siginfo info;
sigset_t intmask;
@@ -5720,10 +5732,7 @@
ki_sigset_t kp_sigmask;
ki_sigset_t kp_sigignore;
- if (trackfork)
- fn = fork;
- if (trackvfork || trackvforkdone)
- fn = vfork;
+ char * const arg[] = { __UNCONST("/bin/echo"), NULL };
DPRINTF("Before forking process PID=%d\n", getpid());
SYSCALL_REQUIRE((child = fork()) != -1);
@@ -5747,10 +5756,18 @@
DPRINTF("Before raising %s from child\n", strsignal(sigval));
FORKEE_ASSERT(raise(sigval) == 0);
- FORKEE_ASSERT((child2 = (fn)()) != -1);
-
- if (child2 == 0)
- _exit(exitval2);
+ if (strcmp(fn, "spawn") == 0) {
+ FORKEE_ASSERT_EQ(posix_spawn(&child2,
+ arg[0], NULL, NULL, arg, NULL), 0);
+ } else {
+ if (strcmp(fn, "fork") == 0) {
+ FORKEE_ASSERT((child2 = fork()) != -1);
+ } else {
+ FORKEE_ASSERT((child2 = vfork()) != -1);
+ }
+ if (child2 == 0)
+ _exit(exitval2);
+ }
FORKEE_REQUIRE_SUCCESS
(wpid = TWAIT_GENERIC(child2, &status, 0), child2);
@@ -5790,16 +5807,19 @@
if (ignored)
kp_sigignore = kp.p_sigignore;
- DPRINTF("Set 0%s%s%s in EVENT_MASK for the child %d\n",
- trackfork ? "|PTRACE_FORK" : "",
- trackvfork ? "|PTRACE_VFORK" : "",
- trackvforkdone ? "|PTRACE_VFORK_DONE" : "", child);
+ DPRINTF("Set 0%s%s%s%s in EVENT_MASK for the child %d\n",
+ strcmp(fn, "spawn") == 0 ? "|PTRACE_POSIX_SPAWN" : "",
+ strcmp(fn, "fork") == 0 ? "|PTRACE_FORK" : "",
+ strcmp(fn, "vfork") == 0 ? "|PTRACE_VFORK" : "",
+ strcmp(fn, "vforkdone") == 0 ? "|PTRACE_VFORK_DONE" : "", child);
event.pe_set_event = 0;
- if (trackfork)
+ if (strcmp(fn, "spawn") == 0)
+ event.pe_set_event |= PTRACE_POSIX_SPAWN;
+ if (strcmp(fn, "fork") == 0)
event.pe_set_event |= PTRACE_FORK;
- if (trackvfork)
+ if (strcmp(fn, "vfork") == 0)
event.pe_set_event |= PTRACE_VFORK;
- if (trackvforkdone)
+ if (strcmp(fn, "vforkdone") == 0)
event.pe_set_event |= PTRACE_VFORK_DONE;
SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
@@ -5807,7 +5827,8 @@
"without signal to be sent\n");
SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
- if (trackfork || trackvfork) {
+ if (strcmp(fn, "spawn") == 0 || strcmp(fn, "fork") == 0 ||
+ strcmp(fn, "vfork") == 0) {
DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
child);
TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
@@ -5853,11 +5874,16 @@
SYSCALL_REQUIRE(
ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
- if (trackfork) {
+ if (strcmp(fn, "spawn") == 0) {
+ ATF_REQUIRE_EQ(
+ state.pe_report_event & PTRACE_POSIX_SPAWN,
+ PTRACE_POSIX_SPAWN);
+ }
+ if (strcmp(fn, "fork") == 0) {
ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK,
PTRACE_FORK);
}
- if (trackvfork) {
+ if (strcmp(fn, "vfork") == 0) {
Home |
Main Index |
Thread Index |
Old Index