gdb.base/interrupt.exp: Use gdb_test_multiple instead of gdb_expect
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / interrupt.exp
1 # Copyright 1994-2015 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 <http://www.gnu.org/licenses/>.
15
16 if [target_info exists gdb,nointerrupts] {
17 verbose "Skipping interrupt.exp because of nointerrupts."
18 continue
19 }
20
21 if [target_info exists gdb,noinferiorio] {
22 verbose "Skipping interrupt.exp because of noinferiorio."
23 return
24 }
25
26
27 standard_testfile
28
29 set options { debug }
30 if { ! [target_info exists gdb,nosignals] } {
31 lappend options "additional_flags=-DSIGNALS"
32 }
33
34 if {[build_executable $testfile.exp $testfile $srcfile $options] == -1} {
35 untested $testfile.exp
36 return -1
37 }
38
39 gdb_start
40
41
42 if ![file exists $binfile] then {
43 perror "$binfile does not exist."
44 return 0
45 } else {
46 gdb_reinitialize_dir $srcdir/$subdir
47 gdb_load $binfile
48 # Hope this is unix :-)
49 gdb_test "shell stty intr '^C'" ".*" \
50 "set interrupt character in interrupt.exp"
51 if [runto_main] then {
52 set msg "process is alive"
53 gdb_test_multiple "continue" $msg {
54 -re "\r\ntalk to me baby\r\n" {
55 pass $msg
56 }
57 }
58
59 # This should appear twice, once for the echo and once for the
60 # program's output.
61
62 set msg "child process ate our char"
63 send_gdb "a\n"
64 gdb_test_multiple "" $msg {
65 -re "^a\r\na\r\n$" {
66 pass $msg
67 }
68 }
69
70 # Wait until the program is in the read system call again.
71 sleep 2
72
73 # Cntrl-c may fail for simulator targets running on a BSD host.
74 # This is the result of a combination of the read syscall
75 # being restarted and gdb capturing the cntrl-c signal.
76
77 # Cntrl-c may fail for simulator targets on slow hosts.
78 # This is because there is a race condition between entering
79 # the read and delivering the cntrl-c.
80
81 send_gdb "\003"
82 set msg "send_gdb control C"
83 gdb_test_multiple "" $msg {
84 -re "Program received signal SIGINT.*$gdb_prompt $" {
85 pass $msg
86 }
87 }
88
89 set msg "call function when asleep"
90 send_gdb "p func1 ()\n"
91 gdb_test_multiple "" $msg {
92 -re " = 4.*$gdb_prompt $" {
93 pass $msg
94 }
95 -re ".*Program received signal SIG(SEGV|ILL).*$gdb_prompt $" {
96 setup_xfail "i*86-pc-linux*-gnu*"
97 fail "child died when we called func1, skipped rest of tests"
98 return
99 }
100 -re "$gdb_prompt $" {
101 # On HPUX-11.0 'send "p func1 ()"' above
102 # terminates the program. A defect is pending on this
103 # issue [defect #DTS CHFts24203]. Hence calling setup_xfail
104 # below.
105 setup_xfail "hppa*-*-*11*" CHFts24203
106 fail "call function when asleep (wrong output)"
107 }
108 default {
109
110 # This fail probably happens whenever we use /proc (we
111 # don't use PRSABORT), but apparently also happens on
112 # other machines as well.
113
114 setup_xfail "sparc*-*-solaris2*"
115 setup_xfail "i*86-*-solaris2*"
116 setup_xfail "*-*-sysv4*"
117 setup_xfail "vax-*-*"
118 setup_xfail "alpha-*-*"
119 setup_xfail "*-*-*bsd*"
120 setup_xfail "*-*-hpux*"
121 setup_xfail "*-*-*lynx*"
122 fail "$msg (stays asleep)"
123 # Send_Gdb a newline to wake it up
124 send_gdb "\n"
125 gdb_test "" " = 4" "call function after waking it"
126 }
127 }
128
129 # Now try calling the function again.
130 gdb_test "p func1 ()" " = 4" "call function a second time"
131
132 # And the program should still be doing the same thing.
133 # The optional trailing \r\n is in case we sent a newline above
134 # to wake the program, in which case the program now sends it
135 # back. We check for it either here or in the next gdb_expect
136 # command, because which one it ends up in is timing dependent.
137 send_gdb "continue\n"
138 # For some reason, i386-*-sysv4 gdb fails to issue the Continuing
139 # message, but otherwise appears normal (FIXME).
140
141 set msg "continue"
142 gdb_test_multiple "" "$msg" {
143 -re "^continue\r\nContinuing.\r\n(\r\n|)$" {
144 pass $msg
145 }
146 -re "^continue\r\n\r\n" {
147 fail "$msg (missing Continuing.)"
148 }
149 }
150
151 send_gdb "data\n"
152 # The optional leading \r\n is in case we sent a newline above
153 # to wake the program, in which case the program now sends it
154 # back.
155 # FIXME: The pattern below leads to an expected success on HPUX-11.0
156 # but the success is spurious. Need to provide the right reg.expr.
157 # here.
158
159 set msg "echo data"
160 gdb_test_multiple "" $msg {
161 -re "^(\r\n|)data\r\ndata\r\n$" {
162 pass $msg
163 }
164 -re "Undefined command.*$gdb_prompt " {
165 fail $msg
166 }
167 }
168
169 if { ! [target_info exists gdb,nosignals] } {
170 # Wait until the program is in the read system call again.
171 sleep 2
172
173 # Stop the program for another test.
174 set msg "Send Control-C, second time"
175 send_gdb "\003"
176 gdb_test_multiple "" "$msg" {
177 -re "Program received signal SIGINT.*$gdb_prompt $" {
178 pass "$msg"
179 }
180 }
181
182 # The "signal" command should deliver the correct signal and
183 # return to the loop.
184 set msg "signal SIGINT"
185 gdb_test_multiple "signal SIGINT" "$msg" {
186 -re "^signal SIGINT\r\nContinuing with signal SIGINT.\r\n(\r\n|)$" {
187 pass "$msg"
188 }
189 }
190
191 # We should be back in the loop.
192 send_gdb "more data\n"
193
194 set msg "echo more data"
195 gdb_test_multiple "" $msg {
196 -re "^(\r\n|)more data\r\nmore data\r\n$" {
197 pass $msg
198 }
199 }
200 }
201
202 set msg "send end of file"
203 send_gdb "\004"
204 gdb_test_multiple "" $msg {
205 -re "end of file.*$inferior_exited_re normally.*$gdb_prompt $" {
206 pass $msg
207 }
208 }
209 }
210 }
211 return 0
This page took 0.03556 seconds and 5 git commands to generate.