Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/kernel/arch/x86 Eliminate code duplication in the x86 ...
details: https://anonhg.NetBSD.org/src/rev/44205dd47f20
branches: trunk
changeset: 352387:44205dd47f20
user: kamil <kamil%NetBSD.org@localhost>
date: Thu Mar 30 02:17:38 2017 +0000
description:
Eliminate code duplication in the x86 dbregs_dr[0123]_trap_variable* tests
This is work in progress to remove no longer needed code overhead shared
between tests.
Sponsored by <The NetBSD Foundation>
diffstat:
tests/kernel/arch/x86/t_ptrace_wait.c | 4360 +++-----------------------------
1 files changed, 409 insertions(+), 3951 deletions(-)
diffs (truncated from 4561 to 300 lines):
diff -r 1d4d51a8eee8 -r 44205dd47f20 tests/kernel/arch/x86/t_ptrace_wait.c
--- a/tests/kernel/arch/x86/t_ptrace_wait.c Wed Mar 29 23:50:09 2017 +0000
+++ b/tests/kernel/arch/x86/t_ptrace_wait.c Thu Mar 30 02:17:38 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.4 2017/03/29 23:50:09 kamil Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.5 2017/03/30 02:17:38 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.4 2017/03/29 23:50:09 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.5 2017/03/30 02:17:38 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -42,6 +42,7 @@
#include <lwp.h>
#include <sched.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -399,370 +400,9 @@
dbreg_preserve(3, dbreg_preserve_mode_continued);
}
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr0_trap_variable_writeonly_byte);
-ATF_TC_HEAD(dbregs_dr0_trap_variable_writeonly_byte, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that setting trap with DR0 triggers SIGTRAP "
- "(break on data writes only and 1 byte mode)");
-}
-
-ATF_TC_BODY(dbregs_dr0_trap_variable_writeonly_byte, tc)
-{
- const int exitval = 5;
- const int sigval = SIGSTOP;
- pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
-#endif
- struct dbreg r1;
- size_t i;
- volatile int watchme;
- union u dr7;
-
- struct ptrace_siginfo info;
- memset(&info, 0, sizeof(info));
-
- dr7.raw = 0;
- dr7.bits.global_dr0_breakpoint = 1;
- dr7.bits.condition_dr0 = 1; /* 0b01 -- break on data write only */
- dr7.bits.len_dr0 = 0; /* 0b00 -- 1 byte */
-
- 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);
-
- watchme = 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 (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[0] = (long)(intptr_t)&watchme;
- printf("Set DR0 (r1.dr[0]) to new value %" PRIxREGISTER "\n",
- r1.dr[0]);
-
- r1.dr[7] = dr7.raw;
- printf("Set DR7 (r1.dr[7]) to new value %" PRIxREGISTER "\n",
- r1.dr[7]);
-
- 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);
-
- 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, SIGTRAP);
-
- printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
- ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
-
- printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
- printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
- info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
- info.psi_siginfo.si_errno);
-
- printf("Before checking siginfo_t\n");
- ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
- ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);
-
- 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);
-
- 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));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr1_trap_variable_writeonly_byte);
-ATF_TC_HEAD(dbregs_dr1_trap_variable_writeonly_byte, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that setting trap with DR1 triggers SIGTRAP "
- "(break on data writes only and 1 byte mode)");
-}
-
-ATF_TC_BODY(dbregs_dr1_trap_variable_writeonly_byte, tc)
-{
- const int exitval = 5;
- const int sigval = SIGSTOP;
- pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
-#endif
- struct dbreg r1;
- size_t i;
- volatile int watchme;
- union u dr7;
-
- struct ptrace_siginfo info;
- memset(&info, 0, sizeof(info));
-
- dr7.raw = 0;
- dr7.bits.global_dr1_breakpoint = 1;
- dr7.bits.condition_dr1 = 1; /* 0b01 -- break on data write only */
- dr7.bits.len_dr1 = 0; /* 0b00 -- 1 byte */
-
- 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);
-
- watchme = 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 (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[1] = (long)(intptr_t)&watchme;
- printf("Set DR1 (r1.dr[1]) to new value %" PRIxREGISTER "\n",
- r1.dr[1]);
-
- r1.dr[7] = dr7.raw;
- printf("Set DR7 (r1.dr[7]) to new value %" PRIxREGISTER "\n",
- r1.dr[7]);
-
- 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);
-
- 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, SIGTRAP);
-
- printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
- ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
-
- printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
- printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
- info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
- info.psi_siginfo.si_errno);
-
- printf("Before checking siginfo_t\n");
- ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
- ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);
-
- 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);
-
- 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));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr2_trap_variable_writeonly_byte);
-ATF_TC_HEAD(dbregs_dr2_trap_variable_writeonly_byte, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that setting trap with DR2 triggers SIGTRAP "
- "(break on data writes only and 1 byte mode)");
-}
-
-ATF_TC_BODY(dbregs_dr2_trap_variable_writeonly_byte, tc)
-{
- const int exitval = 5;
- const int sigval = SIGSTOP;
- pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
-#endif
- struct dbreg r1;
- size_t i;
- volatile int watchme;
- union u dr7;
-
- struct ptrace_siginfo info;
- memset(&info, 0, sizeof(info));
-
- dr7.raw = 0;
- dr7.bits.global_dr2_breakpoint = 1;
- dr7.bits.condition_dr2 = 1; /* 0b01 -- break on data write only */
- dr7.bits.len_dr2 = 0; /* 0b00 -- 1 byte */
-
- 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());
Home |
Main Index |
Thread Index |
Old Index