]>
Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright (C) 1996-2014 Free Software Foundation, Inc. |
0312286c DJ |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
0312286c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
0312286c DJ |
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. | |
e22f8b7c | 12 | # |
0312286c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0312286c | 15 | |
0312286c DJ |
16 | # This file was written by Daniel Jacobowitz <drow@mvista.com> |
17 | # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com). | |
18 | # | |
19 | # This test covers the various forms of "set scheduler-locking". | |
20 | ||
0312286c | 21 | |
0efbbabc | 22 | standard_testfile |
0312286c | 23 | |
18ecae38 DJ |
24 | # The number of threads, including the main thread. |
25 | set NUM 2 | |
26 | ||
0efbbabc | 27 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { |
0312286c DJ |
28 | return -1 |
29 | } | |
30 | ||
31 | # Now we can proceed with the real testing. | |
32 | ||
33 | proc get_args { } { | |
9db70545 MS |
34 | global list_count |
35 | global gdb_prompt | |
36 | global NUM | |
e09490f1 | 37 | |
9db70545 MS |
38 | set pattern "(\[0-9\]+)" |
39 | for {set i 1} {[expr $i < $NUM]} {incr i} { | |
40 | append pattern ", (\[0-9\]+)" | |
41 | } | |
0312286c | 42 | |
9db70545 MS |
43 | gdb_test_multiple "print args" "listed args ($list_count)" { |
44 | -re "\\\$\[0-9\]+ = {$pattern}.*$gdb_prompt $" { | |
45 | set list_count [expr $list_count + 1] | |
46 | pass "listed args ($list_count)" | |
e09490f1 | 47 | |
9db70545 MS |
48 | set result "" |
49 | for {set i 1} {[expr $i <= $NUM]} {incr i} { | |
50 | lappend result $expect_out($i,string) | |
51 | } | |
52 | return $result | |
e09490f1 | 53 | } |
9db70545 | 54 | } |
0312286c DJ |
55 | } |
56 | ||
57 | proc stop_process { description } { | |
58 | global gdb_prompt | |
59 | ||
60 | # For this to work we must be sure to consume the "Continuing." | |
61 | # message first, or GDB's signal handler may not be in place. | |
62 | after 1000 {send_gdb "\003"} | |
63 | gdb_expect { | |
64 | -re "Program received signal SIGINT.*$gdb_prompt $" | |
65 | { | |
66 | pass $description | |
67 | } | |
68 | timeout | |
69 | { | |
70 | fail "$description (timeout)" | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | proc get_current_thread { description } { | |
9db70545 | 76 | global gdb_prompt |
0312286c | 77 | |
9db70545 MS |
78 | gdb_test_multiple "bt" "$description" { |
79 | -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $" { | |
80 | pass $description | |
81 | return $expect_out(1,string) | |
82 | } | |
83 | } | |
84 | return "" | |
0312286c DJ |
85 | } |
86 | ||
87 | proc my_continue { msg } { | |
9db70545 MS |
88 | gdb_test_multiple "continue" "continuing ($msg)" { |
89 | -re "Continuing" { | |
90 | pass "continue ($msg)" | |
91 | } | |
92 | } | |
0312286c | 93 | |
9db70545 | 94 | stop_process "stop all threads ($msg)" |
0312286c | 95 | |
9db70545 MS |
96 | # Make sure we're in one of the non-main looping threads. |
97 | gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"] | |
98 | gdb_continue_to_breakpoint "return to loop ($msg)" | |
99 | delete_breakpoints | |
0312286c DJ |
100 | } |
101 | ||
102 | proc step_ten_loops { msg } { | |
103 | global gdb_prompt | |
104 | ||
105 | for {set i 0} {[expr $i < 10]} {set i [expr $i + 1]} { | |
0312286c | 106 | set other_step 0 |
9db70545 | 107 | gdb_test_multiple "step" "step to increment ($msg $i)" { |
0312286c DJ |
108 | -re ".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" { |
109 | pass "step to increment ($msg $i)" | |
110 | } | |
111 | -re "$gdb_prompt $" { | |
112 | if {$other_step == 0} { | |
113 | set other_step 1 | |
114 | send_gdb "step\n" | |
115 | exp_continue | |
116 | } else { | |
117 | fail "step to increment ($msg $i)" | |
118 | # FIXME cascade? | |
119 | } | |
120 | } | |
0312286c DJ |
121 | } |
122 | } | |
123 | } | |
124 | ||
125 | # Start with a fresh gdb. | |
126 | ||
127 | gdb_exit | |
128 | gdb_start | |
129 | gdb_reinitialize_dir $srcdir/$subdir | |
130 | ||
131 | # We'll need this when we send_gdb a ^C to GDB. Need to do it before we | |
132 | # run the program and gdb starts saving and restoring tty states. | |
133 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
134 | # doesn't use vfork). | |
135 | if ![istarget "*-*-ultrix*"] then { | |
f6978de9 | 136 | gdb_test "shell stty intr '^C'" ".*" |
0312286c DJ |
137 | } |
138 | ||
139 | gdb_load ${binfile} | |
140 | ||
12b5d08a MS |
141 | gdb_test_no_output "set print sevenbit-strings" |
142 | gdb_test_no_output "set width 0" | |
0312286c DJ |
143 | |
144 | runto_main | |
145 | ||
146 | # See if scheduler locking is available on this target. | |
0312286c | 147 | global gdb_prompt |
9db70545 MS |
148 | gdb_test_multiple "set scheduler-locking off" "scheduler locking set to none" { |
149 | -re "Target .* cannot support this command" { | |
150 | unsupported "target does not support scheduler locking" | |
151 | return | |
0312286c | 152 | } |
9db70545 MS |
153 | -re "$gdb_prompt $" { |
154 | pass "scheduler locking set to none" | |
0312286c | 155 | } |
9db70545 MS |
156 | timeout { |
157 | unsupported "target does not support scheduler locking (timeout)" | |
158 | return | |
0312286c DJ |
159 | } |
160 | } | |
161 | ||
162 | gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"] | |
163 | gdb_continue_to_breakpoint "all threads started" | |
164 | ||
165 | global list_count | |
166 | set list_count 0 | |
167 | ||
168 | set start_args [get_args] | |
169 | ||
170 | # First make sure that all threads are alive. | |
171 | my_continue "initial" | |
172 | ||
173 | set cont_args [get_args] | |
174 | ||
e09490f1 | 175 | set bad 0 |
18ecae38 | 176 | for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { |
0312286c | 177 | if {[lindex $start_args $i] == [lindex $cont_args $i]} { |
e09490f1 | 178 | incr bad |
0312286c DJ |
179 | } |
180 | } | |
e09490f1 | 181 | if { $bad == 0 } { |
18ecae38 DJ |
182 | pass "all threads alive" |
183 | } else { | |
e09490f1 | 184 | fail "all threads alive ($bad/$NUM did not run)" |
18ecae38 | 185 | } |
0312286c DJ |
186 | |
187 | # We can't change threads, unfortunately, in current GDB. Use | |
188 | # whichever we stopped in. | |
189 | set curthread [get_current_thread "find current thread (1)"] | |
190 | ||
191 | ||
192 | ||
193 | ||
194 | # Test stepping without scheduler locking. | |
12b5d08a | 195 | gdb_test_no_output "set scheduler-locking off" |
0312286c DJ |
196 | |
197 | step_ten_loops "unlocked" | |
198 | ||
199 | # Make sure we're still in the same thread. | |
200 | set newthread [get_current_thread "find current thread (2)"] | |
201 | if {$curthread == $newthread} { | |
202 | pass "step without lock does not change thread" | |
203 | } else { | |
204 | fail "step without lock does not change thread (switched to thread $newthread)" | |
205 | } | |
206 | ||
207 | set start_args $cont_args | |
208 | set cont_args [get_args] | |
209 | ||
a25fbfec | 210 | set num_other_threads 0 |
18ecae38 | 211 | for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { |
0312286c DJ |
212 | if {[lindex $start_args $i] == [lindex $cont_args $i]} { |
213 | if {$i == $curthread} { | |
214 | fail "current thread stepped (didn't run)" | |
0312286c DJ |
215 | } |
216 | } else { | |
217 | if {$i == $curthread} { | |
218 | if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} { | |
219 | pass "current thread stepped" | |
220 | } else { | |
221 | fail "current thread stepped (wrong amount)" | |
222 | } | |
223 | } else { | |
a25fbfec | 224 | set num_other_threads [expr $num_other_threads + 1] |
0312286c DJ |
225 | } |
226 | } | |
227 | } | |
a25fbfec | 228 | if {$num_other_threads > 0} { |
18ecae38 | 229 | pass "other threads ran - unlocked" |
a25fbfec | 230 | } else { |
18ecae38 | 231 | fail "other threads ran - unlocked" |
a25fbfec | 232 | } |
0312286c DJ |
233 | |
234 | # Test continue with scheduler locking | |
12b5d08a | 235 | gdb_test "set scheduler-locking on" "" |
0312286c DJ |
236 | |
237 | my_continue "with lock" | |
238 | ||
239 | # Make sure we're still in the same thread. | |
240 | set newthread [get_current_thread "find current thread (3)"] | |
241 | if {$curthread == $newthread} { | |
242 | pass "continue with lock does not change thread" | |
243 | } else { | |
244 | fail "continue with lock does not change thread (switched to thread $newthread)" | |
245 | } | |
246 | ||
247 | set start_args $cont_args | |
248 | set cont_args [get_args] | |
249 | ||
18ecae38 DJ |
250 | set num_other_threads 0 |
251 | for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { | |
0312286c DJ |
252 | if {[lindex $start_args $i] == [lindex $cont_args $i]} { |
253 | if {$i == $curthread} { | |
254 | fail "current thread ran (didn't run)" | |
0312286c DJ |
255 | } |
256 | } else { | |
257 | if {$i == $curthread} { | |
258 | pass "current thread ran" | |
259 | } else { | |
18ecae38 | 260 | incr num_other_threads |
0312286c DJ |
261 | } |
262 | } | |
263 | } | |
18ecae38 DJ |
264 | if {$num_other_threads > 0} { |
265 | fail "other threads didn't run - locked" | |
266 | } else { | |
267 | pass "other threads didn't run - locked" | |
268 | } | |
0312286c DJ |
269 | |
270 | # Test stepping with scheduler locking | |
271 | step_ten_loops "locked" | |
272 | ||
273 | # Make sure we're still in the same thread. | |
274 | set newthread [get_current_thread "find current thread (2)"] | |
275 | if {$curthread == $newthread} { | |
276 | pass "step with lock does not change thread" | |
277 | } else { | |
278 | fail "step with lock does not change thread (switched to thread $newthread)" | |
279 | } | |
280 | ||
281 | set start_args $cont_args | |
282 | set cont_args [get_args] | |
283 | ||
18ecae38 DJ |
284 | set num_other_threads 0 |
285 | for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} { | |
0312286c DJ |
286 | if {[lindex $start_args $i] == [lindex $cont_args $i]} { |
287 | if {$i == $curthread} { | |
288 | fail "current thread stepped locked (didn't run)" | |
0312286c DJ |
289 | } |
290 | } else { | |
291 | if {$i == $curthread} { | |
292 | if {[lindex $start_args $i] == [expr [lindex $cont_args $i] - 10]} { | |
293 | pass "current thread stepped locked" | |
294 | } else { | |
295 | fail "current thread stepped locked (wrong amount)" | |
296 | } | |
297 | } else { | |
18ecae38 | 298 | incr num_other_threads |
0312286c DJ |
299 | } |
300 | } | |
301 | } | |
18ecae38 DJ |
302 | if {$num_other_threads > 0} { |
303 | fail "other threads didn't run - step locked" | |
304 | } else { | |
305 | pass "other threads didn't run - step locked" | |
306 | } | |
0312286c DJ |
307 | |
308 | return 0 |