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 Deduplicate shared code in dbregs_pres...
details: https://anonhg.NetBSD.org/src/rev/1d4d51a8eee8
branches: trunk
changeset: 352386:1d4d51a8eee8
user: kamil <kamil%NetBSD.org@localhost>
date: Wed Mar 29 23:50:09 2017 +0000
description:
Deduplicate shared code in dbregs_preserve_dr[0123]{,_yield,_continued}
Move common function code into shared subroutine.
While there remove checks for defined(HAVE_DBREGS). All x86 ports offer
debug register accessors.
Sponsored by <The NetBSD Foundation>
diffstat:
tests/kernel/arch/x86/t_ptrace_wait.c | 1050 ++++----------------------------
1 files changed, 148 insertions(+), 902 deletions(-)
diffs (truncated from 1139 to 300 lines):
diff -r a15d05fbcc03 -r 1d4d51a8eee8 tests/kernel/arch/x86/t_ptrace_wait.c
--- a/tests/kernel/arch/x86/t_ptrace_wait.c Wed Mar 29 23:02:43 2017 +0000
+++ b/tests/kernel/arch/x86/t_ptrace_wait.c Wed Mar 29 23:50:09 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.3 2017/02/25 18:18:29 christos Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.4 2017/03/29 23:50:09 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.3 2017/02/25 18:18:29 christos Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.4 2017/03/29 23:50:09 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -85,8 +85,6 @@
} bits;
};
-
-#if defined(HAVE_DBREGS)
ATF_TC(dbregs_print);
ATF_TC_HEAD(dbregs_print, tc)
{
@@ -143,414 +141,16 @@
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_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)
-{
- 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);
-
- 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]);
-
- 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 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));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-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)
-{
- 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);
-
- 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]);
-
- 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 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));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-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)
-{
- 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);
-
- 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[2] = (long)(intptr_t)&watchme;
- printf("Set DR2 (r1.dr[2]) to new value %" PRIxREGISTER "\n",
- r1.dr[2]);
-
- 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 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));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_preserve_dr3);
-ATF_TC_HEAD(dbregs_preserve_dr3, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that setting DR3 is preserved across ptrace(2) calls");
-}
-
-ATF_TC_BODY(dbregs_preserve_dr3, tc)
-{
- 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);
-
- printf("Before exiting of the child process\n");
- _exit(exitval);
- }
Home |
Main Index |
Thread Index |
Old Index