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 Refactor GPR and FPR tests in t_ptrace_wa...
details: https://anonhg.NetBSD.org/src/rev/61165113c32b
branches: trunk
changeset: 448724:61165113c32b
user: kamil <kamil%NetBSD.org@localhost>
date: Thu Feb 07 23:03:33 2019 +0000
description:
Refactor GPR and FPR tests in t_ptrace_wait* tests
This change deduplicates the code and puts all the test into shared
function body.
No functional change except ranaming tests regs* to access_regs* and
fpregs* to access_fpregs*.
diffstat:
tests/lib/libc/sys/t_ptrace_wait.c | 434 +++++++-----------------------------
1 files changed, 88 insertions(+), 346 deletions(-)
diffs (truncated from 497 to 300 lines):
diff -r 487d52c0cd83 -r 61165113c32b tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 07 22:22:31 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 07 23:03:33 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.71 2019/02/07 00:24:59 kamil Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.72 2019/02/07 23:03:33 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.71 2019/02/07 00:24:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.72 2019/02/07 23:03:33 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -2613,15 +2613,9 @@
/// ----------------------------------------------------------------------------
-#if defined(HAVE_GPREGS)
-ATF_TC(regs1);
-ATF_TC_HEAD(regs1, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify plain PT_GETREGS call without further steps");
-}
-
-ATF_TC_BODY(regs1, tc)
+#if defined(HAVE_GPREGS) || defined(HAVE_FPGPREGS)
+static void
+access_regs(const char *regset, const char *aux)
{
const int exitval = 5;
const int sigval = SIGSTOP;
@@ -2629,117 +2623,23 @@
#if defined(TWAIT_HAVE_STATUS)
int status;
#endif
- struct reg r;
-
- DPRINTF("Before forking process PID=%d\n", getpid());
- SYSCALL_REQUIRE((child = fork()) != -1);
- if (child == 0) {
- DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
- FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
- DPRINTF("Before raising %s from child\n", strsignal(sigval));
- FORKEE_ASSERT(raise(sigval) == 0);
-
- DPRINTF("Before exiting of the child process\n");
- _exit(exitval);
- }
- DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_stopped(status, sigval);
-
- DPRINTF("Call GETREGS for the child process\n");
- SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
-
- DPRINTF("Before resuming the child process where it left off and "
- "without signal to be sent\n");
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_exited(status, exitval);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
+#if defined(HAVE_GPREGS)
+ struct reg gpr;
#endif
-
-#if defined(HAVE_GPREGS)
-ATF_TC(regs2);
-ATF_TC_HEAD(regs2, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify plain PT_GETREGS call and retrieve PC");
-}
-
-ATF_TC_BODY(regs2, tc)
-{
- const int exitval = 5;
- const int sigval = SIGSTOP;
- pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
+#if defined(HAVE_FPREGS)
+ struct fpreg fpr;
#endif
- struct reg r;
-
- DPRINTF("Before forking process PID=%d\n", getpid());
- SYSCALL_REQUIRE((child = fork()) != -1);
- if (child == 0) {
- DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
- FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
- DPRINTF("Before raising %s from child\n", strsignal(sigval));
- FORKEE_ASSERT(raise(sigval) == 0);
-
- DPRINTF("Before exiting of the child process\n");
- _exit(exitval);
- }
- DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_stopped(status, sigval);
-
- DPRINTF("Call GETREGS for the child process\n");
- SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
-
- DPRINTF("Retrieved PC=%" PRIxREGISTER "\n", PTRACE_REG_PC(&r));
-
- DPRINTF("Before resuming the child process where it left off and "
- "without signal to be sent\n");
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_exited(status, exitval);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
+ register_t rgstr;
+
+#if !defined(HAVE_GPREGS)
+ if (strcmp(regset, "regs") == 0)
+ atf_tc_fail("Impossible test scenario!");
#endif
-#if defined(HAVE_GPREGS)
-ATF_TC(regs3);
-ATF_TC_HEAD(regs3, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify plain PT_GETREGS call and retrieve SP");
-}
-
-ATF_TC_BODY(regs3, tc)
-{
- const int exitval = 5;
- const int sigval = SIGSTOP;
- pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
+#if !defined(HAVE_FPREGS)
+ if (strcmp(regset, "fpregs") == 0)
+ atf_tc_fail("Impossible test scenario!");
#endif
- struct reg r;
DPRINTF("Before forking process PID=%d\n", getpid());
SYSCALL_REQUIRE((child = fork()) != -1);
@@ -2760,66 +2660,47 @@
validate_status_stopped(status, sigval);
- DPRINTF("Call GETREGS for the child process\n");
- SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
-
- DPRINTF("Retrieved SP=%" PRIxREGISTER "\n", PTRACE_REG_SP(&r));
-
- DPRINTF("Before resuming the child process where it left off and "
- "without signal to be sent\n");
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_exited(status, exitval);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
+#if defined(HAVE_GPREGS)
+ if (strcmp(regset, "regs") == 0) {
+ DPRINTF("Call GETREGS for the child process\n");
+ SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &gpr, 0) != -1);
+
+ if (strcmp(aux, "none") == 0) {
+ DPRINTF("Retrieved registers\n");
+ } else if (strcmp(aux, "pc") == 0) {
+ rgstr = PTRACE_REG_PC(&gpr);
+ DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr);
+ } else if (strcmp(aux, "set_pc") == 0) {
+ rgstr = PTRACE_REG_PC(&gpr);
+ PTRACE_REG_SET_PC(&gpr, rgstr);
+ } else if (strcmp(aux, "sp") == 0) {
+ rgstr = PTRACE_REG_SP(&gpr);
+ DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr);
+ } else if (strcmp(aux, "intrv") == 0) {
+ rgstr = PTRACE_REG_INTRV(&gpr);
+ DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr);
+ } else if (strcmp(aux, "setregs") == 0) {
+ DPRINTF("Call SETREGS for the child process\n");
+ SYSCALL_REQUIRE(
+ ptrace(PT_GETREGS, child, &gpr, 0) != -1);
+ }
+ }
#endif
-#if defined(HAVE_GPREGS)
-ATF_TC(regs4);
-ATF_TC_HEAD(regs4, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify plain PT_GETREGS call and retrieve INTRV");
-}
-
-ATF_TC_BODY(regs4, tc)
-{
- const int exitval = 5;
- const int sigval = SIGSTOP;
- pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
+#if defined(HAVE_FPREGS)
+ if (strcmp(regset, "fpregs") == 0) {
+ DPRINTF("Call GETFPREGS for the child process\n");
+ SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, &fpr, 0) != -1);
+
+ if (strcmp(aux, "getfpregs") == 0) {
+ DPRINTF("Retrieved FP registers\n");
+ } else if (strcmp(aux, "setfpregs") == 0) {
+ DPRINTF("Call SETFPREGS for the child\n");
+ SYSCALL_REQUIRE(
+ ptrace(PT_SETFPREGS, child, &fpr, 0) != -1);
+ }
+ }
#endif
- struct reg r;
-
- DPRINTF("Before forking process PID=%d\n", getpid());
- SYSCALL_REQUIRE((child = fork()) != -1);
- if (child == 0) {
- DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
- FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
- DPRINTF("Before raising %s from child\n", strsignal(sigval));
- FORKEE_ASSERT(raise(sigval) == 0);
-
- DPRINTF("Before exiting of the child process\n");
- _exit(exitval);
- }
- DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_stopped(status, sigval);
-
- DPRINTF("Call GETREGS for the child process\n");
- SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
-
- DPRINTF("Retrieved INTRV=%" PRIxREGISTER "\n", PTRACE_REG_INTRV(&r));
DPRINTF("Before resuming the child process where it left off and "
"without signal to be sent\n");
@@ -2833,176 +2714,36 @@
DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
}
+
+#define ACCESS_REGS(test, regset, aux) \
+ATF_TC(test); \
+ATF_TC_HEAD(test, tc) \
+{ \
+ atf_tc_set_md_var(tc, "descr", \
+ "Verify " regset " with auxiliary operation: " aux); \
+} \
+ \
+ATF_TC_BODY(test, tc) \
+{ \
+ \
+ access_regs(regset, aux); \
+}
#endif
#if defined(HAVE_GPREGS)
-ATF_TC(regs5);
-ATF_TC_HEAD(regs5, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify PT_GETREGS and PT_SETREGS calls without changing regs");
-}
-
Home |
Main Index |
Thread Index |
Old Index