1 # Copyright 2002-2013 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Corinna Vinschen <vinschen@redhat.com>
18 if [target_info exists gdb,nofileio] {
19 verbose "Skipping fileio.exp because of no fileio capabilities."
25 set srcfile ${testfile}.c
26 set binfile ${objdir}/${subdir}/${testfile}
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 # Create and source the file that provides information about the compiler
34 # used to compile the test case.
36 if [get_compiler_info] {
40 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
41 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
43 set oldtimeout $timeout
44 set timeout [expr "$timeout + 60"]
46 # Start with a fresh gdb.
50 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_test_no_output "set print sevenbit-strings"
53 gdb_test_no_output "set print address off"
54 gdb_test_no_output "set width 0"
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
61 gdb_test "break stop" "Breakpoint .*$srcfile.*"
63 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*"
66 "Continuing\\..*open 1:.*OK$stop_msg" \
70 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
71 "Creating already existing file returns EEXIST"
74 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
75 "Open directory for writing returns EISDIR"
78 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
79 "Opening nonexistant file returns ENOENT"
81 gdb_test "continue" ".*" ""
83 catch "system \"chmod -f -w nowrt.fileio.test\""
86 "Continuing\\..*open 5:.*EACCES$stop_msg" \
87 "Open for write but no write permission returns EACCES"
90 "Continuing\\..*write 1:.*OK$stop_msg" \
94 "Continuing\\..*write 2:.*EBADF$stop_msg" \
95 "Write using invalid file descriptor returns EBADF"
98 "Continuing\\..*write 3:.*EBADF$stop_msg" \
99 "Writing to a read-only file returns EBADF"
102 "Continuing\\..*read 1:.*OK$stop_msg" \
103 "Reading from a file"
106 "Continuing\\..*read 2:.*EBADF$stop_msg" \
107 "Read using invalid file descriptor returns EBADF"
110 "Continuing\\..*lseek 1:.*OK$stop_msg" \
111 "Lseeking CUR a file"
114 "Continuing\\..*lseek 2:.*OK$stop_msg" \
115 "Lseeking END a file"
118 "Continuing\\..*lseek 3:.*OK$stop_msg" \
119 "Lseeking SET a file"
123 "Continuing\\..*close 1:.*OK$stop_msg" \
127 "Continuing\\..*close 2:.*EBADF$stop_msg" \
128 "Closing an invalid file descriptor returns EBADF"
131 "Continuing\\..*stat 1:.*OK$stop_msg" \
135 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
136 "Stat a NULL pathname returns ENOENT or EFAULT"
139 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
140 "Stat an empty pathname returns ENOENT"
143 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
144 "Stat a nonexistant file returns ENOENT"
147 "Continuing\\..*fstat 1:.*OK$stop_msg" \
151 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
152 "Fstat an invalid file descriptor returns EBADF"
155 "Continuing\\..*isatty 1:.*OK$stop_msg" \
159 "Continuing\\..*isatty 2:.*OK$stop_msg" \
163 "Continuing\\..*isatty 3:.*OK$stop_msg" \
167 "Continuing\\..*isatty 4:.*OK$stop_msg" \
168 "Isatty (invalid fd)"
171 "Continuing\\..*isatty 5:.*OK$stop_msg" \
175 "Continuing\\..*system 1:.*OK$stop_msg" \
176 "System says shell is available"
178 gdb_test_no_output "set remote system-call-allowed 1"
181 "Continuing\\..*system 2:.*OK$stop_msg" \
184 # Is this ok? POSIX says system returns a waitpid status?
186 "Continuing\\..*system 3:.*OK$stop_msg" \
187 "System with invalid command returns 127"
190 "Continuing\\..*rename 1:.*OK$stop_msg" \
194 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
195 "Renaming a file to existing directory returns EISDIR"
197 set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
198 gdb_test_multiple continue "${test}" {
199 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
202 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
203 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
204 # this wrong (reporting EBUSY) when the file system is NFS
206 setup_xfail *-*-*linux* gdb/1502
212 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
213 "Renaming a directory to a subdir of itself returns EINVAL"
216 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
217 "Renaming a nonexistant file returns ENOENT"
220 "Continuing\\..*unlink 1:.*OK$stop_msg" \
223 # This test fails on Cygwin because unlink() succeeds on Win32 systems
225 if [ishost *cygwin*] {
229 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
230 "Unlinking a file in a directory w/o write access returns EACCES"
233 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
234 "Unlinking a nonexistant file returns ENOENT"
237 "Continuing\\..*time 1:.*OK$stop_msg" \
238 "Time(2) call returns the same value as in parameter"
242 "Continuing\\..*time 2:.*OK$stop_msg" \
243 "Time(2) returns feasible values"
246 # Wait till GDB really exits.
249 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
250 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
252 set timeout $oldtimeout