1 # Copyright 2002-2019 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 {[is_remote host]} {
29 set outdir [standard_output_file {}]
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
34 [list debug "additional_flags=-DOUTDIR=\"$outdir/\""]] != "" } {
35 untested "failed to compile"
39 # Create and source the file that provides information about the compiler
40 # used to compile the test case.
42 if [get_compiler_info] {
46 set dir2 [standard_output_file dir2.fileio.test]
47 if {[file exists $dir2] && ![file writable $dir2]} {
48 system "chmod +w $dir2"
50 system "rm -rf [standard_output_file *.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 gdb_test_no_output "set print sevenbit-strings"
62 gdb_test_no_output "set print address off"
63 gdb_test_no_output "set width 0"
65 if ![runto_main] then {
66 perror "couldn't run to breakpoint"
70 gdb_test "break stop" "Breakpoint .*$srcfile.*"
72 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(void\\) {}.*"
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 gdb_test "continue" ".*" ""
92 catch "system \"chmod -f -w [standard_output_file 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" \
183 gdb_test_no_output "set debug remote 1"
184 set msg "System says shell is not available"
185 gdb_test_multiple "continue" $msg {
186 -re "Continuing\\..*Fsystem.*system 1:.*OK$stop_msg\r\n$gdb_prompt $" {
189 -re ".*Fsystem.*$gdb_prompt $" {
192 -re "$gdb_prompt $" {
196 gdb_test_no_output "set debug remote 0"
198 gdb_test_no_output "set remote system-call-allowed 1"
201 "Continuing\\..*system 2:.*OK$stop_msg" \
202 "System says shell is available"
205 "Continuing\\..*system 3:.*OK$stop_msg" \
208 # Is this ok? POSIX says system returns a waitpid status?
210 "Continuing\\..*system 4:.*OK$stop_msg" \
211 "System with invalid command returns 127"
213 # Prepare the directory for rename tests in case that test_system
215 set dir1 [file join $outdir "dir1.fileio.test" "subdir.fileio.test"]
216 remote_exec host "mkdir -p $dir1"
217 set dir1 [file join $outdir "dir2.fileio.test"]
218 remote_exec host "mkdir $dir1"
221 "Continuing\\..*rename 1:.*OK$stop_msg" \
225 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
226 "Renaming a file to existing directory returns EISDIR"
228 set test "renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
229 gdb_test_multiple continue "${test}" {
230 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
233 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
234 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
235 # this wrong (reporting EBUSY) when the file system is NFS
237 setup_xfail *-*-*linux* gdb/1502
243 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
244 "Renaming a directory to a subdir of itself returns EINVAL"
247 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
248 "Renaming a nonexistant file returns ENOENT"
251 "Continuing\\..*unlink 1:.*OK$stop_msg" \
254 # This test fails on Cygwin because unlink() succeeds on Win32 systems
256 if [ishost *cygwin*] {
260 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
261 "Unlinking a file in a directory w/o write access returns EACCES"
264 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
265 "Unlinking a nonexistant file returns ENOENT"
268 "Continuing\\..*time 1:.*OK$stop_msg" \
269 "Time(2) call returns the same value as in parameter"
273 "Continuing\\..*time 2:.*OK$stop_msg" \
274 "Time(2) returns feasible values"
278 # Make dir2 writable again so rm -rf of a build tree Just Works.
279 if {[file exists $dir2] && ![file writable $dir2]} {
280 system "chmod +w $dir2"
283 set timeout $oldtimeout