1 # Copyright 2002-2004, 2007-2012 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."
29 set srcfile ${testfile}.c
30 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
37 # Create and source the file that provides information about the compiler
38 # used to compile the test case.
40 if [get_compiler_info ${binfile}] {
44 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
45 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
47 set oldtimeout $timeout
48 set timeout [expr "$timeout + 60"]
50 # Start with a fresh gdb.
54 gdb_reinitialize_dir $srcdir/$subdir
56 gdb_test_no_output "set print sevenbit-strings"
57 gdb_test_no_output "set print address off"
58 gdb_test_no_output "set width 0"
60 if ![runto_main] then {
61 perror "couldn't run to breakpoint"
65 gdb_test "break stop" "Breakpoint .*$srcfile.*"
67 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*"
70 "Continuing\\..*open 1:.*OK$stop_msg" \
74 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
75 "Creating already existing file returns EEXIST"
78 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
79 "Open directory for writing returns EISDIR"
82 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
83 "Opening nonexistant file returns ENOENT"
85 gdb_test "continue" ".*" ""
87 catch "system \"chmod -f -w nowrt.fileio.test\""
90 "Continuing\\..*open 5:.*EACCES$stop_msg" \
91 "Open for write but no write permission returns EACCES"
94 "Continuing\\..*write 1:.*OK$stop_msg" \
98 "Continuing\\..*write 2:.*EBADF$stop_msg" \
99 "Write using invalid file descriptor returns EBADF"
102 "Continuing\\..*write 3:.*EBADF$stop_msg" \
103 "Writing to a read-only file returns EBADF"
106 "Continuing\\..*read 1:.*OK$stop_msg" \
107 "Reading from a file"
110 "Continuing\\..*read 2:.*EBADF$stop_msg" \
111 "Read using invalid file descriptor returns EBADF"
114 "Continuing\\..*lseek 1:.*OK$stop_msg" \
115 "Lseeking CUR a file"
118 "Continuing\\..*lseek 2:.*OK$stop_msg" \
119 "Lseeking END a file"
122 "Continuing\\..*lseek 3:.*OK$stop_msg" \
123 "Lseeking SET a file"
127 "Continuing\\..*close 1:.*OK$stop_msg" \
131 "Continuing\\..*close 2:.*EBADF$stop_msg" \
132 "Closing an invalid file descriptor returns EBADF"
135 "Continuing\\..*stat 1:.*OK$stop_msg" \
139 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
140 "Stat a NULL pathname returns ENOENT or EFAULT"
143 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
144 "Stat an empty pathname returns ENOENT"
147 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
148 "Stat a nonexistant file returns ENOENT"
151 "Continuing\\..*fstat 1:.*OK$stop_msg" \
155 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
156 "Fstat an invalid file descriptor returns EBADF"
159 "Continuing\\..*isatty 1:.*OK$stop_msg" \
163 "Continuing\\..*isatty 2:.*OK$stop_msg" \
167 "Continuing\\..*isatty 3:.*OK$stop_msg" \
171 "Continuing\\..*isatty 4:.*OK$stop_msg" \
172 "Isatty (invalid fd)"
175 "Continuing\\..*isatty 5:.*OK$stop_msg" \
179 "Continuing\\..*system 1:.*OK$stop_msg" \
180 "System says shell is available"
182 gdb_test_no_output "set remote system-call-allowed 1"
185 "Continuing\\..*system 2:.*OK$stop_msg" \
188 # Is this ok? POSIX says system returns a waitpid status?
190 "Continuing\\..*system 3:.*OK$stop_msg" \
191 "System with invalid command returns 127"
194 "Continuing\\..*rename 1:.*OK$stop_msg" \
198 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
199 "Renaming a file to existing directory returns EISDIR"
201 set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
202 gdb_test_multiple continue "${test}" {
203 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
206 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
207 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
208 # this wrong (reporting EBUSY) when the file system is NFS
210 setup_xfail *-*-*linux* gdb/1502
216 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
217 "Renaming a directory to a subdir of itself returns EINVAL"
220 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
221 "Renaming a nonexistant file returns ENOENT"
224 "Continuing\\..*unlink 1:.*OK$stop_msg" \
227 # This test fails on Cygwin because unlink() succeeds on Win32 systems
229 if [ishost *cygwin*] {
233 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
234 "Unlinking a file in a directory w/o write access returns EACCES"
237 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
238 "Unlinking a nonexistant file returns ENOENT"
241 "Continuing\\..*time 1:.*OK$stop_msg" \
242 "Time(2) call returns the same value as in parameter"
246 "Continuing\\..*time 2:.*OK$stop_msg" \
247 "Time(2) returns feasible values"
250 # Wait till GDB really exits.
253 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
254 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
256 set timeout $oldtimeout