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