Module Name:    src
Committed By:   kamil
Date:           Thu Mar 30 20:24:35 UTC 2017

Modified Files:
        src/tests/kernel/arch/x86: t_ptrace_wait.c

Log Message:
Remove deuplicated code in dbregs_dr[01234]_dont_inherit_lwp

Currently remove tests for dbregs_dr[67]_dont_inherit_lwp.

Sponsored by <The NetBSD Foundation>


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/arch/x86/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/arch/x86/t_ptrace_wait.c
diff -u src/tests/kernel/arch/x86/t_ptrace_wait.c:1.5 src/tests/kernel/arch/x86/t_ptrace_wait.c:1.6
--- src/tests/kernel/arch/x86/t_ptrace_wait.c:1.5	Thu Mar 30 02:17:38 2017
+++ src/tests/kernel/arch/x86/t_ptrace_wait.c	Thu Mar 30 20:24:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.5 2017/03/30 02:17:38 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.6 2017/03/30 20:24:35 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.5 2017/03/30 02:17:38 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.6 2017/03/30 20:24:35 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1622,17 +1622,8 @@ lwp_main_func(void *arg)
 	_lwp_exit();
 }
 
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr0_dont_inherit_lwp);
-ATF_TC_HEAD(dbregs_dr0_dont_inherit_lwp, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	    "Verify that 1 LWP creation is intercepted by ptrace(2) with "
-	    "EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 0 from "
-	    "the forker thread is not inherited");
-}
-
-ATF_TC_BODY(dbregs_dr0_dont_inherit_lwp, tc)
+static void
+dbregs_dont_inherit_lwp(int reg)
 {
 	const int exitval = 5;
 	const int sigval = SIGSTOP;
@@ -1698,9 +1689,9 @@ ATF_TC_BODY(dbregs_dr0_dont_inherit_lwp,
 	for (i = 0; i < __arraycount(r1.dr); i++)
 		printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]);
 
-	r1.dr[0] = (long)(intptr_t)check_happy;
-	printf("Set DR0 (r1.dr[0]) to new value %" PRIxREGISTER "\n",
-	    r1.dr[0]);
+	r1.dr[reg] = (long)(intptr_t)check_happy;
+	printf("Set DR%d (r1.dr[%d]) to new value %" PRIxREGISTER "\n",
+	    reg, reg, r1.dr[0]);
 
 	printf("New state of the debug registers (r1):\n");
 	for (i = 0; i < __arraycount(r1.dr); i++)
@@ -1750,9 +1741,21 @@ ATF_TC_BODY(dbregs_dr0_dont_inherit_lwp,
 	    TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
-#endif
 
-#if defined(HAVE_DBREGS)
+ATF_TC(dbregs_dr0_dont_inherit_lwp);
+ATF_TC_HEAD(dbregs_dr0_dont_inherit_lwp, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Verify that 1 LWP creation is intercepted by ptrace(2) with "
+	    "EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 0 from "
+	    "the forker thread is not inherited");
+}
+
+ATF_TC_BODY(dbregs_dr0_dont_inherit_lwp, tc)
+{
+	dbregs_dont_inherit_lwp(0);
+}
+
 ATF_TC(dbregs_dr1_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr1_dont_inherit_lwp, tc)
 {
@@ -1764,125 +1767,9 @@ ATF_TC_HEAD(dbregs_dr1_dont_inherit_lwp,
 
 ATF_TC_BODY(dbregs_dr1_dont_inherit_lwp, tc)
 {
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	ptrace_state_t state;
-	const int slen = sizeof(state);
-	ptrace_event_t event;
-	const int elen = sizeof(event);
-	ucontext_t uc;
-	lwpid_t lid;
-	static const size_t ssize = 16*1024;
-	void *stack;
-	size_t i;
-	struct dbreg r1;
-	struct dbreg r2;
-
-	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 allocating memory for stack in child\n");
-		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
-
-		printf("Before making context for new lwp in child\n");
-		_lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
-
-		printf("Before creating new in child\n");
-		FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
-
-		printf("Before waiting for lwp %d to exit\n", lid);
-		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
-
-		printf("Before verifying that reported %d and running lid %d "
-		    "are the same\n", lid, the_lwp_id);
-		FORKEE_ASSERT_EQ(lid, the_lwp_id);
-
-		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("Set empty EVENT_MASK for the child %d\n", child);
-	event.pe_set_event = PTRACE_LWP_CREATE;
-	ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
-
-	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)check_happy;
-	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("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 - expected stopped "
-	    "SIGTRAP\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-	validate_status_stopped(status, SIGTRAP);
-
-	ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
-
-	ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
-
-	lid = state.pe_lwp;
-	printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
-
-	printf("Call GETDBREGS for the child process new lwp (r2)\n");
-	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, lid) != -1);
-
-	printf("State of the debug registers (r2):\n");
-	for (i = 0; i < __arraycount(r2.dr); i++)
-		printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]);
-
-	printf("Assert that (r1) and (r2) are not 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 - expected exited\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 - expected no process\n",
-	    TWAIT_FNAME);
-	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+	dbregs_dont_inherit_lwp(1);
 }
