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 the PT_WRITE*/PT_READ* and PIOD_...



details:   https://anonhg.NetBSD.org/src/rev/5f5471fa22b2
branches:  trunk
changeset: 362085:5f5471fa22b2
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat May 26 15:32:31 2018 +0000

description:
Refactor the PT_WRITE*/PT_READ* and PIOD_* ATF ptrace(2) tests

Merge all the PT_WRITE*/PT_READ* and PIOD_* the test cases into the common
body.

Changes:
 - treat D and I variations exactly the same
 - stop testing 2-3-4 attempts to perform the same read/write operation
 - stop testing interlocked (handshake) read/write operations
 - rename the tests
 - test write to .text section (with D and I type of operations)

New tests:
 - bytes_transfer_piod_read_d_8
 - bytes_transfer_piod_read_d_16
 - bytes_transfer_piod_read_d_32
 - bytes_transfer_piod_read_d_64
 - bytes_transfer_piod_read_i_8
 - bytes_transfer_piod_read_i_16
 - bytes_transfer_piod_read_i_32
 - bytes_transfer_piod_read_i_64
 - bytes_transfer_piod_write_d_8
 - bytes_transfer_piod_write_d_16
 - bytes_transfer_piod_write_d_32
 - bytes_transfer_piod_write_d_64
 - bytes_transfer_piod_write_i_8
 - bytes_transfer_piod_write_i_16
 - bytes_transfer_piod_write_i_32
 - bytes_transfer_piod_write_i_64
 - bytes_transfer_read_d
 - bytes_transfer_read_i
 - bytes_transfer_write_d
 - bytes_transfer_write_i
 - bytes_transfer_piod_read_d_8_text
 - bytes_transfer_piod_read_d_16_text
 - bytes_transfer_piod_read_d_32_text
 - bytes_transfer_piod_read_d_64_text
 - bytes_transfer_piod_read_i_8_text
 - bytes_transfer_piod_read_i_16_text
 - bytes_transfer_piod_read_i_32_text
 - bytes_transfer_piod_read_i_64_text
 - bytes_transfer_piod_write_d_8_text
 - bytes_transfer_piod_write_d_16_text
 - bytes_transfer_piod_write_d_32_text
 - bytes_transfer_piod_write_d_64_text
 - bytes_transfer_piod_write_i_8_text
 - bytes_transfer_piod_write_i_16_text
 - bytes_transfer_piod_write_i_32_text
 - bytes_transfer_piod_write_i_64_text
 - bytes_transfer_read_d_text
 - bytes_transfer_read_i_text
 - bytes_transfer_write_d_text
 - bytes_transfer_write_i_text
 - bytes_transfer_piod_read_auxv

These tests are now covering all usual code paths.

All tests pass.
The PaX MPROTECT violating ones automatically detect whether to be skipped.

Eliminated 4x more code than removed.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  2577 ++++++-----------------------------
 1 files changed, 490 insertions(+), 2087 deletions(-)

diffs (truncated from 2647 to 300 lines):

diff -r eb0b3344faf3 -r 5f5471fa22b2 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Sat May 26 15:15:17 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Sat May 26 15:32:31 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.53 2018/05/23 23:56:07 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.54 2018/05/26 15:32:31 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.53 2018/05/23 23:56:07 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.54 2018/05/26 15:32:31 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1682,227 +1682,134 @@
 FORK_TEST(vfork8, DSCR(vfork,1,1,1,0,0), vfork, T, T, T, F, F)
 #endif
 
-
-
-
-ATF_TC(io_read_d1);
-ATF_TC_HEAD(io_read_d1, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify PT_IO with PIOD_READ_D and len = sizeof(uint8_t)");
-}
-
-ATF_TC_BODY(io_read_d1, tc)
+/// ----------------------------------------------------------------------------
+
+enum bytes_transfer_type {
+       BYTES_TRANSFER_DATA,
+       BYTES_TRANSFER_DATAIO,
+       BYTES_TRANSFER_TEXT,
+       BYTES_TRANSFER_TEXTIO,
+       BYTES_TRANSFER_AUXV
+};
+
+static int __used
+bytes_transfer_dummy(int a, int b, int c, int d)
 {
-       const int exitval = 5;
-       const int sigval = SIGSTOP;
-       pid_t child, wpid;
-       uint8_t lookup_me = 0;
-       const uint8_t magic = 0xab;
-       struct ptrace_io_desc io = {
-               .piod_op = PIOD_READ_D,
-               .piod_offs = &lookup_me,
-               .piod_addr = &lookup_me,
-               .piod_len = sizeof(lookup_me)
-       };
-#if defined(TWAIT_HAVE_STATUS)
-       int status;
-#endif
-
-       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);
-
-               lookup_me = magic;
-
-               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("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
-           child, getpid());
-       SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
-
-       ATF_REQUIRE_EQ_MSG(lookup_me, magic,
-           "got value %" PRIx8 " != expected %" PRIx8, lookup_me, magic);
-
-       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));
+       int e, f, g, h;
+
+       a *= 4;
+       b += 3;
+       c -= 2;
+       d /= 1;
+
+       e = strtol("10", NULL, 10);
+       f = strtol("20", NULL, 10);
+       g = strtol("30", NULL, 10);
+       h = strtol("40", NULL, 10);
+
+       return (a + b * c - d) + (e * f - g / h);
 }
 
