2003-06-14 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / fileio.exp
1 # Copyright 2002
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # This file was written by Corinna Vinschen <vinschen@redhat.com>
22
23 if [target_info exists gdb,nointerrupts] {
24 verbose "Skipping interrupt.exp because of nointerrupts."
25 continue
26 }
27
28 if [target_info exists gdb,noinferiorio] {
29 verbose "Skipping interrupt.exp because of noinferiorio."
30 return
31 }
32
33 if $tracelevel then {
34 strace $tracelevel
35 }
36
37 set prms_id 0
38 set bug_id 0
39
40 set testfile "fileio"
41 set srcfile ${testfile}.c
42 set binfile ${objdir}/${subdir}/${testfile}
43
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
46 }
47
48 # Create and source the file that provides information about the compiler
49 # used to compile the test case.
50
51 if [get_compiler_info ${binfile}] {
52 return -1;
53 }
54
55 remote_exec build "test -r dir2.fileio.test && chmod -f +w dir2.fileio.test"
56 remote_exec build "rm -rf *.fileio.test"
57
58 set oldtimeout $timeout
59 set timeout [expr "$timeout + 60"]
60
61 # Start with a fresh gdb.
62
63 gdb_exit
64 gdb_start
65 gdb_reinitialize_dir $srcdir/$subdir
66 gdb_load ${binfile}
67 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
68 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
69 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
70
71
72 if ![runto_main] then {
73 perror "couldn't run to breakpoint"
74 continue
75 }
76
77 send_gdb "tbreak 81\n" ; gdb_expect -re "$gdb_prompt $"
78 gdb_test continue \
79 "Continuing\\..*open 1:.*OK.*test_open \\(\\) at.*$srcfile:81.*" \
80 "Open a file"
81
82 send_gdb "tbreak 88\n" ; gdb_expect -re "$gdb_prompt $"
83 gdb_test continue \
84 "Continuing\\..*open 2:.*EEXIST.*test_open \\(\\) at.*$srcfile:88.*" \
85 "Creating already existing file returns EEXIST"
86
87 send_gdb "tbreak 95\n" ; gdb_expect -re "$gdb_prompt $"
88 gdb_test continue \
89 "Continuing\\..*open 3:.*EISDIR.*test_open \\(\\) at.*$srcfile:95.*" \
90 "Open directory for writing returns EISDIR"
91
92 send_gdb "tbreak 102\n" ; gdb_expect -re "$gdb_prompt $"
93 gdb_test continue \
94 "Continuing\\..*open 4:.*ENOENT.*test_open \\(\\) at.*$srcfile:102.*" \
95 "Opening nonexistant file returns ENOENT"
96
97 send_gdb "tbreak 109\n" ; gdb_expect -re "$gdb_prompt $"
98 send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $"
99 catch "system \"chmod -f -w nowrt.fileio.test\""
100
101 send_gdb "tbreak 119\n" ; gdb_expect -re "$gdb_prompt $"
102 gdb_test continue \
103 "Continuing\\..*open 5:.*EACCES.*test_open \\(\\) at.*$srcfile:119.*" \
104 "Open for write but no write permission returns EACCES"
105
106 send_gdb "tbreak 140\n" ; gdb_expect -re "$gdb_prompt $"
107 gdb_test continue \
108 "Continuing\\..*write 1:.*OK.*test_write \\(\\) at.*$srcfile:140.*" \
109 "Writing to a file"
110
111 send_gdb "tbreak 145\n" ; gdb_expect -re "$gdb_prompt $"
112 gdb_test continue \
113 "Continuing\\..*write 2:.*EBADF.*test_write \\(\\) at.*$srcfile:145.*" \
114 "Write using invalid file descriptor returns EBADF"
115
116 send_gdb "tbreak 156\n" ; gdb_expect -re "$gdb_prompt $"
117 gdb_test continue \
118 "Continuing\\..*write 3:.*EBADF.*test_write \\(\\) at.*$srcfile:156.*" \
119 "Writing to a read-only file returns EBADF"
120
121 send_gdb "tbreak 182\n" ; gdb_expect -re "$gdb_prompt $"
122 gdb_test continue \
123 "Continuing\\..*read 1:.*OK.*test_read \\(\\) at.*$srcfile:182.*" \
124 "Reading from a file"
125
126 send_gdb "tbreak 186\n" ; gdb_expect -re "$gdb_prompt $"
127 gdb_test continue \
128 "Continuing\\..*read 2:.*EBADF.*test_read \\(\\) at.*$srcfile:186.*" \
129 "Read using invalid file descriptor returns EBADF"
130
131 send_gdb "tbreak 221\n" ; gdb_expect -re "$gdb_prompt $"
132 gdb_test continue \
133 "Continuing\\..*lseek 1:.*OK.*lseek 2:.*OK.*lseek 3:.*OK.*test_lseek \\(\\) at.*$srcfile:221.*" \
134 "Lseeking a file"
135
136 send_gdb "tbreak 241\n" ; gdb_expect -re "$gdb_prompt $"
137 gdb_test continue \
138 "Continuing\\..*close 1:.*OK.*test_close \\(\\) at.*$srcfile:241.*" \
139 "Closing a file"
140
141 send_gdb "tbreak 245\n" ; gdb_expect -re "$gdb_prompt $"
142 gdb_test continue \
143 "Continuing\\..*close 2:.*EBADF.*test_close \\(\\) at.*$srcfile:245.*" \
144 "Closing an invalid file descriptor returns EBADF"
145
146 send_gdb "tbreak 262\n" ; gdb_expect -re "$gdb_prompt $"
147 gdb_test continue \
148 "Continuing\\..*stat 1:.*OK.*test_stat \\(\\) at.*$srcfile:262.*" \
149 "Stat a file"
150
151 send_gdb "tbreak 267\n" ; gdb_expect -re "$gdb_prompt $"
152 gdb_test continue \
153 "Continuing\\..*stat 2:.*(ENOENT|EFAULT).*test_stat \\(\\) at.*$srcfile:267.*" \
154 "Stat a NULL pathname returns ENOENT or EFAULT"
155
156 send_gdb "tbreak 272\n" ; gdb_expect -re "$gdb_prompt $"
157 gdb_test continue \
158 "Continuing\\..*stat 3:.*ENOENT.*test_stat \\(\\) at.*$srcfile:272.*" \
159 "Stat an empty pathname returns ENOENT"
160
161 send_gdb "tbreak 276\n" ; gdb_expect -re "$gdb_prompt $"
162 gdb_test continue \
163 "Continuing\\..*stat 4:.*ENOENT.*test_stat \\(\\) at.*$srcfile:276.*" \
164 "Stat a nonexistant file returns ENOENT"
165
166 send_gdb "tbreak 301\n" ; gdb_expect -re "$gdb_prompt $"
167 gdb_test continue \
168 "Continuing\\..*fstat 1:.*OK.*test_fstat \\(\\) at.*$srcfile:301.*" \
169 "Fstat an open file"
170
171 send_gdb "tbreak 305\n" ; gdb_expect -re "$gdb_prompt $"
172 gdb_test continue \
173 "Continuing\\..*fstat 2:.*EBADF.*test_fstat \\(\\) at.*$srcfile:305.*" \
174 "Fstat an invalid file descriptor returns EBADF"
175
176 send_gdb "tbreak 314\n" ; gdb_expect -re "$gdb_prompt $"
177 gdb_test continue \
178 "Continuing\\..*isatty 1:.*OK.*test_isatty \\(\\) at.*$srcfile:314.*" \
179 "Isatty (stdin)"
180
181 send_gdb "tbreak 315\n" ; gdb_expect -re "$gdb_prompt $"
182 gdb_test continue \
183 "Continuing\\..*isatty 2:.*OK.*test_isatty \\(\\) at.*$srcfile:315.*" \
184 "Isatty (stdout)"
185
186 send_gdb "tbreak 317\n" ; gdb_expect -re "$gdb_prompt $"
187 gdb_test continue \
188 "Continuing\\..*isatty 3:.*OK.*test_isatty \\(\\) at.*$srcfile:317.*" \
189 "Isatty (stderr)"
190
191 send_gdb "tbreak 319\n" ; gdb_expect -re "$gdb_prompt $"
192 gdb_test continue \
193 "Continuing\\..*isatty 4:.*OK.*test_isatty \\(\\) at.*$srcfile:319.*" \
194 "Isatty (invalid fd)"
195
196 send_gdb "tbreak 327\n" ; gdb_expect -re "$gdb_prompt $"
197 gdb_test continue \
198 "Continuing\\..*isatty 5:.*OK.*test_isatty \\(\\) at.*$srcfile:327.*" \
199 "Isatty (open file)"
200
201 send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
202 send_gdb "tbreak 347\n" ; gdb_expect -re "$gdb_prompt $"
203 gdb_test continue \
204 "Continuing\\..*system 1:.*OK.*test_system \\(\\) at.*$srcfile:347.*" \
205 "System(3) call"
206
207 # Is this ok? POSIX says system returns a waitpid status?
208 send_gdb "tbreak 349\n" ; gdb_expect -re "$gdb_prompt $"
209 gdb_test continue \
210 "Continuing\\..*system 2:.*OK.*test_system \\(\\) at.*$srcfile:349.*" \
211 "System with invalid command returns 127"
212
213 send_gdb "tbreak 378\n" ; gdb_expect -re "$gdb_prompt $"
214 gdb_test continue \
215 "Continuing\\..*rename 1:.*OK.*test_rename \\(\\) at.*$srcfile:378.*" \
216 "Rename a file"
217
218 send_gdb "tbreak 383\n" ; gdb_expect -re "$gdb_prompt $"
219 gdb_test continue \
220 "Continuing\\..*rename 2:.*EISDIR.*test_rename \\(\\) at.*$srcfile:383.*" \
221 "Renaming a file to existing directory returns EISDIR"
222
223 send_gdb "tbreak 388\n" ; gdb_expect -re "$gdb_prompt $"
224 gdb_test continue \
225 "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST).*test_rename \\(\\) at.*$srcfile:388.*" \
226 "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
227
228 send_gdb "tbreak 393\n" ; gdb_expect -re "$gdb_prompt $"
229 gdb_test continue \
230 "Continuing\\..*rename 4:.*EINVAL.*test_rename \\(\\) at.*$srcfile:393.*" \
231 "Renaming a directory to a subdir of itself returns EINVAL"
232
233 send_gdb "tbreak 397\n" ; gdb_expect -re "$gdb_prompt $"
234 gdb_test continue \
235 "Continuing\\..*rename 5:.*ENOENT.*test_rename \\(\\) at.*$srcfile:397.*" \
236 "Renaming a nonexistant file returns ENOENT"
237
238 send_gdb "tbreak 412\n" ; gdb_expect -re "$gdb_prompt $"
239 gdb_test continue \
240 "Continuing\\..*unlink 1:.*OK.*test_unlink \\(\\) at.*$srcfile:412.*" \
241 "Unlink a file"
242
243 send_gdb "tbreak 432\n" ; gdb_expect -re "$gdb_prompt $"
244 # This test fails on Cygwin because unlink() succeeds on Win32 systems
245 # in that situation.
246 if [ishost *cygwin*] {
247 setup_xfail "*-*-*"
248 }
249 gdb_test continue \
250 "Continuing\\..*unlink 2:.*EACCES.*test_unlink \\(\\) at.*$srcfile:432.*" \
251 "Unlinking a file in a directory w/o write access returns EACCES"
252
253 send_gdb "tbreak 436\n" ; gdb_expect -re "$gdb_prompt $"
254 gdb_test continue \
255 "Continuing\\..*unlink 3:.*ENOENT.*test_unlink \\(\\) at.*$srcfile:436.*" \
256 "Unlinking a nonexistant file returns ENOENT"
257
258 send_gdb "tbreak 446\n" ; gdb_expect -re "$gdb_prompt $"
259 gdb_test continue \
260 "Continuing\\..*time 1:.*OK.*test_time \\(\\) at.*$srcfile:446.*" \
261 "Time(2) call returns the same value as in parameter"
262
263 sleep 2
264 send_gdb "tbreak 450\n" ; gdb_expect -re "$gdb_prompt $"
265 gdb_test continue \
266 "Continuing\\..*time 2:.*OK.*test_time \\(\\) at.*$srcfile:450.*" \
267 "Time(2) returns feasible values"
268
269 send_gdb "quit\n"
270 send_gdb "y\n"
271
272 remote_exec build "test -r dir2.fileio.test && chmod -f +w dir2.fileio.test"
273 remote_exec build "rm -rf *.fileio.test"
274
275 set timeout $oldtimeout
276 return 0
277
This page took 0.038693 seconds and 5 git commands to generate.