-#endif
 
-#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr2_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr2_dont_inherit_lwp, tc)
 {
@@ -1894,514 +1781,23 @@ ATF_TC_HEAD(dbregs_dr2_dont_inherit_lwp,
 
 ATF_TC_BODY(dbregs_dr2_dont_inherit_lwp, tc)
 {
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	ptrace_state_t state;
-	const int slen = sizeof(state);
-	ptrace_event_t event;
-	const int elen = sizeof(event);
-	ucontext_t uc;
-	lwpid_t lid;
-	static const size_t ssize = 16*1024;
-	void *stack;
-	size_t i;
-	struct dbreg r1;
-	struct dbreg r2;
-
-	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 allocating memory for stack in child\n");
-		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
-
-		printf("Before making context for new lwp in child\n");
-		_lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
-
-		printf("Before creating new in child\n");
-		FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
-
-		printf("Before waiting for lwp %d to exit\n", lid);
-		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
-
-		printf("Before verifying that reported %d and running lid %d "
-		    "are the same\n", lid, the_lwp_id);
-		FORKEE_ASSERT_EQ(lid, the_lwp_id);
-
-		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("Set empty EVENT_MASK for the child %d\n", child);
-	event.pe_set_event = PTRACE_LWP_CREATE;
-	ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
-
-	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)check_happy;
-	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("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 - expected stopped "
-	    "SIGTRAP\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-	validate_status_stopped(status, SIGTRAP);
-
-	ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
-
-	ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
-
-	lid = state.pe_lwp;
-	printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
-
-	printf("Call GETDBREGS for the child process new lwp (r2)\n");
-	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, lid) != -1);
+	dbregs_dont_inherit_lwp(2);
+}
 
-	printf("State of the debug registers (r2):\n");
-	for (i = 0; i < __arraycount(r2.dr); i++)
-		printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]);
-
-	printf("Assert that (r1) and (r2) are not 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 - expected exited\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 - expected no process\n",
-	    TWAIT_FNAME);
-	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr3_dont_inherit_lwp);
-ATF_TC_HEAD(dbregs_dr3_dont_inherit_lwp, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	    "Verify that 1 LWP creation is intercepted by ptrace(2) with "
-	    "EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 3 from "
-	    "the forker thread is not inherited");
-}
+ATF_TC(dbregs_dr3_dont_inherit_lwp);
+ATF_TC_HEAD(dbregs_dr3_dont_inherit_lwp, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Verify that 1 LWP creation is intercepted by ptrace(2) with "
+	    "EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 3 from "
+	    "the forker thread is not inherited");
+}
 
 ATF_TC_BODY(dbregs_dr3_dont_inherit_lwp, tc)
 {
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	ptrace_state_t state;
-	const int slen = sizeof(state);
-	ptrace_event_t event;
-	const int elen = sizeof(event);
-	ucontext_t uc;
-	lwpid_t lid;
-	static const size_t ssize = 16*1024;
-	void *stack;
-	size_t i;
-	struct dbreg r1;
-	struct dbreg r2;
-
-	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 allocating memory for stack in child\n");
-		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
-
-		printf("Before making context for new lwp in child\n");
-		_lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
-
-		printf("Before creating new in child\n");
-		FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
-
-		printf("Before waiting for lwp %d to exit\n", lid);
-		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
-
-		printf("Before verifying that reported %d and running lid %d "
-		    "are the same\n", lid, the_lwp_id);
-		FORKEE_ASSERT_EQ(lid, the_lwp_id);
-
-		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("Set empty EVENT_MASK for the child %d\n", child);
-	event.pe_set_event = PTRACE_LWP_CREATE;
-	ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
-
-	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[3] = (long)(intptr_t)check_happy;
-	printf("Set DR3 (r1.dr[3]) to new value %" PRIxREGISTER "\n",
-	    r1.dr[3]);
-
-	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("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 - expected stopped "
-	    "SIGTRAP\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-	validate_status_stopped(status, SIGTRAP);
-
-	ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
-
-	ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
-
-	lid = state.pe_lwp;
-	printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
-
-	printf("Call GETDBREGS for the child process new lwp (r2)\n");
-	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, lid) != -1);
-
-	printf("State of the debug registers (r2):\n");
-	for (i = 0; i < __arraycount(r2.dr); i++)
-		printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]);
-
-	printf("Assert that (r1) and (r2) are not 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 - expected exited\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 - expected no process\n",
-	    TWAIT_FNAME);
-	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr6_dont_inherit_lwp);
-ATF_TC_HEAD(dbregs_dr6_dont_inherit_lwp, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	    "Verify that 1 LWP creation is intercepted by ptrace(2) with "
-	    "EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 6 from "
-	    "the forker thread is not inherited");
-}
-
-ATF_TC_BODY(dbregs_dr6_dont_inherit_lwp, tc)
-{
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	ptrace_state_t state;
-	const int slen = sizeof(state);
-	ptrace_event_t event;
-	const int elen = sizeof(event);
-	ucontext_t uc;
-	lwpid_t lid;
-	static const size_t ssize = 16*1024;
-	void *stack;
-	size_t i;
-	struct dbreg r1;
-	struct dbreg r2;
-
-	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 allocating memory for stack in child\n");
-		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
-
-		printf("Before making context for new lwp in child\n");
-		_lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
-
-		printf("Before creating new in child\n");
-		FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
-
-		printf("Before waiting for lwp %d to exit\n", lid);
-		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
-
-		printf("Before verifying that reported %d and running lid %d "
-		    "are the same\n", lid, the_lwp_id);
-		FORKEE_ASSERT_EQ(lid, the_lwp_id);
-
-		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("Set empty EVENT_MASK for the child %d\n", child);
-	event.pe_set_event = PTRACE_LWP_CREATE;
-	ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
-
-	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[6] = 1; /* breakpoint condition dr0 detected */
-	printf("Set DR6 (r1.dr[6]) to new value %" PRIxREGISTER "\n",
-	    r1.dr[6]);
-
-	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("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 - expected stopped "
-	    "SIGTRAP\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-	validate_status_stopped(status, SIGTRAP);
-
-	ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
-
-	ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
-
-	lid = state.pe_lwp;
-	printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
-
-	printf("Call GETDBREGS for the child process new lwp (r2)\n");
-	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, lid) != -1);
-
-	printf("State of the debug registers (r2):\n");
-	for (i = 0; i < __arraycount(r2.dr); i++)
-		printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]);
-
-	printf("Assert that (r1) and (r2) are not 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 - expected exited\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 - expected no process\n",
-	    TWAIT_FNAME);
-	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr7_dont_inherit_lwp);
-ATF_TC_HEAD(dbregs_dr7_dont_inherit_lwp, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	    "Verify that 1 LWP creation is intercepted by ptrace(2) with "
-	    "EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 7 from "
-	    "the forker thread is not inherited");
+	dbregs_dont_inherit_lwp(3);
 }
 
