Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
18ecae38 DJ |
36 | # The number of threads, including the main thread. |
37 | set NUM 2 | |
38 | ||
b5ab8ff3 | 39 | if {[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 | ||
45 | proc 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 | ||
68 | proc 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 | ||
86 | proc 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 | ||
107 | proc 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 | ||
124 | proc 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 | ||
153 | gdb_exit | |
154 | gdb_start | |
155 | gdb_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). | |
161 | if ![istarget "*-*-ultrix*"] then { | |
162 | gdb_test "shell stty intr '^C'" "" | |
163 | } | |
164 | ||
165 | gdb_load ${binfile} | |
166 | ||
167 | gdb_test "set print sevenbit-strings" "" | |
168 | gdb_test "set width 0" "" | |
169 | ||
170 | runto_main | |
171 | ||
172 | # See if scheduler locking is available on this target. | |
173 | send_gdb "set scheduler-locking off\n" | |
174 | global gdb_prompt | |
175 | gdb_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 | ||
192 | gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"] | |
193 | gdb_continue_to_breakpoint "all threads started" | |
194 | ||
195 | global list_count | |
196 | set list_count 0 | |
197 | ||
198 | set start_args [get_args] | |
199 | ||
200 | # First make sure that all threads are alive. | |
201 | my_continue "initial" | |
202 | ||
203 | set cont_args [get_args] | |
204 | ||
18ecae38 DJ |
205 | set ok 1 |
206 | for {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 |
211 | if { $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. | |
219 | set curthread [get_current_thread "find current thread (1)"] | |
220 | ||
221 | ||
222 | ||
223 | ||
224 | # Test stepping without scheduler locking. | |
225 | gdb_test "set scheduler-locking off" "" | |
226 | ||
227 | step_ten_loops "unlocked" | |
228 | ||
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" | |
233 | } else { | |
234 | fail "step without lock does not change thread (switched to thread $newthread)" | |
235 | } | |
236 | ||
237 | set start_args $cont_args | |
238 | set cont_args [get_args] | |
239 | ||
a25fbfec | 240 | set num_other_threads 0 |
18ecae38 | 241 | for {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 | 258 | if {$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 | |
265 | gdb_test "set scheduler-locking on" "" | |
266 | ||
267 | my_continue "with lock" | |
268 | ||
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" | |
273 | } else { | |
274 | fail "continue with lock does not change thread (switched to thread $newthread)" | |
275 | } | |
276 | ||
277 | set start_args $cont_args | |
278 | set cont_args [get_args] | |
279 | ||
18ecae38 DJ |
280 | set num_other_threads 0 |
281 | for {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 |
294 | if {$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 | |
301 | step_ten_loops "locked" | |
302 | ||
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" | |
307 | } else { | |
308 | fail "step with lock does not change thread (switched to thread $newthread)" | |
309 | } | |
310 | ||
311 | set start_args $cont_args | |
312 | set cont_args [get_args] | |
313 | ||
18ecae38 DJ |
314 | set num_other_threads 0 |
315 | for {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 |
332 | if {$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 | |
338 | return 0 |