From patchwork Fri Feb 6 12:25:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 4939 Received: (qmail 6585 invoked by alias); 6 Feb 2015 12:25:42 -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 6568 invoked by uid 89); 6 Feb 2015 12:25:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 06 Feb 2015 12:25:40 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t16CPdb9014315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 6 Feb 2015 07:25:39 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t16CPcxo012300 for ; Fri, 6 Feb 2015 07:25:39 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Improve gdb.threads/attach-many-short-lived-threads.exp timeout handling Date: Fri, 6 Feb 2015 13:25:37 +0100 Message-Id: <1423225537-26694-1-git-send-email-palves@redhat.com> The buildbot shows that this test is still racy, and occasionally fails with time outs on some machines. I'd like to get major issues with load out of the way. The test currently exits after 180s, which is just a random number, that has no relation to what the .exp file considers a time out. This commit makes the program wait a bit longer than what the .exp file considers a time out, and, resets the timer for each iteration. Tested on x86_64 Fedora 20, native and extended-remote gdbserver. gdb/testsuite/ 2015-02-06 Pedro Alves * gdb.threads/attach-many-short-lived-threads.c (SECONDS): New macro. (seconds_left, again): New globals. (main): Wait seconds_left in a 1-second sleep loop instead of sleeping 180 seconds. If 'again' is set, reset the seconds counter. * gdb.threads/attach-many-short-lived-threads.exp (test): Set 'again' in the inferior before detaching. Print the seconds left. (options): New global. (top level): Build program with -DTIMEOUT=$timeout. --- gdb/testsuite/ChangeLog | 13 ++++++++++ .../gdb.threads/attach-many-short-lived-threads.c | 29 +++++++++++++++++++--- .../attach-many-short-lived-threads.exp | 13 +++++++++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5648511..f8ca4e8 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,18 @@ 2015-02-06 Pedro Alves + * gdb.threads/attach-many-short-lived-threads.c (SECONDS): New + macro. + (seconds_left, again): New globals. + (main): Wait seconds_left in a 1-second sleep loop instead of + sleeping 180 seconds. If 'again' is set, reset the seconds + counter. + * gdb.threads/attach-many-short-lived-threads.exp (test): Set + 'again' in the inferior before detaching. Print the seconds left. + (options): New global. + (top level): Build program with -DTIMEOUT=$timeout. + +2015-02-06 Pedro Alves + * gdb.base/gdb-sigterm.c (main): Use the TIMEOUT define to determine how many seconds to pass to 'alarm'. * gdb.base/gdb-sigterm.exp (top level): Build program with diff --git a/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.c b/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.c index 001f2ff..4a75022 100644 --- a/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.c +++ b/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.c @@ -113,6 +113,17 @@ detached_fn (void *arg) return NULL; } +/* Allow for as much timeout as DejaGnu wants, plus a bit of + slack. */ +#define SECONDS (TIMEOUT + 20) + +/* We'll exit after this many seconds. */ +unsigned int seconds_left = SECONDS; + +/* GDB sets this whenever it's about to start a new detach/attach + sequence. We react by resetting the seconds left counter. */ +volatile int again = 0; + int main (int argc, char *argv[]) { @@ -144,8 +155,20 @@ main (int argc, char *argv[]) create_thread (&detached_attr, detached_fn, NULL); } - /* Long enough for all the attach/detach sequences done by the .exp - file. */ - sleep (180); + /* Exit after a while if GDB is gone/crashes. But wait long enough + for one attach/detach sequence done by the .exp file. */ + while (--seconds_left > 0) + { + sleep (1); + + if (again) + { + /* GDB should be reattaching soon. Restart the timer. */ + again = 0; + seconds_left = SECONDS; + } + } + + printf ("timeout, exiting\n"); return 0; } diff --git a/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp b/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp index 96c98ea..2c2236d 100644 --- a/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp +++ b/gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp @@ -112,6 +112,12 @@ proc test {} { } if {$attempt < $attempts} { + # Kick the time out timer for another round. + gdb_test "print again = 1" " = 1" "reset timer in the inferior" + # Show the time we had left in the logs, in case + # something goes wrong. + gdb_test "print seconds_left" " = .*" + gdb_test "detach" "Detaching from.*" } else { gdb_test "kill" "" "kill process" "Kill the program being debugged.*y or n. $" "y" @@ -125,7 +131,12 @@ proc test {} { remote_exec target "kill -9 ${testpid}" } -if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} { +# The test program exits after a while, in case GDB crashes. Make it +# wait at least as long as we may wait before declaring a time out +# failure. +set options { "additional_flags=-DTIMEOUT=$timeout" debug pthreads } + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} { return -1 }