]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/schedlock.exp
This commit was manufactured by cvs2svn to create branch
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / schedlock.exp
1 # Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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.
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 set built_binfile 0
37
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"
41 } else {
42 set possible_libs "-lpthreads -lpthread -lthread"
43 }
44
45 set why_msg "unrecognized error"
46 foreach lib $possible_libs {
47 set options "debug"
48 lappend options "incdir=${objdir}/${subdir}"
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"
54 break
55 }
56 ".*cannot open -lpthread.*" {
57 set why_msg "missing runtime threads library"
58 }
59 ".*Can't find library for -lpthread.*" {
60 set why_msg "missing runtime threads library"
61 }
62 {^$} {
63 pass "successfully compiled posix threads test case"
64 set built_binfile 1
65 break
66 }
67 }
68 }
69 if {$built_binfile == "0"} {
70 unsupported "Couldn't compile ${srcfile}, ${why_msg}"
71 return -1
72 }
73
74 # Now we can proceed with the real testing.
75
76 proc get_args { } {
77 global list_count
78 global gdb_prompt
79
80 send_gdb "print args\n"
81 gdb_expect {
82 -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
83 {
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)]
87 }
88 -re "$gdb_prompt"
89 {
90 fail "listed args ($list_count) (unknown output)"
91 }
92 timeout
93 {
94 fail "listed args ($list_count) (timeout)"
95 }
96 }
97 }
98
99 proc stop_process { description } {
100 global gdb_prompt
101
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"}
105 gdb_expect {
106 -re "Program received signal SIGINT.*$gdb_prompt $"
107 {
108 pass $description
109 }
110 timeout
111 {
112 fail "$description (timeout)"
113 }
114 }
115 }
116
117 proc get_current_thread { description } {
118 global gdb_prompt
119
120 send_gdb "bt\n"
121 gdb_expect {
122 -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $"
123 {
124 pass $description
125 return $expect_out(1,string)
126 }
127 -re "$gdb_prompt $"
128 {
129 fail "$description (unknown output)"
130 }
131 timeout
132 {
133 fail "$description (timeout)"
134 }
135 }
136 }
137
138 proc my_continue { msg } {
139 send_gdb "continue\n"
140 gdb_expect {
141 -re "Continuing"
142 { pass "continue ($msg)" }
143 timeout
144 { fail "continue ($msg) (timeout)" }
145 }
146
147 stop_process "stop all threads ($msg)"
148
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)"
152 delete_breakpoints
153 }
154
155 proc step_ten_loops { msg } {
156 global gdb_prompt
157
158 for {set i 0} {[expr $i < 10]} {set i [expr $i + 1]} {
159 send_gdb "step\n"
160 set other_step 0
161 gdb_expect {
162 -re ".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" {
163 pass "step to increment ($msg $i)"
164 }
165 -re "$gdb_prompt $" {
166 if {$other_step == 0} {
167 set other_step 1
168 send_gdb "step\n"
169 exp_continue
170 } else {
171 fail "step to increment ($msg $i)"
172 # FIXME cascade?
173 }
174 }
175 timeout {
176 fail "step to increment ($msg $i) (timeout)"
177 }
178 }
179 }
180 }
181
182 # Start with a fresh gdb.
183
184 gdb_exit
185 gdb_start
186 gdb_reinitialize_dir $srcdir/$subdir
187
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'" ""
194 }
195
196 gdb_load ${binfile}
197
198 gdb_test "set print sevenbit-strings" ""
199 gdb_test "set width 0" ""
200
201 runto_main
202
203 # See if scheduler locking is available on this target.
204 send_gdb "set scheduler-locking off\n"
205 global gdb_prompt
206 gdb_expect {
207 -re "Target .* cannot support this command"
208 {
209 unsupported "target does not support scheduler locking"
210 return
211 }
212 -re "$gdb_prompt $"
213 {
214 pass "scheduler locking set to none"
215 }
216 timeout
217 {
218 unsupported "target does not support scheduler locking (timeout)"
219 return
220 }
221 }
222
223 gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"]
224 gdb_continue_to_breakpoint "all threads started"
225
226 global list_count
227 set list_count 0
228
229 set start_args [get_args]
230
231 # First make sure that all threads are alive.
232 my_continue "initial"
233
234 set cont_args [get_args]
235
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)"
239 } else {
240 pass "thread $i ran"
241 }
242 }
243
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)"]
247
248
249
250
251 # Test stepping without scheduler locking.
252 gdb_test "set scheduler-locking off" ""
253
254 step_ten_loops "unlocked"
255
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"
260 } else {
261 fail "step without lock does not change thread (switched to thread $newthread)"
262 }
263
264 set start_args $cont_args
265 set cont_args [get_args]
266
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)"
271 } else {
272 fail "other thread $i ran (didn't run) (1)"
273 }
274 } else {
275 if {$i == $curthread} {
276 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
277 pass "current thread stepped"
278 } else {
279 fail "current thread stepped (wrong amount)"
280 }
281 } else {
282 pass "other thread $i ran (1)"
283 }
284 }
285 }
286
287 # Test continue with scheduler locking
288 gdb_test "set scheduler-locking on" ""
289
290 my_continue "with lock"
291
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"
296 } else {
297 fail "continue with lock does not change thread (switched to thread $newthread)"
298 }
299
300 set start_args $cont_args
301 set cont_args [get_args]
302
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)"
307 } else {
308 pass "other thread $i didn't run"
309 }
310 } else {
311 if {$i == $curthread} {
312 pass "current thread ran"
313 } else {
314 fail "other thread $i didn't run (ran)"
315 }
316 }
317 }
318
319 # Test stepping with scheduler locking
320 step_ten_loops "locked"
321
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"
326 } else {
327 fail "step with lock does not change thread (switched to thread $newthread)"
328 }
329
330 set start_args $cont_args
331 set cont_args [get_args]
332
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)"
337 } else {
338 pass "other thread $i didn't run (stepping)"
339 }
340 } else {
341 if {$i == $curthread} {
342 if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} {
343 pass "current thread stepped locked"
344 } else {
345 fail "current thread stepped locked (wrong amount)"
346 }
347 } else {
348 fail "other thread $i didn't run (stepping) (ran)"
349 }
350 }
351 }
352
353 return 0