]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-many-short-lived-threads.exp
index ccb5e9ba5777c77e5170f80fd50a29c8e519e726..bf5fe08f093ed1d208133dd25dd4192f46e5ab23 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2008-2016 Free Software Foundation, Inc.
+# Copyright 2008-2023 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # end up leaving stale state behind that confuse the following
 # attach).
 
+# Return true if the running version of DejaGnu is known to not be
+# able to run this test.
+proc bad_dejagnu {} {
+    set dj_ver [dejagnu_version]
+    set dj_ver_major [lindex $dj_ver 0]
+    set dj_ver_minor [lindex $dj_ver 1]
+
+    # DejaGnu versions prior to 1.6 manage to kill the wrong process
+    # due to PID-reuse races.  Since this test spawns many threads, it
+    # widens the race window a whole lot, enough that the inferior is
+    # often killed, and thus the test randomly fails.  See:
+    # http://lists.gnu.org/archive/html/dejagnu/2015-07/msg00005.html
+    # The fix added a close_wait_program procedure.  If that procedure
+    # is defined, and DejaGnu is older than 1.6, assume that means the
+    # fix was backported.
+    if {$dj_ver_major == 1
+       && ($dj_ver_minor < 6 && [info procs close_wait_program] == "")} {
+       return 1
+    }
+
+    return 0
+}
+
+if {[bad_dejagnu]} {
+    unsupported "broken DejaGnu"
+    return 0
+}
+
 if {![can_spawn_for_attach]} {
     return 0
 }
@@ -34,8 +62,6 @@ proc test {} {
     global gdb_prompt
     global decimal
 
-    clean_restart ${binfile}
-
     set test_spawn_id [spawn_wait_for_attach $binfile]
     set testpid [spawn_id_get_pid $test_spawn_id]
 
@@ -80,12 +106,18 @@ proc test {} {
            sleep 1
 
            set test "no new threads"
-           gdb_test_multiple "info threads" $test {
-               -re "New .*$gdb_prompt $" {
-                   fail $test
+           set status 1
+           gdb_test_multiple "info threads" $test -lbl {
+               -re "\r\n\[^\r\n\]*New " {
+                   set status 0
+                   exp_continue
                }
-               -re "$gdb_prompt $" {
-                   pass $test
+               -re -wrap "" {
+                   if { $status == 1 } {
+                       pass $gdb_test_name
+                   } else {
+                       fail $gdb_test_name
+                   }
                }
            }
 
@@ -100,7 +132,7 @@ proc test {} {
            # detaching from the program and reattaching, we check that
            # the program doesn't die due to gdb leaving a pending
            # breakpoint hit on a new thread unprocessed.
-           gdb_test "break break_fn" "Breakpoint.*" "break break_fn"
+           gdb_test "break break_fn" "Breakpoint.*"
 
            # Wait a bit, to give time for most threads to hit the
            # breakpoint, including threads we might have failed to
@@ -136,7 +168,8 @@ proc test {} {
 # failure.
 set options { "additional_flags=-DTIMEOUT=$timeout" debug pthreads }
 
-if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} {
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
+        $options] == -1} {
     return -1
 }