1 # Copyright (C) 1996, 1997, 2002, 2003, 2007, 2008
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Daniel Jacobowitz <drow@mvista.com>
21 # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
23 # This test covers the various forms of "set scheduler-locking".
32 set testfile "schedlock"
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
36 # The number of threads, including the main thread.
39 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
43 # Now we can proceed with the real testing.
49 send_gdb "print args\n"
51 -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
53 set list_count [expr $list_count + 1]
54 pass "listed args ($list_count)"
55 return [list $expect_out(1,string) $expect_out(2,string)]
59 fail "listed args ($list_count) (unknown output)"
63 fail "listed args ($list_count) (timeout)"
68 proc stop_process { description } {
71 # For this to work we must be sure to consume the "Continuing."
72 # message first, or GDB's signal handler may not be in place.
73 after 1000 {send_gdb "\003"}
75 -re "Program received signal SIGINT.*$gdb_prompt $"
81 fail "$description (timeout)"
86 proc get_current_thread { description } {
91 -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $"
94 return $expect_out(1,string)
98 fail "$description (unknown output)"
102 fail "$description (timeout)"
107 proc my_continue { msg } {
108 send_gdb "continue\n"
111 { pass "continue ($msg)" }
113 { fail "continue ($msg) (timeout)" }
116 stop_process "stop all threads ($msg)"
118 # Make sure we're in one of the non-main looping threads.
119 gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"]
120 gdb_continue_to_breakpoint "return to loop ($msg)"
124 proc step_ten_loops { msg } {
127 for {set i 0} {[expr $i < 10]} {set i [expr $i + 1]} {
131 -re ".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" {
132 pass "step to increment ($msg $i)"
134 -re "$gdb_prompt $" {
135 if {$other_step == 0} {
140 fail "step to increment ($msg $i)"
145 fail "step to increment ($msg $i) (timeout)"
151 # Start with a fresh gdb.
155 gdb_reinitialize_dir $srcdir/$subdir
157 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
158 # run the program and gdb starts saving and restoring tty states.
159 # On Ultrix, we don't need it and it is really slow (because shell_escape
160 # doesn't use vfork).
161 if ![istarget "*-*-ultrix*"] then {
162 gdb_test "shell stty intr '^C'" ""
167 gdb_test "set print sevenbit-strings" ""
168 gdb_test "set width 0" ""
172 # See if scheduler locking is available on this target.
173 send_gdb "set scheduler-locking off\n"
176 -re "Target .* cannot support this command"
178 unsupported "target does not support scheduler locking"
183 pass "scheduler locking set to none"
187 unsupported "target does not support scheduler locking (timeout)"
192 gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"]
193 gdb_continue_to_breakpoint "all threads started"
198 set start_args [get_args]
200 # First make sure that all threads are alive.
201 my_continue "initial"
203 set cont_args [get_args]
206 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
207 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
212 pass "all threads alive"
214 fail "all threads alive"
217 # We can't change threads, unfortunately, in current GDB. Use
218 # whichever we stopped in.
219 set curthread [get_current_thread "find current thread (1)"]
224 # Test stepping without scheduler locking.
225 gdb_test "set scheduler-locking off" ""
227 step_ten_loops "unlocked"
229 # Make sure we're still in the same thread.
230 set newthread [get_current_thread "find current thread (2)"]
231 if {$curthread == $newthread} {
232 pass "step without lock does not change thread"
234 fail "step without lock does not change thread (switched to thread $newthread)"
237 set start_args $cont_args
238 set cont_args [get_args]
240 set num_other_threads 0
241 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
242 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
243 if {$i == $curthread} {
244 fail "current thread stepped (didn't run)"
247 if {$i == $curthread} {
248 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
249 pass "current thread stepped"
251 fail "current thread stepped (wrong amount)"
254 set num_other_threads [expr $num_other_threads + 1]
258 if {$num_other_threads > 0} {
259 pass "other threads ran - unlocked"
261 fail "other threads ran - unlocked"
264 # Test continue with scheduler locking
265 gdb_test "set scheduler-locking on" ""
267 my_continue "with lock"
269 # Make sure we're still in the same thread.
270 set newthread [get_current_thread "find current thread (3)"]
271 if {$curthread == $newthread} {
272 pass "continue with lock does not change thread"
274 fail "continue with lock does not change thread (switched to thread $newthread)"
277 set start_args $cont_args
278 set cont_args [get_args]
280 set num_other_threads 0
281 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
282 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
283 if {$i == $curthread} {
284 fail "current thread ran (didn't run)"
287 if {$i == $curthread} {
288 pass "current thread ran"
290 incr num_other_threads
294 if {$num_other_threads > 0} {
295 fail "other threads didn't run - locked"
297 pass "other threads didn't run - locked"
300 # Test stepping with scheduler locking
301 step_ten_loops "locked"
303 # Make sure we're still in the same thread.
304 set newthread [get_current_thread "find current thread (2)"]
305 if {$curthread == $newthread} {
306 pass "step with lock does not change thread"
308 fail "step with lock does not change thread (switched to thread $newthread)"
311 set start_args $cont_args
312 set cont_args [get_args]
314 set num_other_threads 0
315 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
316 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
317 if {$i == $curthread} {
318 fail "current thread stepped locked (didn't run)"
321 if {$i == $curthread} {
322 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
323 pass "current thread stepped locked"
325 fail "current thread stepped locked (wrong amount)"
328 incr num_other_threads
332 if {$num_other_threads > 0} {
333 fail "other threads didn't run - step locked"
335 pass "other threads didn't run - step locked"