Source-Changes-HG archive

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

[src/trunk]: src/tests/kernel Merge kernel/t_ptrace_wait with kernel/arch/x86...



details:   https://anonhg.NetBSD.org/src/rev/e4507e4033a5
branches:  trunk
changeset: 822710:e4507e4033a5
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Apr 02 00:29:07 2017 +0000

description:
Merge kernel/t_ptrace_wait with kernel/arch/x86/t_ptrace_wait

This aims to remove MD-specific tests files for ptrace(2).

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/kernel/t_ptrace_wait.c     |     9 +-
 tests/kernel/t_ptrace_x86_wait.h |  1983 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1990 insertions(+), 2 deletions(-)

diffs (truncated from 2030 to 300 lines):

diff -r 6ecbe89bfd2a -r e4507e4033a5 tests/kernel/t_ptrace_wait.c
--- a/tests/kernel/t_ptrace_wait.c      Sun Apr 02 00:06:09 2017 +0000
+++ b/tests/kernel/t_ptrace_wait.c      Sun Apr 02 00:29:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.85 2017/04/02 00:03:40 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.86 2017/04/02 00:29:07 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.85 2017/04/02 00:03:40 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.86 2017/04/02 00:29:07 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -42,6 +42,7 @@
 #include <err.h>
 #include <errno.h>
 #include <lwp.h>
+#include <sched.h>
 #include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -7445,6 +7446,8 @@
        TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
 
+#include "t_ptrace_x86_wait.h"
+
 ATF_TP_ADD_TCS(tp)
 {
        setvbuf(stdout, NULL, _IONBF, 0);
@@ -7577,5 +7580,7 @@
 
        ATF_TP_ADD_TC(tp, syscallemu1);
 
+       ATF_TP_ADD_TCS_PTRACE_WAIT_X86();
+
        return atf_no_error();
 }
