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 ATF: Add new test race1 in t_ptrace_wait*



details:   https://anonhg.NetBSD.org/src/rev/c5c73ddbdfb5
branches:  trunk
changeset: 321366:c5c73ddbdfb5
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Mar 13 14:54:13 2018 +0000

description:
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>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  55 ++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 5 deletions(-)

diffs (111 lines):

diff -r ba807add36e9 -r c5c73ddbdfb5 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Tue Mar 13 14:45:36 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Tue Mar 13 14:54:13 2018 +0000
@@ -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 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
+#include <time.h>
 #include <unistd.h>
 
 #include <atf-c.h>
@@ -312,7 +313,8 @@
            "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 @@
        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 @@
        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 @@
        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_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();



Home | Main Index | Thread Index | Old Index