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 posix_spawn(3) ATF tests in t_ptrace_...



details:   https://anonhg.NetBSD.org/src/rev/ac39a5319182
branches:  trunk
changeset: 451888:ac39a5319182
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Jun 10 22:16:06 2019 +0000

description:
Add posix_spawn(3) ATF tests in t_ptrace_wait*

New tests verify whether forking process reports forking events to a
debugger.

Right now there is no support in the kernel for this system.

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  85 ++++++++++++++++++++++++++-----------
 1 files changed, 59 insertions(+), 26 deletions(-)

diffs (160 lines):

diff -r 1c21ac0006e8 -r ac39a5319182 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Mon Jun 10 21:18:04 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Mon Jun 10 22:16:06 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.123 2019/06/10 21:18:04 kamil Exp $        */
+/*     $NetBSD: t_ptrace_wait.c,v 1.124 2019/06/10 22:16:06 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.123 2019/06/10 21:18:04 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.124 2019/06/10 22:16:06 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -46,6 +46,7 @@
 #include <pthread.h>
 #include <sched.h>
 #include <signal.h>
+#include <spawn.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -2985,7 +2986,7 @@
 /// ----------------------------------------------------------------------------
 
 static void
-fork_body(pid_t (*fn)(void), bool trackfork, bool trackvfork,
+fork_body(pid_t (*fn)(void), bool spawn, bool trackfork, bool trackvfork,
     bool trackvforkdone)
 {
        const int exitval = 5;
@@ -3000,6 +3001,11 @@
        ptrace_event_t event;
        const int elen = sizeof(event);
 
+       char * const arg[] = { __UNCONST("/bin/echo"), NULL };
+
+       if (spawn)
+               atf_tc_skip("posix_spawn() is not supported");
+
        DPRINTF("Before forking process PID=%d\n", getpid());
        SYSCALL_REQUIRE((child = fork()) != -1);
        if (child == 0) {
@@ -3009,11 +3015,15 @@
                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 (spawn) {
+                       FORKEE_ASSERT_EQ(posix_spawn(&child2,
+                           arg[0], NULL, NULL, arg, NULL), 0);
+               } else if (fn == fork || fn == vfork) {
+                       FORKEE_ASSERT((child2 = (fn)()) != -1);
+
+                       if (child2 == 0)
+                               _exit(exitval2);
+               }
                FORKEE_REQUIRE_SUCCESS
                    (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
 
@@ -3158,7 +3168,7 @@
        TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
 
-#define FORK_TEST(name,fun,tfork,tvfork,tvforkdone)                    \
+#define FORK_TEST(name,fun,spawn,tfork,tvfork,tvforkdone)              \
 ATF_TC(name);                                                          \
 ATF_TC_HEAD(name, tc)                                                  \
 {                                                                      \
@@ -3172,35 +3182,49 @@
 ATF_TC_BODY(name, tc)                                                  \
 {                                                                      \
                                                                        \
-       fork_body(fun, tfork, tvfork, tvforkdone);                      \
+       fork_body(fun, spawn, tfork, tvfork, tvforkdone);               \
 }
 
-FORK_TEST(fork1, fork, false, false, false)
+FORK_TEST(fork1, fork, false, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(fork2, fork, true, false, false)
-FORK_TEST(fork3, fork, false, true, false)
-FORK_TEST(fork4, fork, true, true, false)
+FORK_TEST(fork2, fork, false, true, false, false)
+FORK_TEST(fork3, fork, false, false, true, false)
+FORK_TEST(fork4, fork, false, true, true, false)
 #endif
-FORK_TEST(fork5, fork, false, false, true)
+FORK_TEST(fork5, fork, false, false, false, true)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(fork6, fork, true, false, true)
-FORK_TEST(fork7, fork, false, true, true)
-FORK_TEST(fork8, fork, true, true, true)
+FORK_TEST(fork6, fork, false, true, false, true)
+FORK_TEST(fork7, fork, false, false, true, true)
+FORK_TEST(fork8, fork, false, true, true, true)
 #endif
 
 #if TEST_VFORK_ENABLED
-FORK_TEST(vfork1, vfork, false, false, false)
+FORK_TEST(vfork1, vfork, false, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(vfork2, vfork, true, false, false)
-FORK_TEST(vfork3, vfork, false, true, false)
-FORK_TEST(vfork4, vfork, true, true, false)
+FORK_TEST(vfork2, vfork, false, true, false, false)
+FORK_TEST(vfork3, vfork, false, false, true, false)
+FORK_TEST(vfork4, vfork, false, true, true, false)
+#endif
+FORK_TEST(vfork5, vfork, false, false, false, true)
+#if defined(TWAIT_HAVE_PID)
+FORK_TEST(vfork6, vfork, false, true, false, true)
+FORK_TEST(vfork7, vfork, false, false, true, true)
+FORK_TEST(vfork8, vfork, false, true, true, true)
+#endif
 #endif
-FORK_TEST(vfork5, vfork, false, false, true)
+
+/* It's ugly, but passing posix_spawn as 'bool' avoids function pointer cast */
+FORK_TEST(posix_spawn1, fork, true, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(vfork6, vfork, true, false, true)
-FORK_TEST(vfork7, vfork, false, true, true)
-FORK_TEST(vfork8, vfork, true, true, true)
+FORK_TEST(posix_spawn2, fork, true, true, false, false)
+FORK_TEST(posix_spawn3, fork, true, false, true, false)
+FORK_TEST(posix_spawn4, fork, true, true, true, false)
 #endif
+FORK_TEST(posix_spawn5, fork, true, false, false, true)
+#if defined(TWAIT_HAVE_PID)
+FORK_TEST(posix_spawn6, fork, true, true, false, true)
+FORK_TEST(posix_spawn7, fork, true, false, true, true)
+FORK_TEST(posix_spawn8, fork, true, true, true, true)
 #endif
 
 /// ----------------------------------------------------------------------------
@@ -7733,6 +7757,15 @@
        ATF_TP_ADD_TC_HAVE_PID(tp, vfork8);
 #endif
 
+       ATF_TP_ADD_TC(tp, posix_spawn1);
+       ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn2);
+       ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn3);
+       ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn4);
+       ATF_TP_ADD_TC(tp, posix_spawn5);
+       ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn6);
+       ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn7);
+       ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn8);
+
        ATF_TP_ADD_TC_HAVE_PID(tp, fork_detach_forker);
 #if TEST_VFORK_ENABLED
        ATF_TP_ADD_TC_HAVE_PID(tp, vfork_detach_vforker);



Home | Main Index | Thread Index | Old Index