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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.threads/] [schedlock.exp] - Blame information for rev 175

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

Line No. Rev Author Line
1 24 jeremybenn
# 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 .
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 
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
 
49
  send_gdb "print args\n"
50
  gdb_expect {
51
    -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
52
      {
53
        set list_count [expr $list_count + 1]
54
        pass "listed args ($list_count)"
55
        return [list $expect_out(1,string) $expect_out(2,string)]
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
 
118
  # Make sure we're in one of the non-main looping threads.
119
  gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"]
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
 
205
set ok 1
206
for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
207
  if {[lindex $start_args $i] == [lindex $cont_args $i]} {
208
    set ok 0
209
  }
210
}
211
if { $ok } {
212
  pass "all threads alive"
213
} else {
214
  fail "all threads alive"
215
}
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
 
240
set num_other_threads 0
241
for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
242
  if {[lindex $start_args $i] == [lindex $cont_args $i]} {
243
    if {$i == $curthread} {
244
      fail "current thread stepped (didn't run)"
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 {
254
      set num_other_threads [expr $num_other_threads + 1]
255
    }
256
  }
257
}
258
if {$num_other_threads > 0} {
259
  pass "other threads ran - unlocked"
260
} else {
261
  fail "other threads ran - unlocked"
262
}
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
 
280
set num_other_threads 0
281
for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
282
  if {[lindex $start_args $i] == [lindex $cont_args $i]} {
283
    if {$i == $curthread} {
284
      fail "current thread ran (didn't run)"
285
    }
286
  } else {
287
    if {$i == $curthread} {
288
      pass "current thread ran"
289
    } else {
290
      incr num_other_threads
291
    }
292
  }
293
}
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
}
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
 
314
set num_other_threads 0
315
for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
316
  if {[lindex $start_args $i] == [lindex $cont_args $i]} {
317
    if {$i == $curthread} {
318
      fail "current thread stepped locked (didn't run)"
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 {
328
      incr num_other_threads
329
    }
330
  }
331
}
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
}
337
 
338
return 0

powered by: WebSVN 2.1.0

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