From patchwork Wed Oct 30 11:04:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35468 Received: (qmail 109848 invoked by alias); 30 Oct 2019 11:05:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109840 invoked by uid 89); 30 Oct 2019 11:05:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN autolearn=ham version=3.3.1 spammy=endless, UD:watchpoint-fork.exp, sk:watchpo, Sleep X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Oct 2019 11:05:03 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 7B9B320339; Wed, 30 Oct 2019 07:05:01 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 3A27D20277 for ; Wed, 30 Oct 2019 07:04:59 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 0D8AD20AF6 for ; Wed, 30 Oct 2019 07:04:59 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Wed, 30 Oct 2019 07:04:59 -0400 From: "Tom de Vries (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] [gdb/testsuite] Fix gdb.threads/watchpoint-fork.exp race X-Gerrit-Change-Id: I63efd4c7771f96b5f5cd87ef2ab36795484ae2be X-Gerrit-Change-Number: 446 X-Gerrit-ChangeURL: X-Gerrit-Commit: 677b9bab635956847a1ec53f2a58f256c2d1a8b4 References: Reply-To: tdevries@suse.de, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-74-g460fb0f7e9 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/446 ...................................................................... [gdb/testsuite] Fix gdb.threads/watchpoint-fork.exp race I ran into: ... Thread 3.1 "watchpoint-fork" hit Breakpoint 3, marker () at \ watchpoint-fork-mt.c:42^M 42 }^M (gdb) parent2: 1945^M FAIL: gdb.threads/watchpoint-fork.exp: child: multithreaded: breakpoint (A) \ after the second fork (timeout) ... The problem is that the FAILing gdb_test expects '(gdb) ' to be the last thing printed, but the inferior prints something after that. A similar FAIL is described in the sources in watchpoint-fork-parent.c: ... printf ("child%d: %d\n", nr, (int) getpid ()); /* Delay to get both the "child%d" and "parent%d" message printed without a race breaking expect by its endless wait on `$gdb_prompt$': Breakpoint 3, marker () at watchpoint-fork.c:33 33 } (gdb) parent2: 14223 */ i = sleep (1); ... I noticed that while the executables print output, the output is not verified in the test-case, so it's merely debug output. Fix this by: - guarding the prints in the executables (as well as related sleep calls) with #if DEBUG, and - compiling by default with DEBUG=0. gdb/testsuite/ChangeLog: 2019-10-30 Tom de Vries * gdb.threads/watchpoint-fork-child.c: Guard prints with #if DEBUG. * gdb.threads/watchpoint-fork-mt.c: Same. * gdb.threads/watchpoint-fork-parent.c: Same. * gdb.threads/watchpoint-fork-st.c: Same. * gdb.threads/watchpoint-fork.exp: Compile with DEBUG=0. Change-Id: I63efd4c7771f96b5f5cd87ef2ab36795484ae2be --- M gdb/testsuite/gdb.threads/watchpoint-fork-child.c M gdb/testsuite/gdb.threads/watchpoint-fork-mt.c M gdb/testsuite/gdb.threads/watchpoint-fork-parent.c M gdb/testsuite/gdb.threads/watchpoint-fork-st.c M gdb/testsuite/gdb.threads/watchpoint-fork.exp 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-child.c b/gdb/testsuite/gdb.threads/watchpoint-fork-child.c index 90c9671..88c4f0c 100644 --- a/gdb/testsuite/gdb.threads/watchpoint-fork-child.c +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-child.c @@ -59,7 +59,9 @@ case -1: assert (0); default: +#if DEBUG printf ("parent%d: %d\n", nr, (int) child); +#endif /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB tracing the child fork with no longer valid thread/lwp entries of the @@ -95,7 +97,9 @@ _exit (0); case 0: +#if DEBUG printf ("child%d: %d\n", nr, (int) getpid ()); +#endif /* Let the parent signal us about its success. Be careful of races. */ diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c index 22be6c7..194e85b 100644 --- a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c @@ -115,7 +115,9 @@ void *thread_result; setbuf (stdout, NULL); +#if DEBUG printf ("main: %d\n", (int) gettid ()); +#endif /* General hardware breakpoints and watchpoints validity. */ marker (); diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-parent.c b/gdb/testsuite/gdb.threads/watchpoint-fork-parent.c index 666ec60..c5642f9 100644 --- a/gdb/testsuite/gdb.threads/watchpoint-fork-parent.c +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-parent.c @@ -40,6 +40,7 @@ case -1: assert (0); case 0: +#if DEBUG printf ("child%d: %d\n", nr, (int) getpid ()); /* Delay to get both the "child%d" and "parent%d" message printed without a race breaking expect by its endless wait on `$gdb_prompt$': @@ -48,6 +49,7 @@ (gdb) parent2: 14223 */ i = sleep (1); assert (i == 0); +#endif /* We must not get caught here (against a forgotten breakpoint). */ var++; @@ -55,11 +57,13 @@ _exit (exit_code); default: +#if DEBUG printf ("parent%d: %d\n", nr, (int) child); /* Delay to get both the "child%d" and "parent%d" message printed, see above. */ i = sleep (1); assert (i == 0); +#endif pid_got = wait (&status); assert (pid_got == child); diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-st.c b/gdb/testsuite/gdb.threads/watchpoint-fork-st.c index 030be6d..b82bcd7 100644 --- a/gdb/testsuite/gdb.threads/watchpoint-fork-st.c +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-st.c @@ -41,7 +41,9 @@ main (void) { setbuf (stdout, NULL); +#if DEBUG printf ("main: %d\n", (int) getpid ()); +#endif /* General hardware breakpoints and watchpoints validity. */ marker (); diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp index 49a6167..22fb921 100644 --- a/gdb/testsuite/gdb.threads/watchpoint-fork.exp +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp @@ -17,7 +17,11 @@ set testfile watchpoint-fork +# Set DEBUG to 0 or 1 in sources +set debug 0 + proc test {type symbol} { + global debug with_test_prefix "$type" { global testfile subdir srcdir gdb_prompt @@ -30,7 +34,8 @@ set srcfile_main ${testfile}-st.c if {[build_executable $testfile.exp $executable \ [list $srcfile_main ${testfile}-${type}.c] \ - [list debug additional_flags=-D$symbol]] == -1} { + [list debug additional_flags=-D$symbol \ + additional_flags=-DDEBUG=$debug]] == -1} { return -1 } @@ -96,7 +101,11 @@ with_test_prefix "multithreaded" { set executable ${testfile}-${type}-mt set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c - if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" [standard_output_file ${executable}] executable [list debug "additional_flags=-D$symbol -DTHREAD"]] != "" } { + if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" \ + [standard_output_file ${executable}] executable \ + [list debug "additional_flags=-D$symbol" \ + "additional_flags=-DDEBUG=$debug" \ + "-DTHREAD"]] != "" } { untested "failed to compile" return }