1 # Copyright 2002-2024 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 require {!target_info exists gdb,nofileio}
22 if {[is_remote host]} {
25 set outdir [standard_output_file {}]
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
30 [list debug "additional_flags=-DOUTDIR=\"$outdir/\""]] != "" } {
31 untested "failed to compile"
35 set dir2 [standard_output_file dir2.fileio.test]
36 if {[file exists $dir2] && ![file writable $dir2]} {
37 system "chmod +w $dir2"
39 system "rm -rf [standard_output_file *.fileio.test]"
41 set oldtimeout $timeout
42 set timeout [expr "$timeout + 60"]
44 clean_restart $binfile
45 gdb_test_no_output "set print sevenbit-strings"
46 gdb_test_no_output "set print address off"
47 gdb_test_no_output "set width 0"
53 gdb_test "break stop" "Breakpoint .*$srcfile.*"
55 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(void\\) {}.*"
58 "Continuing\\..*open 1:.*OK$stop_msg" \
62 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
63 "Creating already existing file returns EEXIST"
66 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
67 "Open directory for writing returns EISDIR"
70 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
71 "Opening nonexistant file returns ENOENT"
73 gdb_test "continue" ".*" ""
75 catch "system \"chmod -f -w [standard_output_file nowrt.fileio.test]\""
77 # If the user is root, we will always have write permission.
82 "Continuing\\..*open 5:.*EACCES$stop_msg" \
83 "Open for write but no write permission returns EACCES"
86 "Continuing\\..*write 1:.*OK$stop_msg" \
90 "Continuing\\..*write 2:.*EBADF$stop_msg" \
91 "Write using invalid file descriptor returns EBADF"
94 "Continuing\\..*write 3:.*EBADF$stop_msg" \
95 "Writing to a read-only file returns EBADF"
98 "Continuing\\..*read 1:.*OK$stop_msg" \
102 "Continuing\\..*read 2:.*EBADF$stop_msg" \
103 "Read using invalid file descriptor returns EBADF"
106 "Continuing\\..*lseek 1:.*OK$stop_msg" \
107 "Lseeking CUR a file"
110 "Continuing\\..*lseek 2:.*OK$stop_msg" \
111 "Lseeking END a file"
114 "Continuing\\..*lseek 3:.*OK$stop_msg" \
115 "Lseeking SET a file"
119 "Continuing\\..*close 1:.*OK$stop_msg" \
123 "Continuing\\..*close 2:.*EBADF$stop_msg" \
124 "Closing an invalid file descriptor returns EBADF"
127 "Continuing\\..*stat 1:.*OK$stop_msg" \
131 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
132 "Stat a NULL pathname returns ENOENT or EFAULT"
135 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
136 "Stat an empty pathname returns ENOENT"
139 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
140 "Stat a nonexistant file returns ENOENT"
143 "Continuing\\..*fstat 1:.*OK$stop_msg" \
147 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
148 "Fstat an invalid file descriptor returns EBADF"
151 "Continuing\\..*isatty 1:.*OK$stop_msg" \
155 "Continuing\\..*isatty 2:.*OK$stop_msg" \
159 "Continuing\\..*isatty 3:.*OK$stop_msg" \
163 "Continuing\\..*isatty 4:.*OK$stop_msg" \
167 "Continuing\\..*isatty 5:.*OK$stop_msg" \
170 gdb_test_no_output "set debug remote 1"
171 set msg "System says shell is not available"
172 gdb_test_multiple "continue" $msg {
173 -re "Continuing\\..*Fsystem.*system 1:.*OK$stop_msg\r\n$gdb_prompt $" {
176 -re ".*Fsystem.*$gdb_prompt $" {
179 -re "$gdb_prompt $" {
183 gdb_test_no_output "set debug remote 0"
185 gdb_test_no_output "set remote system-call-allowed 1"
188 "Continuing\\..*system 2:.*OK$stop_msg" \
189 "System says shell is available"
192 "Continuing\\..*system 3:.*OK$stop_msg" \
195 # Is this ok? POSIX says system returns a waitpid status?
197 "Continuing\\..*system 4:.*OK$stop_msg" \
198 "System with invalid command returns 127"
200 # Prepare the directory for rename tests in case that test_system
202 set dir1 [file join $outdir "dir1.fileio.test" "subdir.fileio.test"]
203 remote_exec host "mkdir -p $dir1"
204 set dir1 [file join $outdir "dir2.fileio.test"]
205 remote_exec host "mkdir $dir1"
208 "Continuing\\..*rename 1:.*OK$stop_msg" \
212 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
213 "Renaming a file to existing directory returns EISDIR"
215 set test "renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
216 gdb_test_multiple continue "${test}" {
217 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
220 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
221 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
222 # this wrong (reporting EBUSY) when the file system is NFS
224 setup_xfail *-*-*linux* gdb/1502
230 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
231 "Renaming a directory to a subdir of itself returns EINVAL"
234 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
235 "Renaming a nonexistant file returns ENOENT"
238 "Continuing\\..*unlink 1:.*OK$stop_msg" \
241 # This test fails on Cygwin because unlink() succeeds on Win32 systems
243 if [ishost *cygwin*] {
246 # If the user is root, we will always have write permission.
251 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
252 "Unlinking a file in a directory w/o write access returns EACCES"
255 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
256 "Unlinking a nonexistant file returns ENOENT"
259 "Continuing\\..*time 1:.*OK$stop_msg" \
260 "Time(2) call returns the same value as in parameter"
264 "Continuing\\..*time 2:.*OK$stop_msg" \
265 "Time(2) returns feasible values"
269 # Make dir2 writable again so rm -rf of a build tree Just Works.
270 if {[file exists $dir2] && ![file writable $dir2]} {
271 system "chmod +w $dir2"
274 set timeout $oldtimeout