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