]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/fileio.exp
* gdb.arch/altivec-abi.exp: Replace gdb_suppress_entire_file with
[thirdparty/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 untested fileio.exp
41 return -1
42 }
43
44 # Create and source the file that provides information about the compiler
45 # used to compile the test case.
46
47 if [get_compiler_info ${binfile}] {
48 return -1;
49 }
50
51 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
52 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
53
54 set oldtimeout $timeout
55 set timeout [expr "$timeout + 60"]
56
57 # Start with a fresh gdb.
58
59 gdb_exit
60 gdb_start
61 gdb_reinitialize_dir $srcdir/$subdir
62 gdb_load ${binfile}
63 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
64 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
65 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
66
67
68 if ![runto_main] then {
69 perror "couldn't run to breakpoint"
70 continue
71 }
72
73 send_gdb "break stop\n" ; gdb_expect -re "Breakpoint .*$srcfile.*$gdb_prompt $"
74 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*"
75
76 gdb_test continue \
77 "Continuing\\..*open 1:.*OK$stop_msg" \
78 "Open a file"
79
80 gdb_test continue \
81 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
82 "Creating already existing file returns EEXIST"
83
84 gdb_test continue \
85 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
86 "Open directory for writing returns EISDIR"
87
88 gdb_test continue \
89 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
90 "Opening nonexistant file returns ENOENT"
91
92 send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $"
93 catch "system \"chmod -f -w nowrt.fileio.test\""
94
95 gdb_test continue \
96 "Continuing\\..*open 5:.*EACCES$stop_msg" \
97 "Open for write but no write permission returns EACCES"
98
99 gdb_test continue \
100 "Continuing\\..*write 1:.*OK$stop_msg" \
101 "Writing to a file"
102
103 gdb_test continue \
104 "Continuing\\..*write 2:.*EBADF$stop_msg" \
105 "Write using invalid file descriptor returns EBADF"
106
107 gdb_test continue \
108 "Continuing\\..*write 3:.*EBADF$stop_msg" \
109 "Writing to a read-only file returns EBADF"
110
111 gdb_test continue \
112 "Continuing\\..*read 1:.*OK$stop_msg" \
113 "Reading from a file"
114
115 gdb_test continue \
116 "Continuing\\..*read 2:.*EBADF$stop_msg" \
117 "Read using invalid file descriptor returns EBADF"
118
119 gdb_test continue \
120 "Continuing\\..*lseek 1:.*OK$stop_msg" \
121 "Lseeking CUR a file"
122
123 gdb_test continue \
124 "Continuing\\..*lseek 2:.*OK$stop_msg" \
125 "Lseeking END a file"
126
127 gdb_test continue \
128 "Continuing\\..*lseek 3:.*OK$stop_msg" \
129 "Lseeking SET a file"
130
131
132 gdb_test continue \
133 "Continuing\\..*close 1:.*OK$stop_msg" \
134 "Closing a file"
135
136 gdb_test continue \
137 "Continuing\\..*close 2:.*EBADF$stop_msg" \
138 "Closing an invalid file descriptor returns EBADF"
139
140 gdb_test continue \
141 "Continuing\\..*stat 1:.*OK$stop_msg" \
142 "Stat a file"
143
144 gdb_test continue \
145 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
146 "Stat a NULL pathname returns ENOENT or EFAULT"
147
148 gdb_test continue \
149 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
150 "Stat an empty pathname returns ENOENT"
151
152 gdb_test continue \
153 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
154 "Stat a nonexistant file returns ENOENT"
155
156 gdb_test continue \
157 "Continuing\\..*fstat 1:.*OK$stop_msg" \
158 "Fstat an open file"
159
160 gdb_test continue \
161 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
162 "Fstat an invalid file descriptor returns EBADF"
163
164 gdb_test continue \
165 "Continuing\\..*isatty 1:.*OK$stop_msg" \
166 "Isatty (stdin)"
167
168 gdb_test continue \
169 "Continuing\\..*isatty 2:.*OK$stop_msg" \
170 "Isatty (stdout)"
171
172 gdb_test continue \
173 "Continuing\\..*isatty 3:.*OK$stop_msg" \
174 "Isatty (stderr)"
175
176 gdb_test continue \
177 "Continuing\\..*isatty 4:.*OK$stop_msg" \
178 "Isatty (invalid fd)"
179
180 gdb_test continue \
181 "Continuing\\..*isatty 5:.*OK$stop_msg" \
182 "Isatty (open file)"
183
184 gdb_test continue \
185 "Continuing\\..*system 1:.*OK$stop_msg" \
186 "System says shell is available"
187
188 send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
189 gdb_test continue \
190 "Continuing\\..*system 2:.*OK$stop_msg" \
191 "System(3) call"
192
193 # Is this ok? POSIX says system returns a waitpid status?
194 gdb_test continue \
195 "Continuing\\..*system 3:.*OK$stop_msg" \
196 "System with invalid command returns 127"
197
198 gdb_test continue \
199 "Continuing\\..*rename 1:.*OK$stop_msg" \
200 "Rename a file"
201
202 gdb_test continue \
203 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
204 "Renaming a file to existing directory returns EISDIR"
205
206 set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
207 gdb_test_multiple continue "${test}" {
208 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
209 pass "${test}"
210 }
211 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
212 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
213 # this wrong (reporting EBUSY) when the file system is NFS
214 # mounted.
215 setup_xfail *-*-*linux* gdb/1502
216 fail "${test}"
217 }
218 }
219
220 gdb_test continue \
221 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
222 "Renaming a directory to a subdir of itself returns EINVAL"
223
224 gdb_test continue \
225 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
226 "Renaming a nonexistant file returns ENOENT"
227
228 gdb_test continue \
229 "Continuing\\..*unlink 1:.*OK$stop_msg" \
230 "Unlink a file"
231
232 # This test fails on Cygwin because unlink() succeeds on Win32 systems
233 # in that situation.
234 if [ishost *cygwin*] {
235 setup_xfail "*-*-*"
236 }
237 gdb_test continue \
238 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
239 "Unlinking a file in a directory w/o write access returns EACCES"
240
241 gdb_test continue \
242 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
243 "Unlinking a nonexistant file returns ENOENT"
244
245 gdb_test continue \
246 "Continuing\\..*time 1:.*OK$stop_msg" \
247 "Time(2) call returns the same value as in parameter"
248
249 sleep 2
250 gdb_test continue \
251 "Continuing\\..*time 2:.*OK$stop_msg" \
252 "Time(2) returns feasible values"
253
254 send_gdb "quit\n"
255 send_gdb "y\n"
256
257 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
258 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
259
260 set timeout $oldtimeout
261 return 0