Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel/arch/amd64 Use siginfo_t to validate tests/kern...



details:   https://anonhg.NetBSD.org/src/rev/aef0b6f3ad6c
branches:  trunk
changeset: 350731:aef0b6f3ad6c
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jan 18 05:14:34 2017 +0000

description:
Use siginfo_t to validate tests/kernel/arch/amd64/t_ptrace_wait*

This change makes sure that the fired expected watchpoint with expected
property. It's done with PT_GET_SIGINFO and checking SIGTRAP codes.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/kernel/arch/amd64/t_ptrace_wait.c |  196 +++++++++++++++++++++++++++++++-
 1 files changed, 194 insertions(+), 2 deletions(-)

diffs (truncated from 378 to 300 lines):

diff -r 5453da3f1614 -r aef0b6f3ad6c tests/kernel/arch/amd64/t_ptrace_wait.c
--- a/tests/kernel/arch/amd64/t_ptrace_wait.c   Wed Jan 18 05:11:59 2017 +0000
+++ b/tests/kernel/arch/amd64/t_ptrace_wait.c   Wed Jan 18 05:14:34 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.10 2017/01/16 21:35:59 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.11 2017/01/18 05:14:34 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.10 2017/01/16 21:35:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.11 2017/01/18 05:14:34 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -366,6 +366,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -418,6 +420,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 0);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        pw.pw_md.md_address = NULL;
        printf("Before writing watchpoint %d (disable it)\n", i);
        ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1);
@@ -456,6 +472,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -508,6 +526,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 1);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        pw.pw_md.md_address = NULL;
        printf("Before writing watchpoint %d (disable it)\n", i);
        ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1);
@@ -546,6 +578,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -598,6 +632,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 2);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        pw.pw_md.md_address = NULL;
        printf("Before writing watchpoint %d (disable it)\n", i);
        ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1);
@@ -636,6 +684,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -688,6 +738,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 3);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        pw.pw_md.md_address = NULL;
        printf("Before writing watchpoint %d (disable it)\n", i);
        ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1);
@@ -726,6 +790,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -777,6 +843,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 0);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        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);
@@ -811,6 +891,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -862,6 +944,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 1);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        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);
@@ -896,6 +992,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -947,6 +1045,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 2);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        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);
@@ -982,6 +1094,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -1033,6 +1147,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 3);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        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);
@@ -1067,6 +1195,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -1118,6 +1248,20 @@
 
        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_HWWPT);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 0);
+       ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
        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);
@@ -1152,6 +1296,8 @@
        struct ptrace_watchpoint pw;
        int len = sizeof(pw);
        int watchme = 1234;
+       struct ptrace_siginfo info;
+       memset(&info, 0, sizeof(info));
 
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
@@ -1203,6 +1349,20 @@
 
        validate_status_stopped(status, SIGTRAP);



Home | Main Index | Thread Index | Old Index