* gdb.dwarf2/dw2-compressed.S: Also define __start.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / schedlock.exp
CommitLineData
9b254dd1
DJ
1# Copyright (C) 1996, 1997, 2002, 2003, 2007, 2008
2# Free Software Foundation, Inc.
0312286c
DJ
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
0312286c 7# (at your option) any later version.
e22f8b7c 8#
0312286c
DJ
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.
e22f8b7c 13#
0312286c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
0312286c
DJ
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Daniel Jacobowitz <drow@mvista.com>
21# (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
22#
23# This test covers the various forms of "set scheduler-locking".
24
25if $tracelevel then {
26 strace $tracelevel
27}
28
29set prms_id 0
30set bug_id 0
31
32set testfile "schedlock"
33set srcfile ${testfile}.c
34set binfile ${objdir}/${subdir}/${testfile}
35
18ecae38
DJ
36# The number of threads, including the main thread.
37set NUM 2
38
b5ab8ff3 39if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
0312286c
DJ
40 return -1
41}
42
43# Now we can proceed with the real testing.
44
45proc get_args { } {
46 global list_count
47 global gdb_prompt
48
49 send_gdb "print args\n"
50 gdb_expect {
18ecae38 51 -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
0312286c
DJ
52 {
53 set list_count [expr $list_count + 1]
54 pass "listed args ($list_count)"
18ecae38 55 return [list $expect_out(1,string) $expect_out(2,string)]
0312286c
DJ
56 }
57 -re "$gdb_prompt"
58 {
59 fail "listed args ($list_count) (unknown output)"
60 }
61 timeout
62 {
63 fail "listed args ($list_count) (timeout)"
64 }
65 }
66}
67
68proc stop_process { description } {
69 global gdb_prompt
70
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"}
74 gdb_expect {
75 -re "Program received signal SIGINT.*$gdb_prompt $"
76 {
77 pass $description
78 }
79 timeout
80 {
81 fail "$description (timeout)"
82 }
83 }
84}
85
86proc get_current_thread { description } {
87 global gdb_prompt
88
89 send_gdb "bt\n"
90 gdb_expect {
91 -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $"
92 {
93 pass $description
94 return $expect_out(1,string)
95 }
96 -re "$gdb_prompt $"
97 {
98 fail "$description (unknown output)"
99 }
100 timeout
101 {
102 fail "$description (timeout)"
103 }
104 }
105}
106
107proc my_continue { msg } {
108 send_gdb "continue\n"
109 gdb_expect {
110 -re "Continuing"
111 { pass "continue ($msg)" }
112 timeout
113 { fail "continue ($msg) (timeout)" }
114 }
115
116 stop_process "stop all threads ($msg)"
117
a25fbfec 118 # Make sure we're in one of the non-main looping threads.
18ecae38 119 gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"]
0312286c
DJ
120 gdb_continue_to_breakpoint "return to loop ($msg)"
121 delete_breakpoints
122}
123
124proc step_ten_loops { msg } {
125 global gdb_prompt
126
127 for {set i 0} {[expr $i < 10]} {set i [expr $i + 1]} {
128 send_gdb "step\n"
129 set other_step 0
130 gdb_expect {
131 -re ".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" {
132 pass "step to increment ($msg $i)"
133 }
134 -re "$gdb_prompt $" {
135 if {$other_step == 0} {
136 set other_step 1
137 send_gdb "step\n"
138 exp_continue
139 } else {
140 fail "step to increment ($msg $i)"
141 # FIXME cascade?
142 }
143 }
144 timeout {
145 fail "step to increment ($msg $i) (timeout)"
146 }
147 }
148 }
149}
150
151# Start with a fresh gdb.
152
153gdb_exit
154gdb_start
155gdb_reinitialize_dir $srcdir/$subdir
156
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).
161if ![istarget "*-*-ultrix*"] then {
162 gdb_test "shell stty intr '^C'" ""
163}
164
165gdb_load ${binfile}
166
167gdb_test "set print sevenbit-strings" ""
168gdb_test "set width 0" ""
169
170runto_main
171
172# See if scheduler locking is available on this target.
173send_gdb "set scheduler-locking off\n"
174global gdb_prompt
175gdb_expect {
176 -re "Target .* cannot support this command"
177 {
178 unsupported "target does not support scheduler locking"
179 return
180 }
181 -re "$gdb_prompt $"
182 {
183 pass "scheduler locking set to none"
184 }
185 timeout
186 {
187 unsupported "target does not support scheduler locking (timeout)"
188 return
189 }
190}
191
192gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"]
193gdb_continue_to_breakpoint "all threads started"
194
195global list_count
196set list_count 0
197
198set start_args [get_args]
199
200# First make sure that all threads are alive.
201my_continue "initial"
202
203set cont_args [get_args]
204
18ecae38
DJ
205set ok 1
206for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
0312286c 207 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
18ecae38 208 set ok 0
0312286c
DJ
209 }
210}
18ecae38
DJ
211if { $ok } {
212 pass "all threads alive"
213} else {
214 fail "all threads alive"
215}
0312286c
DJ
216
217# We can't change threads, unfortunately, in current GDB. Use
218# whichever we stopped in.
219set curthread [get_current_thread "find current thread (1)"]
220
221
222
223
224# Test stepping without scheduler locking.
225gdb_test "set scheduler-locking off" ""
226
227step_ten_loops "unlocked"
228
229# Make sure we're still in the same thread.
230set newthread [get_current_thread "find current thread (2)"]
231if {$curthread == $newthread} {
232 pass "step without lock does not change thread"
233} else {
234 fail "step without lock does not change thread (switched to thread $newthread)"
235}
236
237set start_args $cont_args
238set cont_args [get_args]
239
a25fbfec 240set num_other_threads 0
18ecae38 241for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
0312286c
DJ
242 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
243 if {$i == $curthread} {
244 fail "current thread stepped (didn't run)"
0312286c
DJ
245 }
246 } else {
247 if {$i == $curthread} {
248 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
249 pass "current thread stepped"
250 } else {
251 fail "current thread stepped (wrong amount)"
252 }
253 } else {
a25fbfec 254 set num_other_threads [expr $num_other_threads + 1]
0312286c
DJ
255 }
256 }
257}
a25fbfec 258if {$num_other_threads > 0} {
18ecae38 259 pass "other threads ran - unlocked"
a25fbfec 260} else {
18ecae38 261 fail "other threads ran - unlocked"
a25fbfec 262}
0312286c
DJ
263
264# Test continue with scheduler locking
265gdb_test "set scheduler-locking on" ""
266
267my_continue "with lock"
268
269# Make sure we're still in the same thread.
270set newthread [get_current_thread "find current thread (3)"]
271if {$curthread == $newthread} {
272 pass "continue with lock does not change thread"
273} else {
274 fail "continue with lock does not change thread (switched to thread $newthread)"
275}
276
277set start_args $cont_args
278set cont_args [get_args]
279
18ecae38
DJ
280set num_other_threads 0
281for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
0312286c
DJ
282 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
283 if {$i == $curthread} {
284 fail "current thread ran (didn't run)"
0312286c
DJ
285 }
286 } else {
287 if {$i == $curthread} {
288 pass "current thread ran"
289 } else {
18ecae38 290 incr num_other_threads
0312286c
DJ
291 }
292 }
293}
18ecae38
DJ
294if {$num_other_threads > 0} {
295 fail "other threads didn't run - locked"
296} else {
297 pass "other threads didn't run - locked"
298}
0312286c
DJ
299
300# Test stepping with scheduler locking
301step_ten_loops "locked"
302
303# Make sure we're still in the same thread.
304set newthread [get_current_thread "find current thread (2)"]
305if {$curthread == $newthread} {
306 pass "step with lock does not change thread"
307} else {
308 fail "step with lock does not change thread (switched to thread $newthread)"
309}
310
311set start_args $cont_args
312set cont_args [get_args]
313
18ecae38
DJ
314set num_other_threads 0
315for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
0312286c
DJ
316 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
317 if {$i == $curthread} {
318 fail "current thread stepped locked (didn't run)"
0312286c
DJ
319 }
320 } else {
321 if {$i == $curthread} {
322 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
323 pass "current thread stepped locked"
324 } else {
325 fail "current thread stepped locked (wrong amount)"
326 }
327 } else {
18ecae38 328 incr num_other_threads
0312286c
DJ
329 }
330 }
331}
18ecae38
DJ
332if {$num_other_threads > 0} {
333 fail "other threads didn't run - step locked"
334} else {
335 pass "other threads didn't run - step locked"
336}
0312286c
DJ
337
338return 0
This page took 0.568907 seconds and 4 git commands to generate.