* linux-nat.c (count_events_callback, select_event_lwp_callback): Only
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / schedlock.exp
1 # Copyright (C) 1996, 1997, 2002, 2003, 2007, 2008
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
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/>.
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
25 if $tracelevel then {
26 strace $tracelevel
27 }
28
29 set prms_id 0
30 set bug_id 0
31
32 set testfile "schedlock"
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
35
36 # The number of threads, including the main thread.
37 set NUM 2
38
39 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
40 return -1
41 }
42
43 # Now we can proceed with the real testing.
44
45 proc get_args { } {
46 global list_count
47 global gdb_prompt
48 global NUM
49
50 set pattern "(\[0-9\]+)"
51 for {set i 1} {[expr $i < $NUM]} {incr i} {
52 append pattern ", (\[0-9\]+)"
53 }
54
55 send_gdb "print args\n"
56 gdb_expect {
57 -re "\\\$\[0-9\]+ = {$pattern}.*$gdb_prompt"
58 {
59 set list_count [expr $list_count + 1]
60 pass "listed args ($list_count)"
61
62 set result ""
63 for {set i 1} {[expr $i <= $NUM]} {incr i} {
64 lappend result $expect_out($i,string)
65 }
66 return $result
67 }
68 -re "$gdb_prompt"
69 {
70 fail "listed args ($list_count) (unknown output)"
71 }
72 timeout
73 {
74 fail "listed args ($list_count) (timeout)"
75 }
76 }
77 }
78
79 proc stop_process { description } {
80 global gdb_prompt
81
82 # For this to work we must be sure to consume the "Continuing."
83 # message first, or GDB's signal handler may not be in place.
84 after 1000 {send_gdb "\003"}
85 gdb_expect {
86 -re "Program received signal SIGINT.*$gdb_prompt $"
87 {
88 pass $description
89 }
90 timeout
91 {
92 fail "$description (timeout)"
93 }
94 }
95 }
96
97 proc get_current_thread { description } {
98 global gdb_prompt
99
100 send_gdb "bt\n"
101 gdb_expect {
102 -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $"
103 {
104 pass $description
105 return $expect_out(1,string)
106 }
107 -re "$gdb_prompt $"
108 {
109 fail "$description (unknown output)"
110 }
111 timeout
112 {
113 fail "$description (timeout)"
114 }
115 }
116 }
117
118 proc my_continue { msg } {
119 send_gdb "continue\n"
120 gdb_expect {
121 -re "Continuing"
122 { pass "continue ($msg)" }
123 timeout
124 { fail "continue ($msg) (timeout)" }
125 }
126
127 stop_process "stop all threads ($msg)"
128
129 # Make sure we're in one of the non-main looping threads.
130 gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"]
131 gdb_continue_to_breakpoint "return to loop ($msg)"
132 delete_breakpoints
133 }
134
135 proc step_ten_loops { msg } {
136 global gdb_prompt
137
138 for {set i 0} {[expr $i < 10]} {set i [expr $i + 1]} {
139 send_gdb "step\n"
140 set other_step 0
141 gdb_expect {
142 -re ".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" {
143 pass "step to increment ($msg $i)"
144 }
145 -re "$gdb_prompt $" {
146 if {$other_step == 0} {
147 set other_step 1
148 send_gdb "step\n"
149 exp_continue
150 } else {
151 fail "step to increment ($msg $i)"
152 # FIXME cascade?
153 }
154 }
155 timeout {
156 fail "step to increment ($msg $i) (timeout)"
157 }
158 }
159 }
160 }
161
162 # Start with a fresh gdb.
163
164 gdb_exit
165 gdb_start
166 gdb_reinitialize_dir $srcdir/$subdir
167
168 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
169 # run the program and gdb starts saving and restoring tty states.
170 # On Ultrix, we don't need it and it is really slow (because shell_escape
171 # doesn't use vfork).
172 if ![istarget "*-*-ultrix*"] then {
173 gdb_test "shell stty intr '^C'" ""
174 }
175
176 gdb_load ${binfile}
177
178 gdb_test "set print sevenbit-strings" ""
179 gdb_test "set width 0" ""
180
181 runto_main
182
183 # See if scheduler locking is available on this target.
184 send_gdb "set scheduler-locking off\n"
185 global gdb_prompt
186 gdb_expect {
187 -re "Target .* cannot support this command"
188 {
189 unsupported "target does not support scheduler locking"
190 return
191 }
192 -re "$gdb_prompt $"
193 {
194 pass "scheduler locking set to none"
195 }
196 timeout
197 {
198 unsupported "target does not support scheduler locking (timeout)"
199 return
200 }
201 }
202
203 gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"]
204 gdb_continue_to_breakpoint "all threads started"
205
206 global list_count
207 set list_count 0
208
209 set start_args [get_args]
210
211 # First make sure that all threads are alive.
212 my_continue "initial"
213
214 set cont_args [get_args]
215
216 set bad 0
217 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
218 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
219 incr bad
220 }
221 }
222 if { $bad == 0 } {
223 pass "all threads alive"
224 } else {
225 fail "all threads alive ($bad/$NUM did not run)"
226 }
227
228 # We can't change threads, unfortunately, in current GDB. Use
229 # whichever we stopped in.
230 set curthread [get_current_thread "find current thread (1)"]
231
232
233
234
235 # Test stepping without scheduler locking.
236 gdb_test "set scheduler-locking off" ""
237
238 step_ten_loops "unlocked"
239
240 # Make sure we're still in the same thread.
241 set newthread [get_current_thread "find current thread (2)"]
242 if {$curthread == $newthread} {
243 pass "step without lock does not change thread"
244 } else {
245 fail "step without lock does not change thread (switched to thread $newthread)"
246 }
247
248 set start_args $cont_args
249 set cont_args [get_args]
250
251 set num_other_threads 0
252 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
253 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
254 if {$i == $curthread} {
255 fail "current thread stepped (didn't run)"
256 }
257 } else {
258 if {$i == $curthread} {
259 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
260 pass "current thread stepped"
261 } else {
262 fail "current thread stepped (wrong amount)"
263 }
264 } else {
265 set num_other_threads [expr $num_other_threads + 1]
266 }
267 }
268 }
269 if {$num_other_threads > 0} {
270 pass "other threads ran - unlocked"
271 } else {
272 fail "other threads ran - unlocked"
273 }
274
275 # Test continue with scheduler locking
276 gdb_test "set scheduler-locking on" ""
277
278 my_continue "with lock"
279
280 # Make sure we're still in the same thread.
281 set newthread [get_current_thread "find current thread (3)"]
282 if {$curthread == $newthread} {
283 pass "continue with lock does not change thread"
284 } else {
285 fail "continue with lock does not change thread (switched to thread $newthread)"
286 }
287
288 set start_args $cont_args
289 set cont_args [get_args]
290
291 set num_other_threads 0
292 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
293 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
294 if {$i == $curthread} {
295 fail "current thread ran (didn't run)"
296 }
297 } else {
298 if {$i == $curthread} {
299 pass "current thread ran"
300 } else {
301 incr num_other_threads
302 }
303 }
304 }
305 if {$num_other_threads > 0} {
306 fail "other threads didn't run - locked"
307 } else {
308 pass "other threads didn't run - locked"
309 }
310
311 # Test stepping with scheduler locking
312 step_ten_loops "locked"
313
314 # Make sure we're still in the same thread.
315 set newthread [get_current_thread "find current thread (2)"]
316 if {$curthread == $newthread} {
317 pass "step with lock does not change thread"
318 } else {
319 fail "step with lock does not change thread (switched to thread $newthread)"
320 }
321
322 set start_args $cont_args
323 set cont_args [get_args]
324
325 set num_other_threads 0
326 for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
327 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
328 if {$i == $curthread} {
329 fail "current thread stepped locked (didn't run)"
330 }
331 } else {
332 if {$i == $curthread} {
333 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
334 pass "current thread stepped locked"
335 } else {
336 fail "current thread stepped locked (wrong amount)"
337 }
338 } else {
339 incr num_other_threads
340 }
341 }
342 }
343 if {$num_other_threads > 0} {
344 fail "other threads didn't run - step locked"
345 } else {
346 pass "other threads didn't run - step locked"
347 }
348
349 return 0
This page took 0.046779 seconds and 5 git commands to generate.