summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.hp/start-stop.exp
blob: 4f70f51cedecee0a6a7c451e71b42094e87778e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# start_stop.exp -- Expect script to test a threaded pgm which has terminating threads
# Copyright (C) 1992 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# Comment out for now, since this test is (sometimes?) hanging on 11.0
#
# return 0

# use this to debug:
#
#log_user 1

# Thread stuff is _slow_; prepare for long waits.
#
# Further, this test has some "null" lines designed
# to consume output from gdb that was too late to be
# matched (sequence is "gdb_test" sends; timeout and
# on to next send; result finally comes in; mismatch).
#
# The null command is 'gdb_test "p \$pc" ".*" ""'
# NOTE: this command undoes any up/down stuff!
#
proc pre_timeout {} {
    global timeout

    set timeout [expr "$timeout + 100"]
}

proc post_timeout {} {
    global timeout
    global oldtimeout

    set timeout $oldtimeout
    gdb_test "p \$pc" ".*" ""
}

if $tracelevel then {
    strace $tracelevel
}

if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
    verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
    return 0
}

set testfile start-stop
set srcfile ${srcdir}/${subdir}/${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}

if [get_compiler_info ${binfile}] {
    return -1
}

# To build the executable we need to link against the thread library.
#
#     cc -Ae -g -o start-stop -lpthread start-stop.c
#
#compile "${srcfile} -Ae -g -lpthread -o ${binfile}"

if {$gcc_compiled == 0} {
    set additional_flags "additional_flags=-Ae"
} else {
    set additional_flags ""
}

