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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Corinna Vinschen <vinschen@redhat.com>
22 if [target_info exists gdb,nofileio] {
23 verbose "Skipping fileio.exp because of no fileio capabilities."
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
43 # Create and source the file that provides information about the compiler
44 # used to compile the test case.
46 if [get_compiler_info ${binfile}] {
50 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
51 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
53 set oldtimeout $timeout
54 set timeout [expr "$timeout + 60"]
56 # Start with a fresh gdb.
60 gdb_reinitialize_dir $srcdir/$subdir
62 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
63 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
64 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
67 if ![runto_main] then {
68 perror "couldn't run to breakpoint"
72 send_gdb "break stop\n" ; gdb_expect -re "Breakpoint .*$srcfile.*$gdb_prompt $"
73 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*"
76 "Continuing\\..*open 1:.*OK$stop_msg" \
80 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
81 "Creating already existing file returns EEXIST"
84 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
85 "Open directory for writing returns EISDIR"
88 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
89 "Opening nonexistant file returns ENOENT"
91 send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $"
92 catch "system \"chmod -f -w nowrt.fileio.test\""
95 "Continuing\\..*open 5:.*EACCES$stop_msg" \
96 "Open for write but no write permission returns EACCES"
99 "Continuing\\..*write 1:.*OK$stop_msg" \
103 "Continuing\\..*write 2:.*EBADF$stop_msg" \
104 "Write using invalid file descriptor returns EBADF"
107 "Continuing\\..*write 3:.*EBADF$stop_msg" \
108 "Writing to a read-only file returns EBADF"
111 "Continuing\\..*read 1:.*OK$stop_msg" \
112 "Reading from a file"
115 "Continuing\\..*read 2:.*EBADF$stop_msg" \
116 "Read using invalid file descriptor returns EBADF"
119 "Continuing\\..*lseek 1:.*OK$stop_msg" \
120 "Lseeking CUR a file"
123 "Continuing\\..*lseek 2:.*OK$stop_msg" \
124 "Lseeking END a file"
127 "Continuing\\..*lseek 3:.*OK$stop_msg" \
128 "Lseeking SET a file"
132 "Continuing\\..*close 1:.*OK$stop_msg" \
136 "Continuing\\..*close 2:.*EBADF$stop_msg" \
137 "Closing an invalid file descriptor returns EBADF"
140 "Continuing\\..*stat 1:.*OK$stop_msg" \
144 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
145 "Stat a NULL pathname returns ENOENT or EFAULT"
148 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
149 "Stat an empty pathname returns ENOENT"
152 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
153 "Stat a nonexistant file returns ENOENT"
156 "Continuing\\..*fstat 1:.*OK$stop_msg" \
160 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
161 "Fstat an invalid file descriptor returns EBADF"
164 "Continuing\\..*isatty 1:.*OK$stop_msg" \
168 "Continuing\\..*isatty 2:.*OK$stop_msg" \
172 "Continuing\\..*isatty 3:.*OK$stop_msg" \
176 "Continuing\\..*isatty 4:.*OK$stop_msg" \
177 "Isatty (invalid fd)"
180 "Continuing\\..*isatty 5:.*OK$stop_msg" \
184 "Continuing\\..*system 1:.*OK$stop_msg" \
185 "System says shell is available"
187 send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
189 "Continuing\\..*system 2:.*OK$stop_msg" \
192 # Is this ok? POSIX says system returns a waitpid status?
194 "Continuing\\..*system 3:.*OK$stop_msg" \
195 "System with invalid command returns 127"
198 "Continuing\\..*rename 1:.*OK$stop_msg" \
202 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
203 "Renaming a file to existing directory returns EISDIR"
205 set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
206 gdb_test_multiple continue "${test}" {
207 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
210 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
211 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
212 # this wrong (reporting EBUSY) when the file system is NFS
214 setup_xfail *-*-*linux* gdb/1502
220 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
221 "Renaming a directory to a subdir of itself returns EINVAL"
224 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
225 "Renaming a nonexistant file returns ENOENT"
228 "Continuing\\..*unlink 1:.*OK$stop_msg" \
231 # This test fails on Cygwin because unlink() succeeds on Win32 systems
233 if [ishost *cygwin*] {
237 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
238 "Unlinking a file in a directory w/o write access returns EACCES"
241 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
242 "Unlinking a nonexistant file returns ENOENT"
245 "Continuing\\..*time 1:.*OK$stop_msg" \
246 "Time(2) call returns the same value as in parameter"
250 "Continuing\\..*time 2:.*OK$stop_msg" \
251 "Time(2) returns feasible values"
256 remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
257 remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
259 set timeout $oldtimeout