1 # Copyright (C) 1996, 1997, 2002, 2003 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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}
38 # Default to the usual (only?) -lpthread on GNU/Linux to quiet noise
39 if [istarget "*-*-linux*"] then {
40 set possible_libs "-lpthread -lpthreads -lthread"
42 set possible_libs "-lpthreads -lpthread -lthread"
45 set why_msg "unrecognized error"
46 foreach lib $possible_libs {
48 lappend options "incdir=${objdir}"
49 lappend options "libs=$lib"
50 set ccout [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options]
51 switch -regexp -- $ccout {
52 ".*no posix threads support.*" {
53 set why_msg "missing threads include file"
56 ".*cannot open -lpthread.*" {
57 set why_msg "missing runtime threads library"
59 ".*Can't find library for -lpthread.*" {
60 set why_msg "missing runtime threads library"
63 pass "successfully compiled posix threads test case"
69 if {$built_binfile == "0"} {
70 unsupported "Couldn't compile ${srcfile}, ${why_msg}"
74 # Now we can proceed with the real testing.
80 send_gdb "print args\n"
82 -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
84 set list_count [expr $list_count + 1]
85 pass "listed args ($list_count)"
86 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)]
90 fail "listed args ($list_count) (unknown output)"
94 fail "listed args ($list_count) (timeout)"
99 proc stop_process { description } {
102 # For this to work we must be sure to consume the "Continuing."
103 # message first, or GDB's signal handler may not be in place.
104 after 1000 {send_gdb "\003"}
106 -re "Program received signal SIGINT.*$gdb_prompt $"
112 fail "$description (timeout)"
117 proc get_current_thread { description } {
122 -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $"
125 return $expect_out(1,string)
129 fail "$description (unknown output)"
133 fail "$description (timeout)"
138 proc my_continue { msg } {
139 send_gdb "continue\n"
142 { pass "continue ($msg)" }
144 { fail "continue ($msg) (timeout)" }
147 stop_process "stop all threads ($msg)"
149 # Make sure we're in one of the looping threads.
150 gdb_breakpoint [gdb_get_line_number "schedlock.exp: main loop"]
151 gdb_continue_to_breakpoint "return to loop ($msg)"
155 proc step_ten_loops { msg } {
158 for {set i 0} {[expr $i < 10]} {set i [expr $i + 1]} {
162 -re ".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" {
163 pass "step to increment ($msg $i)"
165 -re "$gdb_prompt $" {
166 if {$other_step == 0} {
171 fail "step to increment ($msg $i)"
176 fail "step to increment ($msg $i) (timeout)"
182 # Start with a fresh gdb.
186 gdb_reinitialize_dir $srcdir/$subdir
188 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
189 # run the program and gdb starts saving and restoring tty states.
190 # On Ultrix, we don't need it and it is really slow (because shell_escape
191 # doesn't use vfork).
192 if ![istarget "*-*-ultrix*"] then {
193 gdb_test "shell stty intr '^C'" ""
198 gdb_test "set print sevenbit-strings" ""
199 gdb_test "set width 0" ""
203 # See if scheduler locking is available on this target.
204 send_gdb "set scheduler-locking off\n"
207 -re "Target .* cannot support this command"
209 unsupported "target does not support scheduler locking"
214 pass "scheduler locking set to none"
218 unsupported "target does not support scheduler locking (timeout)"
223 gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"]
224 gdb_continue_to_breakpoint "all threads started"
229 set start_args [get_args]
231 # First make sure that all threads are alive.
232 my_continue "initial"
234 set cont_args [get_args]
236 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
237 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
238 fail "thread $i ran (didn't run)"
244 # We can't change threads, unfortunately, in current GDB. Use
245 # whichever we stopped in.
246 set curthread [get_current_thread "find current thread (1)"]
251 # Test stepping without scheduler locking.
252 gdb_test "set scheduler-locking off" ""
254 step_ten_loops "unlocked"
256 # Make sure we're still in the same thread.
257 set newthread [get_current_thread "find current thread (2)"]
258 if {$curthread == $newthread} {
259 pass "step without lock does not change thread"
261 fail "step without lock does not change thread (switched to thread $newthread)"
264 set start_args $cont_args
265 set cont_args [get_args]
267 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
268 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
269 if {$i == $curthread} {
270 fail "current thread stepped (didn't run)"
272 fail "other thread $i ran (didn't run) (1)"
275 if {$i == $curthread} {
276 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
277 pass "current thread stepped"
279 fail "current thread stepped (wrong amount)"
282 pass "other thread $i ran (1)"
287 # Test continue with scheduler locking
288 gdb_test "set scheduler-locking on" ""
290 my_continue "with lock"
292 # Make sure we're still in the same thread.
293 set newthread [get_current_thread "find current thread (3)"]
294 if {$curthread == $newthread} {
295 pass "continue with lock does not change thread"
297 fail "continue with lock does not change thread (switched to thread $newthread)"
300 set start_args $cont_args
301 set cont_args [get_args]
303 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
304 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
305 if {$i == $curthread} {
306 fail "current thread ran (didn't run)"
308 pass "other thread $i didn't run"
311 if {$i == $curthread} {
312 pass "current thread ran"
314 fail "other thread $i didn't run (ran)"
319 # Test stepping with scheduler locking
320 step_ten_loops "locked"
322 # Make sure we're still in the same thread.
323 set newthread [get_current_thread "find current thread (2)"]
324 if {$curthread == $newthread} {
325 pass "step with lock does not change thread"
327 fail "step with lock does not change thread (switched to thread $newthread)"
330 set start_args $cont_args
331 set cont_args [get_args]
333 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
334 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
335 if {$i == $curthread} {
336 fail "current thread stepped locked (didn't run)"
338 pass "other thread $i didn't run (stepping)"
341 if {$i == $curthread} {
342 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
343 pass "current thread stepped locked"
345 fail "current thread stepped locked (wrong amount)"
348 fail "other thread $i didn't run (stepping) (ran)"