From 18ecae383162b8c1be40030cddd69f12d718c689 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Mon, 17 Sep 2007 15:38:05 +0000 Subject: [PATCH] * schedlock.c (NUM): Change to 1. (main): Use args[0] for the main thread. * schedlock.exp: Only expect two threads. Only issue one pass or fail regardless of the number of threads. --- gdb/testsuite/ChangeLog | 7 ++++ gdb/testsuite/gdb.threads/schedlock.c | 8 ++-- gdb/testsuite/gdb.threads/schedlock.exp | 51 ++++++++++++++++--------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 188db16099..491124ac08 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2007-09-17 Daniel Jacobowitz + + * schedlock.c (NUM): Change to 1. + (main): Use args[0] for the main thread. + * schedlock.exp: Only expect two threads. Only issue one pass or fail + regardless of the number of threads. + 2007-09-14 Maciej W. Rozycki * gdb.mi/mi-watch.exp (test_watchpoint_all): Pass the watchpoint diff --git a/gdb/testsuite/gdb.threads/schedlock.c b/gdb/testsuite/gdb.threads/schedlock.c index c1b9069a62..b364dd41b3 100644 --- a/gdb/testsuite/gdb.threads/schedlock.c +++ b/gdb/testsuite/gdb.threads/schedlock.c @@ -22,7 +22,7 @@ void *thread_function(void *arg); /* Pointer to function executed by each thread */ -#define NUM 5 +#define NUM 1 unsigned int args[NUM+1]; @@ -32,7 +32,7 @@ int main() { void *thread_result; long i; - for (i = 0; i < NUM; i++) + for (i = 1; i <= NUM; i++) { args[i] = 1; res = pthread_create(&threads[i], @@ -42,8 +42,8 @@ int main() { } /* schedlock.exp: last thread start. */ - args[i] = 1; - thread_function ((void *) i); + args[0] = 1; + thread_function ((void *) 0); exit(EXIT_SUCCESS); } diff --git a/gdb/testsuite/gdb.threads/schedlock.exp b/gdb/testsuite/gdb.threads/schedlock.exp index cc9a53b851..c2ec57a267 100644 --- a/gdb/testsuite/gdb.threads/schedlock.exp +++ b/gdb/testsuite/gdb.threads/schedlock.exp @@ -32,6 +32,9 @@ set testfile "schedlock" set srcfile ${testfile}.c set binfile ${objdir}/${subdir}/${testfile} +# The number of threads, including the main thread. +set NUM 2 + if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } { return -1 } @@ -44,11 +47,11 @@ proc get_args { } { send_gdb "print args\n" gdb_expect { - -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt" + -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt" { set list_count [expr $list_count + 1] pass "listed args ($list_count)" - return [list $expect_out(1,string) $expect_out(2,string) $expect_out(3,string) $expect_out(4,string) $expect_out(5,string) $expect_out(6,string)] + return [list $expect_out(1,string) $expect_out(2,string)] } -re "$gdb_prompt" { @@ -112,7 +115,7 @@ proc my_continue { msg } { stop_process "stop all threads ($msg)" # Make sure we're in one of the non-main looping threads. - gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 5"] + gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"] gdb_continue_to_breakpoint "return to loop ($msg)" delete_breakpoints } @@ -198,13 +201,17 @@ my_continue "initial" set cont_args [get_args] -for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} { +set ok 1 +for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { if {[lindex $start_args $i] == [lindex $cont_args $i]} { - fail "thread $i ran (didn't run)" - } else { - pass "thread $i ran" + set ok 0 } } +if { $ok } { + pass "all threads alive" +} else { + fail "all threads alive" +} # We can't change threads, unfortunately, in current GDB. Use # whichever we stopped in. @@ -230,7 +237,7 @@ set start_args $cont_args set cont_args [get_args] set num_other_threads 0 -for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} { +for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { if {[lindex $start_args $i] == [lindex $cont_args $i]} { if {$i == $curthread} { fail "current thread stepped (didn't run)" @@ -248,9 +255,9 @@ for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} { } } if {$num_other_threads > 0} { - pass "other threads ran (1)" + pass "other threads ran - unlocked" } else { - fail "other threads ran (no other threads ran) (1)" + fail "other threads ran - unlocked" } # Test continue with scheduler locking @@ -269,21 +276,25 @@ if {$curthread == $newthread} { set start_args $cont_args set cont_args [get_args] -for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} { +set num_other_threads 0 +for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { if {[lindex $start_args $i] == [lindex $cont_args $i]} { if {$i == $curthread} { fail "current thread ran (didn't run)" - } else { - pass "other thread $i didn't run" } } else { if {$i == $curthread} { pass "current thread ran" } else { - fail "other thread $i didn't run (ran)" + incr num_other_threads } } } +if {$num_other_threads > 0} { + fail "other threads didn't run - locked" +} else { + pass "other threads didn't run - locked" +} # Test stepping with scheduler locking step_ten_loops "locked" @@ -299,12 +310,11 @@ if {$curthread == $newthread} { set start_args $cont_args set cont_args [get_args] -for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} { +set num_other_threads 0 +for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { if {[lindex $start_args $i] == [lindex $cont_args $i]} { if {$i == $curthread} { fail "current thread stepped locked (didn't run)" - } else { - pass "other thread $i didn't run (stepping)" } } else { if {$i == $curthread} { @@ -314,9 +324,14 @@ for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} { fail "current thread stepped locked (wrong amount)" } } else { - fail "other thread $i didn't run (stepping) (ran)" + incr num_other_threads } } } +if {$num_other_threads > 0} { + fail "other threads didn't run - step locked" +} else { + pass "other threads didn't run - step locked" +} return 0