* gdb.threads/pthreads.exp: Wait for output and delay
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / pthreads.exp
index 08e4af384d671aba38177d53023550cf767c516d..0703395d78bfaad200239518423c0cea44779ecb 100644 (file)
@@ -46,7 +46,7 @@ if [istarget "*-*-linux"] then {
     set target_cflags ""
 }
 set why_msg "unrecognized error"
-foreach lib {-lpthreads -lpthread} {
+foreach lib {-lpthreads -lpthread -lthread} {
     set options "debug"
     lappend options "incdir=${objdir}/${subdir}"
     lappend options "libs=$lib"
@@ -113,7 +113,7 @@ proc all_threads_running {} {
     # been called 15 times.  This should be plenty of time to allow
     # every thread to run at least once, since each thread sleeps for
     # one second between calls to common_routine.
-    gdb_test "tbreak common_routine if hits == 15" ""
+    gdb_test "tbreak common_routine if hits >= 15" ""
 
     # Start all the threads running again and wait for the inferior
     # to stop.  Since no other breakpoints are set at this time
@@ -135,9 +135,22 @@ proc all_threads_running {} {
     # Check that we stopped when we actually expected to stop, by
     # verifying that there have been 15 previous hits.
 
+    # NOTE: Because of synchronization behavior, it is possible for
+    # more than one thread to increment "hits" between one breakpoint
+    # trap and the next.  So stopping after 16 or 17 hits should be
+    # considered acceptable.
+
     send_gdb "p common_routine::hits\n"
     gdb_expect {
-       -re ".*= 15\r\n$gdb_prompt $" {}
+       -re ".*= 15\r\n$gdb_prompt $" {
+           pass "stopped before calling common_routine 15 times"
+       }
+       -re ".*= 16\r\n$gdb_prompt $" {
+           pass "stopped before calling common_routine 15 times (16 times)"
+       }
+       -re ".*= 17\r\n$gdb_prompt $" {
+           pass "stopped before calling common_routine 15 times (17 times)"
+       }
        default {
            fail "stopped before calling common_routine 15 times"
            return 0
@@ -157,7 +170,11 @@ proc all_threads_running {} {
 
     send_gdb "p common_routine::full_coverage\n"
     gdb_expect {
-       -re ".*= 1\r\n$gdb_prompt $" {}
+       -re ".* = 1.*$gdb_prompt $" {}
+       -re ".* = 0.*$gdb_prompt $" {
+           fail "some threads didn't run"
+           return 0
+       }
        default {
            fail "some threads didn't run"
            return 0
@@ -180,13 +197,11 @@ proc test_startup {} {
     # We should be able to do an info threads before starting any others.
     send_gdb "info threads\n"
     gdb_expect {
-       -re ".*Thread.*LWP.*main.*$gdb_prompt $" {
+       -re ".*Thread.*main.*$gdb_prompt $" {
            pass "info threads"
        }
        -re "\r\n$gdb_prompt $" {
-           pass "info threads"
-           setup_xfail "*-*-*"
-           fail "gdb does not support pthreads for this machine"
+           unsupported "gdb does not support pthreads for this machine"
            return 0
        }
     }
@@ -233,6 +248,15 @@ proc check_control_c {} {
 
     # Send a continue followed by ^C to the process to stop it.
     send_gdb "continue\n"
+    gdb_expect {
+       -re "Continuing." {
+           pass "Continue with all threads running"
+       }
+       timeout {
+           fail "Continue with all threads running (timeout)"
+       }
+    }
+    sleep 1
     set description "Stopped with a ^C"
     after 1000 [send_gdb "\003"]
     gdb_expect {
@@ -244,6 +268,7 @@ proc check_control_c {} {
        }
        timeout {
            fail "$description (timeout)"
+           return 1;
        }
     }
     gdb_test "bt" ""
@@ -252,6 +277,7 @@ proc check_control_c {} {
     if [all_threads_running] then {
        pass "All threads running after continuing from ^C stop"
     }
+    return 0;
 }
 
 proc check_backtraces {} {
@@ -286,6 +312,7 @@ proc check_backtraces {} {
     send_gdb "continue\n"
     gdb_expect {
        -re "Breakpoint .* common_routine \\(arg=2\\).*" {
+           pass "continue to bkpt at common_routine in thread 2"
            send_gdb "backtrace\n"
            gdb_expect {
                -re "#0.*common_routine \\(arg=2\\).*#1.*thread2.*" {
@@ -300,16 +327,16 @@ proc check_backtraces {} {
            }
        }
        -re "Breakpoint .* common_routine \\(arg=0\\).*" {
-           fail "stopped in main thread at breakpoint for thread 2"
+           fail "continue to bkpt at common_routine in thread 2 (arg=0)"
        }
        -re "Breakpoint .* common_routine \\(arg=1\\).*" {
-           fail "stopped in main thread at breakpoint for thread 1"
+           fail "continue to bkpt at common_routine in thread 2 (arg=1)"
        }
        -re ".*$gdb_prompt" {
            fail "continue to bkpt at common_routine in thread 2"
        }
        default {
-           fail "continue to bkpt at common_routine in thread 2"
+           fail "continue to bkpt at common_routine in thread 2 (default)"
        }
        timeout {
            fail "continue to bkpt at common_routine in thread 2 (timeout)"
@@ -321,7 +348,10 @@ setup_xfail "alpha-*-osf*"
 if [runto_main] then {
     clear_xfail "alpha-*-osf*"
     if [test_startup] then {
-       check_control_c
+       if [check_control_c] then {
+           warning "Could not stop child with ^C; skipping rest of tests.\n"
+           return;
+       }
        check_backtraces
     }
 }
This page took 0.046353 seconds and 4 git commands to generate.