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