Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add new tests for combination of wait(2) interfaces with ptr...



details:   https://anonhg.NetBSD.org/src/rev/3c0a965319ef
branches:  trunk
changeset: 818931:3c0a965319ef
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Nov 07 21:09:03 2016 +0000

description:
Add new tests for combination of wait(2) interfaces with ptrace(2)

Move out wait(2) specific tests from t_ptrace and put them to t_ptrace_wait

Add generic code fragments to reuse the same source-code for every member
of the wait(2) family, namely:
 - wait(2)
 - waitpid(2)
 - waitid(2)
 - wait3(2)
 - wait4(2)
 - wait6(2)

Currently in the new test-suite there are the following tests:
 - traceme1
 - traceme2
 - traceme3
 - traceme4
 - attach1

Not all tests are possible to be executed against every wait(2)-like
interface, therefore they will be disabled in such case. Currently this
limits attach1 to waitpid(2), waitid(2), wait4(2), wait6(2), while the
other tests (traceme 1-4) run with all of the interfaces.

The construct of this file is dedicated for addition of new tests in the
close future.

As of now all of the tests pass correctly.

Thanks for Robert Elz for suggestions on improving the code (earlier draft
of this new form).

Sponsored by <The NetBSD Foundation>.

diffstat:

 distrib/sets/lists/debug/mi     |    8 +-
 distrib/sets/lists/tests/mi     |    8 +-
 tests/kernel/Makefile           |    8 +-
 tests/kernel/t_ptrace.c         |  568 +--------------------------------
 tests/kernel/t_ptrace_wait.c    |  694 ++++++++++++++++++++++++++++++++++++++++
 tests/kernel/t_ptrace_wait3.c   |   30 +
 tests/kernel/t_ptrace_wait4.c   |   30 +
 tests/kernel/t_ptrace_wait6.c   |   30 +
 tests/kernel/t_ptrace_waitid.c  |   30 +
 tests/kernel/t_ptrace_waitpid.c |   30 +
 10 files changed, 869 insertions(+), 567 deletions(-)

diffs (truncated from 1541 to 300 lines):

diff -r febbce7654c8 -r 3c0a965319ef distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Mon Nov 07 21:05:38 2016 +0000
+++ b/distrib/sets/lists/debug/mi       Mon Nov 07 21:09:03 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.172 2016/11/06 17:07:50 alnsn Exp $
+# $NetBSD: mi,v 1.173 2016/11/07 21:09:03 kamil Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -1692,6 +1692,12 @@
 ./usr/libdata/debug/usr/tests/kernel/t_pollts.debug                    tests-obsolete          obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/t_posix_fadvise.debug             tests-obsolete          obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/t_ptrace.debug                    tests-kernel-tests      debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_ptrace_wait.debug               tests-kernel-tests      debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_ptrace_wait3.debug              tests-kernel-tests      debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_ptrace_wait4.debug              tests-kernel-tests      debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_ptrace_wait6.debug              tests-kernel-tests      debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_ptrace_waitid.debug             tests-kernel-tests      debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_ptrace_waitpid.debug            tests-kernel-tests      debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/t_pty.debug                       tests-kernel-tests      debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/t_rnd.debug                       tests-kernel-tests      debug,atf,rump
 ./usr/libdata/debug/usr/tests/kernel/t_sigaction.debug                 tests-obsolete          obsolete,compattestfile
diff -r febbce7654c8 -r 3c0a965319ef distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Nov 07 21:05:38 2016 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Nov 07 21:09:03 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.695 2016/11/07 00:54:48 ozaki-r Exp $
+# $NetBSD: mi,v 1.696 2016/11/07 21:09:03 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2127,6 +2127,12 @@
 ./usr/tests/kernel/t_posix_fallocate           tests-obsolete          obsolete
 ./usr/tests/kernel/t_ps_strings                        tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_ptrace                    tests-kernel-tests      compattestfile,atf
+./usr/tests/kernel/t_ptrace_wait               tests-kernel-tests      compattestfile,atf
+./usr/tests/kernel/t_ptrace_wait3              tests-kernel-tests      compattestfile,atf
+./usr/tests/kernel/t_ptrace_wait4              tests-kernel-tests      compattestfile,atf
+./usr/tests/kernel/t_ptrace_wait6              tests-kernel-tests      compattestfile,atf
+./usr/tests/kernel/t_ptrace_waitid             tests-kernel-tests      compattestfile,atf
+./usr/tests/kernel/t_ptrace_waitpid            tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_pty                       tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_rnd                       tests-kernel-tests      atf,rump
 ./usr/tests/kernel/t_sigaction                 tests-obsolete          obsolete