if  { [gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}.o" object [list debug $additional_flags]] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}
remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread  -lc /opt/langtools/lib/end.o -o ${binfile}"


gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

gdb_load ${binfile}
if ![runto_main] then {
   fail "Can't run to main"
   return 0
}

set oldtimeout $timeout
#set timeout [expr "$timeout + 200"]
set oldverbose $verbose
#set verbose 40

gdb_test "b do_pass" ".*" "set do_pass bp"
gdb_test "c" ".*Breakpoint.*do_pass.*" "run to do_pass"

# Should be only one thread.
#
pre_timeout
send_gdb "info thread\n"
gdb_expect {
    -re ".*2 process.*$gdb_prompt $" { fail "Old code for 'thread.c'" }
    -re ".*2 system thread.*1 sys.*$gdb_prompt $" { fail "Too many threads" }
    -re ".*1 system thread.*$gdb_prompt $" { pass "Just one thread" }
    -re ".*$gdb_prompt $" { fail "no thread info" }
    timeout { fail "timeout on info thread 1" }
}
post_timeout

# Run to a point after the thread creates (105 is just
# before the first join).
#
# The "== Thread" stuff is output from the computing threads.
#
gdb_test "b 105" ".*Breakpoint.*" "set 105 bp"

pre_timeout
send_gdb "c\n"
gdb_expect {
    -re ".*== Thread.*== Thread.*== Thread.*105.*$gdb_prompt $" {
        pass "new threads created and ended"
        set threads_exist 0
    }
    -re ".*== Thread.*== Thread.*105.*$gdb_prompt $" {
        pass "new threads created and ended"
        set threads_exist 1
    }
    -re ".*== Thread.*.*105.*$gdb_prompt $" {
        pass "new threads created and ended"
        set threads_exist 2
    }
    -re ".*New thread.*New th.*New th.*105.*$gdb_prompt $" { 
        pass "new threads created" 
        set threads_exist 3
    }
    -re ".*Breakpoint.*105.*$gdb_prompt $" {
        set threads_exist 0
        fail "didn't see any threads" 
    }
    -re ".*$gdb_prompt $" {
        set threads_exist 0
        fail "didn't even hit bp"
    }
    timeout { 
        set threads_exist -1 
        fail "timeout on continue" 
    }
}

# Look at the threads again.  We expect that some of
# the threads may have already finished execution.
#
send_gdb "info thread\n" 
gdb_expect {
    -re ".*4.*3.*2.* 1.*thread.*$gdb_prompt $" { set seen_threads 3 }
    -re ".*3.*2.* 1.*thread.*$gdb_prompt $"    { set seen_threads 2 }
    -re ".*2.* 1.*thread.*$gdb_prompt $"       { set seen_threads 1 }
    -re ".* 1.*thread.*$gdb_prompt $"          { set seen_threads 0 }
    -re ".*$gdb_prompt $"                      { set seen_threads 0 }
    timeout          { 
        set seen_threads -10
        fail "timeout on second info thread" 
    }
}
post_timeout

if { $seen_threads == $threads_exist } {
    pass "saw all threads that existed"
} else {
    if { $seen_threads > $threads_exist } {
        fail "may have seen threads that didn't finish exiting yet"
    } else {
        fail "didn't see live threads"
    }
}

gdb_test "cle"  ".*Deleted.*" "del bp at 105"

# Check that threads are being consumed at the join call.
# We expect to join three times.  If we ever see the bp at
# 111, we've gone too far.
#
gdb_test "b 106" ".*Breakpoint.*106.*" "set bp at 106"
gdb_test "b 111" ".*Breakpoint.*111.*" "set bp at 111"

# This one is sure: we're already in the loop.
#
gdb_test "c"    ".*Breakpoint.*106.*" "hit bp at 106 1st time, 2 left"

# Did we go around the loop again?
#
send_gdb "c\n"
gdb_expect {
    -re ".*Breakpoint.*111.*" { 
        fail "didn't join right 1" 
        gdb_test "cle" ".*" ""
    }
    -re ".*Breakpoint.*106.*" { 
        pass "hit bp at 106 2nd time, 1 left" 
        send_gdb "c\n" 
        gdb_expect {
            -re ".*Breakpoint.*111.*" { 
                 fail "didn't join right 2" 
                 gdb_test "cle" ".*" ""
            }
            -re ".*Breakpoint.*106.*" { 
                 pass "hit bp at 106 3rd time, 0 left"
                 gdb_test "cle" ".*" ""
                 gdb_test "c" ".*Breakpoint.*111.*" ""
                 gdb_test "cle" ".*" ""
            }
            timeout { fail "timeout going around the loop"}
        }
    }
    timeout { fail "timeout getting to 106"}
}

# Should only be one thread now.
#
pre_timeout
send_gdb "info thread\n"
gdb_expect {
    -re ".*2 system thread.*1 sys.*$gdb_prompt $" { fail "Too many threads" }
    -re ".*1 system th.*$gdb_prompt $"            { pass "Just one thread"  }
    -re ".*$gdb_prompt $"     { pass "One thread shown as no threads, ok" }
    timeout               { fail "timeout third info thread" }
}
post_timeout

#============================= Begin pass 2 ===========
#
# Ok, go around again
#
gdb_test "c" ".*Breakpoint.*do_pass.*" "hit do_pass bp again 2"
gdb_test "b 105" ".*Breakpoint.*" "set 105 bp 2"

pre_timeout
send_gdb "c\n"
gdb_expect {
    -re ".*== Thread.*== Thread.*== Thread.*$gdb_prompt $" {
        pass "new threads created and ended 2"
        set threads_exist 0
    }
    -re ".*== Thread.*== Thread.*$gdb_prompt $" {
        pass "new threads created and ended 2"
        set threads_exist 1
    }
    -re ".*== Thread.*$gdb_prompt $" {
        pass "new threads created and ended 2"
        set threads_exist 2
    }
    -re ".*New system thread.*New sys.*New.*105.*$gdb_prompt $" { 
        pass "new threads created 2" 
        set threads_exist 3
    }
    timeout { 
        set threads_exist -1 
        fail "timeout on continue 2" 
    }
}

# Look at the threads again.  We expect that some of
# the threads may have already finished execution.
#
send_gdb "info thread\n" 
gdb_expect {
    -re ".*4.*3.*2.* 1.*thread.*$gdb_prompt $" { set seen_threads 3 }
    -re ".*3.*2.* 1.*thread.*$gdb_prompt $"    { set seen_threads 2 }
    -re ".*2.* 1.*thread.*$gdb_prompt $"       { set seen_threads 1 }
    -re ".* 1.*thread.*$gdb_prompt $"          { set seen_threads 0 }
    -re ".*$gdb_prompt $"                      { set seen_threads 0 }
    timeout          { 
        set seen_threads -10
        fail "timeout on second info thread 2" 
    }
}
post_timeout

if { $seen_threads == $threads_exist } {
    pass "saw all threads that existed"
} else {
    if { $seen_threads > $threads_exist } {
        fail "may have seen threads that didn't finish exiting yet 2"
    } else {
        fail "didn't see live threads 2"
    }
}

gdb_test "cle"  ".*Deleted.*" "del bp at 105 2"

# Check that threads are being consumed at the join call.
# We expect to join three times.  If we ever see the bp at
# 111, we've gone too far.
#
gdb_test "b 106" ".*Breakpoint.*106.*" "set bp at 106 2"
gdb_test "b 111" ".*Breakpoint.*111.*" "set bp at 111 2"

# This one is sure: we're already in the loop.
#
gdb_test "c"  ".*Breakpoint.*106.*" "hit bp at 106 1st time, 2 left 2"

# Did we go around the loop again?
#
send_gdb "c\n"
gdb_expect {
    -re ".*Breakpoint.*111.*" { 
        fail "didn't join right 1, pass 2" 
        gdb_test "cle" ".*" ""
    }
    -re ".*Breakpoint.*106.*" { 
        pass "hit bp at 106 2nd time, 1 left, pass 2" 
        send_gdb "c\n" 
        gdb_expect {
            -re ".*Breakpoint.*111.*" { 
                 fail "didn't join right 2, pass 2" 
                 gdb_test "cle" ".*" ""
            }
            -re ".*Breakpoint.*106.*" { 
                 pass "hit bp at 106 3rd time, 0 left, pass 2"
                 gdb_test "cle" ".*" ""
                 gdb_test "c" ".*Breakpoint.*111.*" ""
                 gdb_test "cle" ".*" ""
            }
            timeout { fail "timeout going around loop, pass 2"}
        }
    }
    timeout { fail "timeout continue to 106, pass 2"}
}

# Should only be one thread now.
#
pre_timeout
send_gdb "info thread\n"
gdb_expect {
    -re ".*2 system thread.*1 sys.*$gdb_prompt $" { fail "Too many threads, pass 2" }
    -re ".*1 system thread.*$gdb_prompt $" { pass "Just one thread, pass 2" }
    -re ".*$gdb_prompt $" { pass "One thread shown as no threads, ok, pass 2" }
    timeout { fail "timeout last info thread, pass 2" }
}
post_timeout

# Done!
#
gdb_exit

set timeout $oldtimeout
set verbose $oldverbose

# execute_anywhere "rm -f ${binfile}"
#
return 0