-ATF_TC(io_read_d2);
-ATF_TC_HEAD(io_read_d2, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify PT_IO with PIOD_READ_D and len = sizeof(uint16_t)");
-}
-
-ATF_TC_BODY(io_read_d2, tc)
+static void
+bytes_transfer(int operation, int size, enum bytes_transfer_type type)
 {
        const int exitval = 5;
        const int sigval = SIGSTOP;
        pid_t child, wpid;
-       uint16_t lookup_me = 0;
-       const uint16_t magic = 0x1234;
-       struct ptrace_io_desc io = {
-               .piod_op = PIOD_READ_D,
-               .piod_offs = &lookup_me,
-               .piod_addr = &lookup_me,
-               .piod_len = sizeof(lookup_me)
-       };
+
+       bool skip = false;
+
+       int lookup_me = 0;
+       uint8_t lookup_me8 = 0;
+       uint16_t lookup_me16 = 0;
+       uint32_t lookup_me32 = 0;
+       uint64_t lookup_me64 = 0;
+
+       int magic = 0x13579246;
+       uint8_t magic8 = 0xab;
+       uint16_t magic16 = 0x1234;
+       uint32_t magic32 = 0x98765432;
+       uint64_t magic64 = 0xabcdef0123456789;
+
+       struct ptrace_io_desc io;
 #if defined(TWAIT_HAVE_STATUS)
        int status;
 #endif
-
-       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);
-
-               lookup_me = magic;
-
-               DPRINTF("Before raising %s from child\n", strsignal(sigval));
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               DPRINTF("Before exiting of the child process\n");
-               _exit(exitval);
+       AuxInfo *ai = NULL, *aip;
+
+       /* Prepare variables for .TEXT transfers */
+       switch (type) {
+       case BYTES_TRANSFER_TEXT:
+               memcpy(&magic, bytes_transfer_dummy, sizeof(magic));
+               break;
+       case BYTES_TRANSFER_TEXTIO:
+               switch (size) {
+               case 8:
+                       memcpy(&magic8, bytes_transfer_dummy, sizeof(magic8));
+                       break;
+               case 16:
+                       memcpy(&magic16, bytes_transfer_dummy, sizeof(magic16));
+                       break;
+               case 32:
+                       memcpy(&magic32, bytes_transfer_dummy, sizeof(magic32));
+                       break;
+               case 64:
+                       memcpy(&magic64, bytes_transfer_dummy, sizeof(magic64));
+                       break;
+               }
+               break;
+       default:
+               break;
        }
-       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("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
-           child, getpid());
-       SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
-
-       ATF_REQUIRE_EQ_MSG(lookup_me, magic,
-           "got value %" PRIx16 " != expected %" PRIx16, lookup_me, magic);
-
-       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));
-}
-
-ATF_TC(io_read_d3);
-ATF_TC_HEAD(io_read_d3, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify PT_IO with PIOD_READ_D and len = sizeof(uint32_t)");
-}
-
-ATF_TC_BODY(io_read_d3, tc)
-{
-       const int exitval = 5;
-       const int sigval = SIGSTOP;
-       pid_t child, wpid;
-       uint32_t lookup_me = 0;
-       const uint32_t magic = 0x1234abcd;
-       struct ptrace_io_desc io = {
-               .piod_op = PIOD_READ_D,
-               .piod_offs = &lookup_me,
-               .piod_addr = &lookup_me,
-               .piod_len = sizeof(lookup_me)
-       };
-#if defined(TWAIT_HAVE_STATUS)
-       int status;
-#endif
-
-       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);
-
-               lookup_me = magic;
-
-               DPRINTF("Before raising %s from child\n", strsignal(sigval));
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               DPRINTF("Before exiting of the child process\n");
-               _exit(exitval);
+
+       /* Prepare variables for PIOD and AUXV transfers */
+       switch (type) {
+       case BYTES_TRANSFER_TEXTIO:
+       case BYTES_TRANSFER_DATAIO:
+               io.piod_op = operation;
+               switch (size) {
+               case 8:
+                       io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ?
+                                      (void *)bytes_transfer_dummy :
+                                      &lookup_me8;
+                       io.piod_addr = &lookup_me8;
+                       io.piod_len = sizeof(lookup_me8);
+                       break;
+               case 16:
+                       io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ?
+                                      (void *)bytes_transfer_dummy :
+                                      &lookup_me16;
+                       io.piod_addr = &lookup_me16;
+                       io.piod_len = sizeof(lookup_me16);
+                       break;
+               case 32:
+                       io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ?
+                                      (void *)bytes_transfer_dummy :
+                                      &lookup_me32;
+                       io.piod_addr = &lookup_me32;
+                       io.piod_len = sizeof(lookup_me32);
+                       break;
+               case 64:
+                       io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ?
+                                      (void *)bytes_transfer_dummy :
+                                      &lookup_me64;
+                       io.piod_addr = &lookup_me64;
+                       io.piod_len = sizeof(lookup_me64);
+                       break;
+               default:
+                       break;
+               }
+               break;
+       case BYTES_TRANSFER_AUXV:



Home | Main Index | Thread Index | Old Index