diff -r febbce7654c8 -r 3c0a965319ef tests/kernel/Makefile
--- a/tests/kernel/Makefile     Mon Nov 07 21:05:38 2016 +0000
+++ b/tests/kernel/Makefile     Mon Nov 07 21:09:03 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.40 2016/11/02 12:51:22 kamil Exp $
+# $NetBSD: Makefile,v 1.41 2016/11/07 21:09:03 kamil Exp $
 
 NOMAN=         # defined
 
@@ -10,6 +10,12 @@
 TESTS_C=       t_lock
 TESTS_C+=      t_lockf
 TESTS_C+=      t_ptrace
+TESTS_C+=      t_ptrace_wait
+TESTS_C+=      t_ptrace_wait3
+TESTS_C+=      t_ptrace_wait4
+TESTS_C+=      t_ptrace_wait6
+TESTS_C+=      t_ptrace_waitid
+TESTS_C+=      t_ptrace_waitpid
 TESTS_C+=      t_pty
 TESTS_C+=      t_mqueue
 TESTS_C+=      t_sysv
diff -r febbce7654c8 -r 3c0a965319ef tests/kernel/t_ptrace.c
--- a/tests/kernel/t_ptrace.c   Mon Nov 07 21:05:38 2016 +0000
+++ b/tests/kernel/t_ptrace.c   Mon Nov 07 21:09:03 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace.c,v 1.12 2016/11/06 21:47:53 kamil Exp $      */
+/*     $NetBSD: t_ptrace.c,v 1.13 2016/11/07 21:09:03 kamil Exp $      */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace.c,v 1.12 2016/11/06 21:47:53 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace.c,v 1.13 2016/11/07 21:09:03 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -70,558 +70,6 @@
                     __FILE__, __LINE__, __func__, #x);                         \
 } while (0)
 
