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