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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.threads/] [attachstop-mt.exp] - Blame information for rev 318

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

Line No. Rev Author Line
1 227 jeremybenn
# Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
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
5
# the Free Software Foundation; either version 3 of the License, or
6
# (at your option) any later version.
7
#
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.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see .
15
 
16
# This test is based on gdb.base/attach.exp with modifications by Jeff Johnston
17
#  and Jan Kratochvil .
18
 
19
# This test only works on Linux
20
if { ![isnative] || [is_remote host] || ![istarget *-linux*] } {
21
    continue
22
}
23
 
24
set testfile "attachstop-mt"
25
set srcfile  ${testfile}.c
26
set binfile  ${objdir}/${subdir}/${testfile}
27
set escapedbinfile  [string_to_regexp ${objdir}/${subdir}/${testfile}]
28
 
29
#execute_anywhere "rm -f ${binfile}"
30
remote_exec build "rm -f ${binfile}"
31
# For debugging this test
32
#
33
#log_user 1
34
 
35
# build the test case
36
#
37
if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
38
    untested attachstop-mt.exp
39
    return -1
40
}
41
 
42
if [get_compiler_info ${binfile}] {
43
    return -1
44
}
45
 
46
# Start the program running and then wait for a bit, to be sure
47
# that it can be attached to.
48
 
49
set testpid [eval exec $binfile &]
50
 
51
# No race
52
sleep 2
53
 
54
# The testcase has three threads, find some other thread TID for $testpid2.
55
set tids [exec sh -c "echo /proc/$testpid/task/*"]
56
regsub -all /proc/$testpid/task/ $tids {} tids
57
if {$tids == "*"} {
58
    unresolved "/proc/PID/task is not supported (kernel-2.4?)"
59
    remote_exec build "kill -9 ${testpid}"
60
    return -1
61
}
62
set tids [lsort -integer [split $tids]]
63
if {[llength $tids] != 3 || [lindex $tids 0] != $testpid} {
64
    verbose -log "Invalid TIDs <$tids> for PID $testpid"
65
    fail "Invalid TIDs found"
66
    remote_exec build "kill -9 ${testpid}"
67
    return -1
68
}
69
set testpid2 [lindex $tids 2]
70
 
71
# Initial sanity test it is normally sleeping
72
set status2 /proc/${testpid}/task/${testpid2}/status
73
set fileid0 [open $status2 r];
74
gets $fileid0 line1;
75
gets $fileid0 line2;
76
close $fileid0;
77
 
78
set test "attach0, initial sanity check of the sleeping state"
79
if {[string match "*(sleeping)*" $line2]} {
80
  pass $test
81
} else {
82
  fail $test
83
}
84
 
85
# Sttach and detach to test it will not become stopped
86
gdb_start
87
gdb_reinitialize_dir $srcdir/$subdir
88
gdb_load ${binfile}
89
 
90
set test "attach0 to sleeping"
91
gdb_test_multiple "attach $testpid" "$test" {
92
    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
93
        pass "$test"
94
    }
95
}
96
 
97
gdb_test "gcore /dev/null" ".*aved corefile.*" "attach0 to sleeping gcore invocation"
98
 
99
gdb_test "thread 2" ".*witching to thread 2 .*" "attach0 to sleeping switch thread"
100
 
101
gdb_test "bt" ".*sleep.*func.*" "attach0 to sleeping bt"
102
 
103
# Exit and detach the process.
104
 
105
gdb_exit
106
 
107
# No race
108
sleep 2
109
 
110
# Check it did not get stopped by our gdb
111
set fileid1 [open $status2 r];
112
gets $fileid1 line1;
113
gets $fileid1 line2;
114
close $fileid1;
115
 
116
set test "attach1, post-gdb sanity check of the sleeping state - Red Hat BZ 197584"
117
if {[string match "*(sleeping)*" $line2]} {
118
  pass $test
119
} else {
120
  fail $test
121
}
122
 
123
# Stop the program
124
remote_exec build "kill -s STOP ${testpid}"
125
 
126
# No race
127
sleep 2
128
 
129
# Check it really got stopped by kill(1)
130
set fileid2 [open $status2 r];
131
gets $fileid2 line1;
132
gets $fileid2 line2;
133
close $fileid2;
134
 