-/* This function is currently designed to be run in the main/parent process */
-static void
-await_zombie(pid_t process)
-{
-       struct kinfo_proc2 p;
-       size_t len = sizeof(p);
-
-       const int name[] = {
-               [0] = CTL_KERN,
-               [1] = KERN_PROC2,
-               [2] = KERN_PROC_PID,
-               [3] = process,
-               [4] = sizeof(p),
-               [5] = 1
-       };
-
-       const size_t namelen = __arraycount(name);
-
-       /* Await the process becoming a zombie */
-       while(1) {
-               ATF_REQUIRE(sysctl(name, namelen, &p, &len, NULL, 0) == 0);
-
-               if (p.p_stat == LSZOMB)
-                       break;
-
-               ATF_REQUIRE(usleep(1000) == 0);
-       }
-}
-
-ATF_TC(traceme1);
-ATF_TC_HEAD(traceme1, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify SIGSTOP followed by _exit(2) in a child");
-}
-
-ATF_TC_BODY(traceme1, tc)
-{
-       int status;
-       const int exitval = 5;
-       const int sigval = SIGSTOP;
-       pid_t child, wpid;
-
-       printf("Before forking process PID=%d\n", getpid());
-       ATF_REQUIRE((child = fork()) != -1);
-       if (child == 0) {
-               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               _exit(exitval);
-       }
-       printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
-       printf("Before calling waitpid() for the child\n");
-       wpid = waitpid(child, &status, 0);
-
-       printf("Validating child's PID (expected %d, got %d)\n", child, wpid);
-       ATF_REQUIRE(child == wpid);
-
-       printf("Ensuring that the child has not been exited\n");
-       ATF_REQUIRE(!WIFEXITED(status));
-
-       printf("Ensuring that the child has not been continued\n");
-       ATF_REQUIRE(!WIFCONTINUED(status));
-
-       printf("Ensuring that the child has not been terminated with a "
-           "signal\n");
-       ATF_REQUIRE(!WIFSIGNALED(status));
-
-       printf("Ensuring that the child has been stopped\n");
-       ATF_REQUIRE(WIFSTOPPED(status));
-
-       printf("Verifying that he child has been stopped with the %s signal "
-           "(received %s)\n", sys_signame[sigval],
-           sys_signame[WSTOPSIG(status)]);
-       ATF_REQUIRE(WSTOPSIG(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, 0) != -1);
-
-       printf("Before calling waitpid() for the child\n");
-       wpid = waitpid(child, &status, 0);
-
-       printf("Validating that child's PID is still there\n");
-       ATF_REQUIRE(wpid == child);
-
-       printf("Ensuring that the child has been exited\n");
-       ATF_REQUIRE(WIFEXITED(status));
-
-       printf("Ensuring that the child has not been continued\n");
-       ATF_REQUIRE(!WIFCONTINUED(status));
-
-       printf("Ensuring that the child has not been terminated with a "
-           "signal\n");
-       ATF_REQUIRE(!WIFSIGNALED(status));
-
-       printf("Ensuring that the child has not been stopped\n");
-       ATF_REQUIRE(!WIFSTOPPED(status));
-
-       printf("Verifying that he child has exited with the %d status "
-           "(received %d)\n", exitval, WEXITSTATUS(status));
-       ATF_REQUIRE(WEXITSTATUS(status) == exitval);
-
-       printf("Before calling waitpid() for the exited child\n");
-       wpid = waitpid(child, &status, 0);
-
-       printf("Validating that child's PID no longer exists\n");
-       ATF_REQUIRE(wpid == -1);
-
-       printf("Validating that errno is set to %s (got %s)\n",
-           strerror(ECHILD), strerror(errno));
-       ATF_REQUIRE(errno == ECHILD);
-}
-
-ATF_TC(traceme2);
-ATF_TC_HEAD(traceme2, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify SIGSTOP followed by _exit(2) in a child");
-}
-
-static int traceme2_caught = 0;
-
-static void
-traceme2_sighandler(int sig)
-{
-       FORKEE_ASSERTX(sig == SIGINT);
-
-       ++traceme2_caught;
-}
-
-ATF_TC_BODY(traceme2, tc)
-{
-       int status;
-       const int exitval = 5;
-       const int sigval = SIGSTOP, sigsent = SIGINT;
-       pid_t child, wpid;
-       struct sigaction sa;
-
-       printf("Before forking process PID=%d\n", getpid());
-       ATF_REQUIRE((child = fork()) != -1);
-       if (child == 0) {
-               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-               sa.sa_handler = traceme2_sighandler;
-               sa.sa_flags = SA_SIGINFO;
-               sigemptyset(&sa.sa_mask);
-
-               FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1);
-
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               FORKEE_ASSERTX(traceme2_caught == 1);
-
-               _exit(exitval);
-       }
-       printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
-       printf("Before calling waitpid() for the child\n");
-       wpid = waitpid(child, &status, 0);
-
-       printf("Validating child's PID (expected %d, got %d)\n", child, wpid);
-       ATF_REQUIRE(child == wpid);
-
-       printf("Ensuring that the child has not been exited\n");
-       ATF_REQUIRE(!WIFEXITED(status));
-
-       printf("Ensuring that the child has not been continued\n");
-       ATF_REQUIRE(!WIFCONTINUED(status));
-
-       printf("Ensuring that the child has not been terminated with a "
-           "signal\n");
-       ATF_REQUIRE(!WIFSIGNALED(status));
-
-       printf("Ensuring that the child has been stopped\n");
-       ATF_REQUIRE(WIFSTOPPED(status));
-
-       printf("Verifying that he child has been stopped with the %s signal "
-           "(received %s)\n", sys_signame[sigval],
-           sys_signame[WSTOPSIG(status)]);
-       ATF_REQUIRE(WSTOPSIG(status) == sigval);
-
-       printf("Before resuming the child process where it left off and with "
-           "signal %s to be sent\n", sys_signame[sigsent]);
-       ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
-
-       printf("Before calling waitpid() for the child\n");
-       wpid = waitpid(child, &status, 0);
-
-       printf("Validating that child's PID is still there\n");
-       ATF_REQUIRE(wpid == child);
-
-       printf("Ensuring that the child has been exited\n");
-       ATF_REQUIRE(WIFEXITED(status));
-
-       printf("Ensuring that the child has not been continued\n");
-       ATF_REQUIRE(!WIFCONTINUED(status));
-
-       printf("Ensuring that the child has not been terminated with a "
-           "signal\n");
-       ATF_REQUIRE(!WIFSIGNALED(status));
-
-       printf("Ensuring that the child has not been stopped\n");
-       ATF_REQUIRE(!WIFSTOPPED(status));
-
-       printf("Verifying that he child has exited with the %d status "
-           "(received %d)\n", exitval, WEXITSTATUS(status));
-       ATF_REQUIRE(WEXITSTATUS(status) == exitval);
-
-       printf("Before calling waitpid() for the exited child\n");



Home | Main Index | Thread Index | Old Index