Module Name:    src
Committed By:   kamil
Date:           Tue Mar 13 14:54:13 UTC 2018

Modified Files:
        src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
  Assert that await_zombie() in attach1 always finds a single
  process and no other error is reported

race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7).
A buggy kernel was asserting an error within this timeframe almost always.

The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.25 src/tests/lib/libc/sys/t_ptrace_wait.c:1.26
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.25	Wed Mar  7 16:40:06 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Mar 13 14:54:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.25 2018/03/07 16:40:06 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.26 2018/03/13 14:54:13 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.25 2018/03/07 16:40:06 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.26 2018/03/13 14:54:13 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -48,6 +48,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.25
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
+#include <time.h>
 #include <unistd.h>
 
 #include <atf-c.h>
@@ -312,7 +313,8 @@ ATF_TC_HEAD(attach1, tc)
 	    "Assert that tracer sees process termination before the parent");
 }
 
-ATF_TC_BODY(attach1, tc)
+static void
+attach1_raw(bool raw)
 {
 	struct msg_fds parent_tracee, parent_tracer;
 	const int exitval_tracee = 5;
@@ -372,8 +374,10 @@ ATF_TC_BODY(attach1, tc)
 	PARENT_TO_CHILD("exit tracee", parent_tracee,  msg);
 
 	DPRINTF("Detect that tracee is zombie\n");
-	await_zombie(tracee);
-
+	if (raw)
+		await_zombie_raw(tracee, 0);
+	else
+		await_zombie(tracee);
 
 	DPRINTF("Assert that there is no status about tracee %d - "
 	    "Tracer must detect zombie first - calling %s()\n", tracee,
@@ -402,6 +406,14 @@ ATF_TC_BODY(attach1, tc)
 	msg_close(&parent_tracer);
 	msg_close(&parent_tracee);
 }
+
+ATF_TC_BODY(attach1, tc)
+{
+
+	/* Reuse this test with race1 */
+	attach1_raw(false);
+}
+
 #endif
 
 #if defined(TWAIT_HAVE_PID)
@@ -7062,6 +7074,37 @@ ATF_TC_BODY(syscallemu1, tc)
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
 
+#if defined(TWAIT_HAVE_PID)
+ATF_TC(race1);
+ATF_TC_HEAD(race1, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Assert that await_zombie() in attach1 always finds a single "
+	    "process and no other error is reported");
+}
+
+ATF_TC_BODY(race1, tc)
+{
+	time_t start, end;
+	double diff;
+	unsigned long N = 0;
+
+	/* Reuse this test with attach1 */
+
+	start = time(NULL);
+	while (true) {
+		DPRINTF("Step: %lu\n", N);
+		attach1_raw(true);
+		end = time(NULL);
+		diff = difftime(end, start);
+		if (diff >= 5.0)
+			break;
+		++N;
+	}
+	DPRINTF("Iterations: %lu\n", N);
+}
+#endif
+
 #include "t_ptrace_amd64_wait.h"
 #include "t_ptrace_i386_wait.h"
 #include "t_ptrace_x86_wait.h"
@@ -7193,6 +7236,8 @@ ATF_TP_ADD_TCS(tp)
 
 	ATF_TP_ADD_TC(tp, syscallemu1);
 
+	ATF_TP_ADD_TC_HAVE_PID(tp, race1);
+
 	ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_I386();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_X86();

Reply via email to