Module Name: src Committed By: kamil Date: Wed Jan 25 17:01:57 UTC 2017
Modified Files: src/tests/kernel: t_ptrace_wait.c Log Message: Add io_read_auxv1 in t_ptrace_wait{,3,4,6,id,pid} io_read_auxv1: Verify PT_READ_AUXV called for tracee Sponsored by <The NetBSD Foundation> To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/tests/kernel/t_ptrace_wait.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/kernel/t_ptrace_wait.c diff -u src/tests/kernel/t_ptrace_wait.c:1.60 src/tests/kernel/t_ptrace_wait.c:1.61 --- src/tests/kernel/t_ptrace_wait.c:1.60 Sat Jan 14 19:17:10 2017 +++ src/tests/kernel/t_ptrace_wait.c Wed Jan 25 17:01:57 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.60 2017/01/14 19:17:10 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.61 2017/01/25 17:01:57 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.60 2017/01/14 19:17:10 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.61 2017/01/25 17:01:57 kamil Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -37,6 +37,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.60 #include <sys/sysctl.h> #include <sys/wait.h> #include <machine/reg.h> +#include <elf.h> #include <err.h> #include <errno.h> #include <lwp.h> @@ -2407,6 +2408,72 @@ ATF_TC_BODY(io_write_d4, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); } +ATF_TC(io_read_auxv1); +ATF_TC_HEAD(io_read_auxv1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify PT_READ_AUXV called for tracee"); +} + +ATF_TC_BODY(io_read_auxv1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + AuxInfo ai[100], *aip; + struct ptrace_io_desc io = { + .piod_op = PIOD_READ_AUXV, + .piod_offs = 0, + .piod_addr = ai, + .piod_len = sizeof(ai) + }; + + 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("Read new AUXV from tracee (PID=%d) by tracer (PID=%d)\n", + child, getpid()); + ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); + + printf("Asserting that AUXV length (%zu) is > 0\n", io.piod_len); + ATF_REQUIRE(io.piod_len > 0); + + for (aip = ai; aip->a_type != AT_NULL; aip++) + printf("a_type=%#llx a_v=%#llx\n", + (long long int)aip->a_type, (long long int)aip->a_v); + + 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(read_d1); ATF_TC_HEAD(read_d1, tc) { @@ -5667,6 +5734,8 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, read_i3); ATF_TP_ADD_TC(tp, read_i4); + ATF_TP_ADD_TC(tp, io_read_auxv1); + ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs2); ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs3);