diff -r 6ecbe89bfd2a -r e4507e4033a5 tests/kernel/t_ptrace_x86_wait.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/t_ptrace_x86_wait.h  Sun Apr 02 00:29:07 2017 +0000
@@ -0,0 +1,1983 @@
+/*     $NetBSD: t_ptrace_x86_wait.h,v 1.1 2017/04/02 00:29:07 kamil Exp $      */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if defined(__i386__) || defined(__x86_64__)
+union u {
+       unsigned long raw;
+       struct {
+               unsigned long local_dr0_breakpoint : 1;         /* 0 */
+               unsigned long global_dr0_breakpoint : 1;        /* 1 */
+               unsigned long local_dr1_breakpoint : 1;         /* 2 */
+               unsigned long global_dr1_breakpoint : 1;        /* 3 */
+               unsigned long local_dr2_breakpoint : 1;         /* 4 */
+               unsigned long global_dr2_breakpoint : 1;        /* 5 */
+               unsigned long local_dr3_breakpoint : 1;         /* 6 */
+               unsigned long global_dr3_breakpoint : 1;        /* 7 */
+               unsigned long local_exact_breakpt : 1;          /* 8 */
+               unsigned long global_exact_breakpt : 1;         /* 9 */
+               unsigned long reserved_10 : 1;                  /* 10 */
+               unsigned long rest_trans_memory : 1;            /* 11 */
+               unsigned long reserved_12 : 1;                  /* 12 */
+               unsigned long general_detect_enable : 1;        /* 13 */
+               unsigned long reserved_14 : 1;                  /* 14 */
+               unsigned long reserved_15 : 1;                  /* 15 */
+               unsigned long condition_dr0 : 2;                /* 16-17 */
+               unsigned long len_dr0 : 2;                      /* 18-19 */
+               unsigned long condition_dr1 : 2;                /* 20-21 */
+               unsigned long len_dr1 : 2;                      /* 22-23 */
+               unsigned long condition_dr2 : 2;                /* 24-25 */
+               unsigned long len_dr2 : 2;                      /* 26-27 */
+               unsigned long condition_dr3 : 2;                /* 28-29 */
+               unsigned long len_dr3 : 2;                      /* 30-31 */
+       } bits;
+};
+
+ATF_TC(dbregs_print);
+ATF_TC_HEAD(dbregs_print, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify plain PT_GETDBREGS with printing Debug Registers");
+}
+
+ATF_TC_BODY(dbregs_print, tc)
+{
+       const int exitval = 5;
+       const int sigval = SIGSTOP;
+       pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+       int status;
+#endif
+       struct dbreg r;
+       size_t i;
+
+       printf("Before forking process PID=%d\n", getpid());
+       ATF_REQUIRE((child = fork()) != -1);
+       if (child == 0) {
+               printf("Before calling PT_TRACE_ME from child %d\n", getpid());
+               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+               printf("Before raising %s from child\n", strsignal(sigval));
+               FORKEE_ASSERT(raise(sigval) == 0);
+
+               printf("Before exiting of the child process\n");
+               _exit(exitval);
+       }
+       printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       validate_status_stopped(status, sigval);        
+
+       printf("Call GETDBREGS for the child process\n");
+       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r, 0) != -1);
+
+       printf("State of the debug registers:\n");
+       for (i = 0; i < __arraycount(r.dr); i++)
+               printf("r[%zu]=%" PRIxREGISTER "\n", i, r.dr[i]);
+
+       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 %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       validate_status_exited(status, exitval);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+
+
+enum dbreg_preserve_mode {
+       dbreg_preserve_mode_none,
+       dbreg_preserve_mode_yield,
+       dbreg_preserve_mode_continued
+};
+
+static void
+dbreg_preserve(int reg, enum dbreg_preserve_mode mode)
+{
+       const int exitval = 5;
+       const int sigval = SIGSTOP;
+       pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+       int status;
+#endif
+       struct dbreg r1;
+       struct dbreg r2;
+       size_t i;
+       int watchme;
+
+       printf("Before forking process PID=%d\n", getpid());
+       ATF_REQUIRE((child = fork()) != -1);
+       if (child == 0) {
+               printf("Before calling PT_TRACE_ME from child %d\n", getpid());
+               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+               printf("Before raising %s from child\n", strsignal(sigval));
+               FORKEE_ASSERT(raise(sigval) == 0);
+
+               if (mode == dbreg_preserve_mode_continued) {
+                       printf("Before raising %s from child\n",
+                              strsignal(sigval));
+                       FORKEE_ASSERT(raise(sigval) == 0);
+               }
+
+               printf("Before exiting of the child process\n");
+               _exit(exitval);
+       }
+       printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       validate_status_stopped(status, sigval);
+
+       printf("Call GETDBREGS for the child process (r1)\n");
+       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r1, 0) != -1);
+
+       printf("State of the debug registers (r1):\n");
+       for (i = 0; i < __arraycount(r1.dr); i++)
+               printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]);
+
+       r1.dr[reg] = (long)(intptr_t)&watchme;
+       printf("Set DR0 (r1.dr[%d]) to new value %" PRIxREGISTER "\n",
+           reg, r1.dr[reg]);
+
+       printf("New state of the debug registers (r1):\n");
+       for (i = 0; i < __arraycount(r1.dr); i++)
+               printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]);
+
+       printf("Call SETDBREGS for the child process (r1)\n");
+       ATF_REQUIRE(ptrace(PT_SETDBREGS, child, &r1, 0) != -1);
+
+       switch (mode) {
+       case dbreg_preserve_mode_none:
+               break;
+       case dbreg_preserve_mode_yield:
+               printf("Yields a processor voluntarily and gives other "
+                      "threads a chance to run without waiting for an "
+                      "involuntary preemptive switch\n");
+               sched_yield();
+               break;
+       case dbreg_preserve_mode_continued:
+               printf("Call CONTINUE for the child process\n");
+               ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+               printf("Before calling %s() for the child\n", TWAIT_FNAME);
+               TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+               validate_status_stopped(status, sigval);
+               break;
+       }
+
+       printf("Call GETDBREGS for the child process (r2)\n");
+       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
+
+       printf("Assert that (r1) and (r2) are the same\n");
+       ATF_REQUIRE(memcmp(&r1, &r2, sizeof(r1)) == 0);
+
+       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 %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+       validate_status_exited(status, exitval);
+
+       printf("Before calling %s() for the child\n", TWAIT_FNAME);
+       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+
+
+ATF_TC(dbregs_preserve_dr0);
+ATF_TC_HEAD(dbregs_preserve_dr0, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that setting DR0 is preserved across ptrace(2) calls");
+}
+
+ATF_TC_BODY(dbregs_preserve_dr0, tc)
+{
+       dbreg_preserve(0, dbreg_preserve_mode_none);
+}
+
+ATF_TC(dbregs_preserve_dr1);
+ATF_TC_HEAD(dbregs_preserve_dr1, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that setting DR1 is preserved across ptrace(2) calls");
+}
+
+ATF_TC_BODY(dbregs_preserve_dr1, tc)
+{
+       dbreg_preserve(1, dbreg_preserve_mode_none);
+}
+
+ATF_TC(dbregs_preserve_dr2);
+ATF_TC_HEAD(dbregs_preserve_dr2, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "Verify that setting DR2 is preserved across ptrace(2) calls");
+}
+
+ATF_TC_BODY(dbregs_preserve_dr2, tc)
+{



Home | Main Index | Thread Index | Old Index