Improve gdb.threads/attach-many-short-lived-threads.exp timeout handling
authorPedro Alves <palves@redhat.com>
Fri, 6 Feb 2015 12:24:32 +0000 (13:24 +0100)
committerPedro Alves <palves@redhat.com>
Fri, 6 Feb 2015 12:24:32 +0000 (13:24 +0100)
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  <palves@redhat.com>

* 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
gdb/testsuite/gdb.threads/attach-many-short-lived-threads.c
gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp

index 56485115d65b3c3212dd2199511859992525484d..f8ca4e88e07ef2920e07dfcedd969831852ff02c 100644 (file)
@@ -1,3 +1,16 @@
+2015-02-06  Pedro Alves  <palves@redhat.com>
+
+       * 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  <palves@redhat.com>
 
        * gdb.base/gdb-sigterm.c (main): Use the TIMEOUT define to
index 001f2ffe80aeca11d8e20d844c535adec11c1318..4a750228394b6b0136e25a067f617e2d6828f466 100644 (file)
@@ -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;
 }
index 96c98ea843de687d6423496daab3a674747c0d9a..2c2236da2e9588e53dec6ca752e029d547dd396b 100644 (file)
@@ -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
 }
 
This page took 0.031941 seconds and 4 git commands to generate.