-ATF_TC_BODY(dbregs_dr7_dont_inherit_lwp, tc)
-{
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	ptrace_state_t state;
-	const int slen = sizeof(state);
-	ptrace_event_t event;
-	const int elen = sizeof(event);
-	ucontext_t uc;
-	lwpid_t lid;
-	static const size_t ssize = 16*1024;
-	void *stack;
-	size_t i;
-	struct dbreg r1;
-	struct dbreg r2;
-
-	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 allocating memory for stack in child\n");
-		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
-
-		printf("Before making context for new lwp in child\n");
-		_lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
-
-		printf("Before creating new in child\n");
-		FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
-
-		printf("Before waiting for lwp %d to exit\n", lid);
-		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
-
-		printf("Before verifying that reported %d and running lid %d "
-		    "are the same\n", lid, the_lwp_id);
-		FORKEE_ASSERT_EQ(lid, the_lwp_id);
-
-		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("Set empty EVENT_MASK for the child %d\n", child);
-	event.pe_set_event = PTRACE_LWP_CREATE;
-	ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
-
-	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[7] = __BIT(16); /* break on data writes dr0 */
-	printf("Set DR6 (r1.dr[7]) to new value %" PRIxREGISTER "\n",
-	    r1.dr[7]);
-
-	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("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 - expected stopped "
-	    "SIGTRAP\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-	validate_status_stopped(status, SIGTRAP);
-
-	ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
-
-	ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
-
-	lid = state.pe_lwp;
-	printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
-
-	printf("Call GETDBREGS for the child process new lwp (r2)\n");
-	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, lid) != -1);
-
-	printf("State of the debug registers (r2):\n");
-	for (i = 0; i < __arraycount(r2.dr); i++)
-		printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]);
-
-	printf("Assert that (r1) and (r2) are not 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 - expected exited\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 - expected no process\n",
-	    TWAIT_FNAME);
-	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-#endif
-
 #if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr0_dont_inherit_execve);
 ATF_TC_HEAD(dbregs_dr0_dont_inherit_execve, tc)
@@ -3102,8 +2498,6 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr1_dont_inherit_lwp);
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr2_dont_inherit_lwp);
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr3_dont_inherit_lwp);
-	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr6_dont_inherit_lwp);
-	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr7_dont_inherit_lwp);
 
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr0_dont_inherit_execve);
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr1_dont_inherit_execve);

Reply via email to