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."
26 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
31 # Create and source the file that provides information about the compiler
32 # used to compile the test case.
34 if [get_compiler_info] {
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}
41 set oldtimeout $timeout
42 set timeout [expr "$timeout + 60"]
44 # Start with a fresh gdb.
48 gdb_reinitialize_dir $srcdir/$subdir
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"
54 if ![runto_main] then {
55 perror "couldn't run to breakpoint"
59 gdb_test "break stop" "Breakpoint .*$srcfile.*"
61 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*"
64 "Continuing\\..*open 1:.*OK$stop_msg" \
68 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
69 "Creating already existing file returns EEXIST"
72 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
73 "Open directory for writing returns EISDIR"
76 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
77 "Opening nonexistant file returns ENOENT"
79 gdb_test "continue" ".*" ""
81 catch "system \"chmod -f -w nowrt.fileio.test\""
84 "Continuing\\..*open 5:.*EACCES$stop_msg" \
85 "Open for write but no write permission returns EACCES"
88 "Continuing\\..*write 1:.*OK$stop_msg" \
92 "Continuing\\..*write 2:.*EBADF$stop_msg" \
93 "Write using invalid file descriptor returns EBADF"
96 "Continuing\\..*write 3:.*EBADF$stop_msg" \
97 "Writing to a read-only file returns EBADF"
100 "Continuing\\..*read 1:.*OK$stop_msg" \
101 "Reading from a file"
104 "Continuing\\..*read 2:.*EBADF$stop_msg" \
105 "Read using invalid file descriptor returns EBADF"
108 "Continuing\\..*lseek 1:.*OK$stop_msg" \
109 "Lseeking CUR a file"
112 "Continuing\\..*lseek 2:.*OK$stop_msg" \
113 "Lseeking END a file"
116 "Continuing\\..*lseek 3:.*OK$stop_msg" \
117 "Lseeking SET a file"
121 "Continuing\\..*close 1:.*OK$stop_msg" \
125 "Continuing\\..*close 2:.*EBADF$stop_msg" \
126 "Closing an invalid file descriptor returns EBADF"
129 "Continuing\\..*stat 1:.*OK$stop_msg" \
133 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
134 "Stat a NULL pathname returns ENOENT or EFAULT"
137 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
138 "Stat an empty pathname returns ENOENT"
141 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
142 "Stat a nonexistant file returns ENOENT"
145 "Continuing\\..*fstat 1:.*OK$stop_msg" \
149 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
150 "Fstat an invalid file descriptor returns EBADF"
153 "Continuing\\..*isatty 1:.*OK$stop_msg" \
157 "Continuing\\..*isatty 2:.*OK$stop_msg" \
161 "Continuing\\..*isatty 3:.*OK$stop_msg" \
165 "Continuing\\..*isatty 4:.*OK$stop_msg" \
166 "Isatty (invalid fd)"
169 "Continuing\\..*isatty 5:.*OK$stop_msg" \
173 "Continuing\\..*system 1:.*OK$stop_msg" \
174 "System says shell is available"
176 gdb_test_no_output "set remote system-call-allowed 1"
179 "Continuing\\..*system 2:.*OK$stop_msg" \
182 # Is this ok? POSIX says system returns a waitpid status?
184 "Continuing\\..*system 3:.*OK$stop_msg" \
185 "System with invalid command returns 127"
188 "Continuing\\..*rename 1:.*OK$stop_msg" \
192 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
193 "Renaming a file to existing directory returns EISDIR"
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 $" {
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
204 setup_xfail *-*-*linux* gdb/1502
210 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
211 "Renaming a directory to a subdir of itself returns EINVAL"
214 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
215 "Renaming a nonexistant file returns ENOENT"
218 "Continuing\\..*unlink 1:.*OK$stop_msg" \
221 # This test fails on Cygwin because unlink() succeeds on Win32 systems
223 if [ishost *cygwin*] {
227 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
228 "Unlinking a file in a directory w/o write access returns EACCES"
231 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
232 "Unlinking a nonexistant file returns ENOENT"
235 "Continuing\\..*time 1:.*OK$stop_msg" \
236 "Time(2) call returns the same value as in parameter"
240 "Continuing\\..*time 2:.*OK$stop_msg" \
241 "Time(2) returns feasible values"
244 # Wait till GDB really exits.
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}
250 set timeout $oldtimeout