1 # Copyright 2002, 2003, 2004, 2007 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 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Corinna Vinschen <vinschen@redhat.com>
21 if [target_info exists gdb,nofileio] {
22 verbose "Skipping fileio.exp because of no fileio capabilities."
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 # Create and source the file that provides information about the compiler
43 # used to compile the test case.
45 if [get_compiler_info ${binfile}] {
49 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
50 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
52 set oldtimeout $timeout
53 set timeout [expr "$timeout + 60"]
55 # Start with a fresh gdb.
59 gdb_reinitialize_dir $srcdir/$subdir
61 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
62 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
63 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
66 if ![runto_main] then {
67 perror "couldn't run to breakpoint"
71 send_gdb "break stop\n" ; gdb_expect -re "Breakpoint .*$srcfile.*$gdb_prompt $"
72 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*"
75 "Continuing\\..*open 1:.*OK$stop_msg" \
79 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
80 "Creating already existing file returns EEXIST"
83 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
84 "Open directory for writing returns EISDIR"
87 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
88 "Opening nonexistant file returns ENOENT"
90 send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $"
91 catch "system \"chmod -f -w nowrt.fileio.test\""
94 "Continuing\\..*open 5:.*EACCES$stop_msg" \
95 "Open for write but no write permission returns EACCES"
98 "Continuing\\..*write 1:.*OK$stop_msg" \
102 "Continuing\\..*write 2:.*EBADF$stop_msg" \
103 "Write using invalid file descriptor returns EBADF"
106 "Continuing\\..*write 3:.*EBADF$stop_msg" \
107 "Writing to a read-only file returns EBADF"
110 "Continuing\\..*read 1:.*OK$stop_msg" \
111 "Reading from a file"
114 "Continuing\\..*read 2:.*EBADF$stop_msg" \
115 "Read using invalid file descriptor returns EBADF"
118 "Continuing\\..*lseek 1:.*OK$stop_msg" \
119 "Lseeking CUR a file"
122 "Continuing\\..*lseek 2:.*OK$stop_msg" \
123 "Lseeking END a file"
126 "Continuing\\..*lseek 3:.*OK$stop_msg" \
127 "Lseeking SET a file"
131 "Continuing\\..*close 1:.*OK$stop_msg" \
135 "Continuing\\..*close 2:.*EBADF$stop_msg" \
136 "Closing an invalid file descriptor returns EBADF"
139 "Continuing\\..*stat 1:.*OK$stop_msg" \
143 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
144 "Stat a NULL pathname returns ENOENT or EFAULT"
147 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
148 "Stat an empty pathname returns ENOENT"
151 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
152 "Stat a nonexistant file returns ENOENT"
155 "Continuing\\..*fstat 1:.*OK$stop_msg" \
159 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
160 "Fstat an invalid file descriptor returns EBADF"
163 "Continuing\\..*isatty 1:.*OK$stop_msg" \
167 "Continuing\\..*isatty 2:.*OK$stop_msg" \
171 "Continuing\\..*isatty 3:.*OK$stop_msg" \
175 "Continuing\\..*isatty 4:.*OK$stop_msg" \
176 "Isatty (invalid fd)"
179 "Continuing\\..*isatty 5:.*OK$stop_msg" \
183 "Continuing\\..*system 1:.*OK$stop_msg" \
184 "System says shell is available"
186 send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
188 "Continuing\\..*system 2:.*OK$stop_msg" \
191 # Is this ok? POSIX says system returns a waitpid status?
193 "Continuing\\..*system 3:.*OK$stop_msg" \
194 "System with invalid command returns 127"
197 "Continuing\\..*rename 1:.*OK$stop_msg" \
201 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
202 "Renaming a file to existing directory returns EISDIR"
204 set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
205 gdb_test_multiple continue "${test}" {
206 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
209 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
210 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
211 # this wrong (reporting EBUSY) when the file system is NFS
213 setup_xfail *-*-*linux* gdb/1502
219 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
220 "Renaming a directory to a subdir of itself returns EINVAL"
223 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
224 "Renaming a nonexistant file returns ENOENT"
227 "Continuing\\..*unlink 1:.*OK$stop_msg" \
230 # This test fails on Cygwin because unlink() succeeds on Win32 systems
232 if [ishost *cygwin*] {
236 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
237 "Unlinking a file in a directory w/o write access returns EACCES"
240 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
241 "Unlinking a nonexistant file returns ENOENT"
244 "Continuing\\..*time 1:.*OK$stop_msg" \
245 "Time(2) call returns the same value as in parameter"
249 "Continuing\\..*time 2:.*OK$stop_msg" \
250 "Time(2) returns feasible values"
255 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
256 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
258 set timeout $oldtimeout