OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.threads/] [schedlock.exp] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.