135
set test "attach2, initial sanity check of the stopped state"
136
if {[string match "*(stopped)*" $line2]} {
137
  pass $test
138
} else {
139
  fail $test
140
}
141
 
142
# Start with clean gdb
143
gdb_start
144
gdb_reinitialize_dir $srcdir/$subdir
145
gdb_load ${binfile}
146
 
147
# Verify that we can attach to the process by first giving its
148
# executable name via the file command, and using attach with the
149
# process ID.
150
 
151
set test "set file, before attach3 to stopped process"
152
gdb_test_multiple "file $binfile" "$test" {
153
   -re "Load new symbol table from.*y or n. $" {
154
        gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
155
                "$test (re-read)"
156
    }
157
    -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
158
        pass "$test"
159
    }
160
}
161
 
162
set test "attach3 to stopped, after setting file"
163
gdb_test_multiple "attach $testpid" "$test" {
164
    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
165
        pass "$test"
166
    }
167
}
168
 
169
# We may be already after the threads phase.
170
# `thread 2' command is important for the test to switch the current thread to
171
# a non-primary one for the detach process.
172
 
173
gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach3 to stopped switch thread"
174
gdb_test "bt" ".*sleep.*(func|main).*" "attach3 to stopped bt"
175
 
176
# Exit and detach the process.
177
gdb_exit
178
 
179
# Stop the program
180
remote_exec build "kill -s STOP ${testpid}"
181
 
182
# No race
183
sleep 2
184
 
185
# Continue the test as we would hit another expected bug regarding
186
#       Program received signal SIGSTOP, Stopped (signal).
187
# across NPTL threads.
188
 
189
gdb_start
190
gdb_reinitialize_dir $srcdir/$subdir
191
gdb_load ${binfile}
192
 
193
# Verify that we can attach to the process just by giving the
194
# process ID.
195
 
196
set test "attach4 to stopped, after setting file"
197
gdb_test_multiple "attach $testpid" "$test" {
198
    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
199
        pass "$test"
200
    }
201
}
202
 
203
# We may be already after the threads phase.
204
# `thread 2' command is important for the test to switch the current thread to
205
# a non-primary one for the detach process.
206
 
207
gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach4 to stopped switch thread"
208
gdb_test "bt" ".*sleep.*(func|main).*" "attach4 to stopped bt"
209
 
210
# RHEL3U8 kernel-2.4.21-47.EL will not return SIGINT but only shorten the sleep.
211
gdb_breakpoint [gdb_get_line_number "Ridiculous time"]
212
gdb_breakpoint [gdb_get_line_number "cut the sleep time"]
213
set test "attach4 continue"
214
send_gdb "continue\n"
215
gdb_expect {
216
  -re "Continuing"
217
    { pass "continue ($test)" }
218
  timeout
219
    { fail "continue ($test) (timeout)" }
220
}
221
 
222
# For this to work we must be sure to consume the "Continuing."
223
# message first, or GDB's signal handler may not be in place.
224
after 1000 {send_gdb "\003"}
225
set test "attach4 stop by interrupt"
226
gdb_expect {
227
  -re "Program received signal SIGINT.*$gdb_prompt $"
228
    {
229
      pass $test
230
    }
231
  -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
232
    {
233
      pass $test
234
    }
235
  timeout
236
    {
237
      fail "$test (timeout)"
238
    }
239
}
240
 
241
gdb_exit
242
 
243
# No race
244
sleep 2
245
 
246
# At this point, the process should be sleeping
247
 
248
set fileid4 [open $status2 r];
249
gets $fileid4 line1;
250
gets $fileid4 line2;
251
close $fileid4;
252
 
253
set test "attach4, exit leaves process sleeping"
254
if {[string match "*(sleeping)*" $line2]} {
255
  pass $test
256
} else {
257
  fail $test
258
}
259
 
260
# Make sure we don't leave a process around to confuse
261
# the next test run (and prevent the compile by keeping
262
# the text file busy), in case the "set should_exit" didn't
263
# work.
264
 
265
remote_exec build "kill -9 ${testpid}"
266
 
267
return 0

powered by: WebSVN 2.1.0

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