1# Copyright 2002, 2003, 2004, 2007 Free Software Foundation, Inc. 2 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. 7# 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. 12# 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/>. 15 16# Please email any bugs, comments, and/or additions to this file to: 17# bug-gdb@prep.ai.mit.edu 18 19# This file was written by Corinna Vinschen <vinschen@redhat.com> 20 21if [target_info exists gdb,nofileio] { 22 verbose "Skipping fileio.exp because of no fileio capabilities." 23 continue 24} 25 26if $tracelevel then { 27 strace $tracelevel 28} 29 30set prms_id 0 31set bug_id 0 32 33set testfile "fileio" 34set srcfile ${testfile}.c 35set binfile ${objdir}/${subdir}/${testfile} 36 37if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 38 untested fileio.exp 39 return -1 40} 41 42# Create and source the file that provides information about the compiler 43# used to compile the test case. 44 45if [get_compiler_info ${binfile}] { 46 return -1; 47} 48 49remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test} 50remote_exec build {sh -xc rm\ -rf\ *.fileio.test} 51 52set oldtimeout $timeout 53set timeout [expr "$timeout + 60"] 54 55# Start with a fresh gdb. 56 57gdb_exit 58gdb_start 59gdb_reinitialize_dir $srcdir/$subdir 60gdb_load ${binfile} 61send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $" 62send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $" 63send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $" 64 65 66if ![runto_main] then { 67 perror "couldn't run to breakpoint" 68 continue 69} 70 71send_gdb "break stop\n" ; gdb_expect -re "Breakpoint .*$srcfile.*$gdb_prompt $" 72set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(\\) {}.*" 73 74gdb_test continue \ 75"Continuing\\..*open 1:.*OK$stop_msg" \ 76"Open a file" 77 78gdb_test continue \ 79"Continuing\\..*open 2:.*EEXIST$stop_msg" \ 80"Creating already existing file returns EEXIST" 81 82gdb_test continue \ 83"Continuing\\..*open 3:.*EISDIR$stop_msg" \ 84"Open directory for writing returns EISDIR" 85 86gdb_test continue \ 87"Continuing\\..*open 4:.*ENOENT$stop_msg" \ 88"Opening nonexistant file returns ENOENT" 89 90send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $" 91catch "system \"chmod -f -w nowrt.fileio.test\"" 92 93gdb_test continue \ 94"Continuing\\..*open 5:.*EACCES$stop_msg" \ 95"Open for write but no write permission returns EACCES" 96 97gdb_test continue \ 98"Continuing\\..*write 1:.*OK$stop_msg" \ 99"Writing to a file" 100 101gdb_test continue \ 102"Continuing\\..*write 2:.*EBADF$stop_msg" \ 103"Write using invalid file descriptor returns EBADF" 104 105gdb_test continue \ 106"Continuing\\..*write 3:.*EBADF$stop_msg" \ 107"Writing to a read-only file returns EBADF" 108 109gdb_test continue \ 110"Continuing\\..*read 1:.*OK$stop_msg" \ 111"Reading from a file" 112 113gdb_test continue \ 114"Continuing\\..*read 2:.*EBADF$stop_msg" \ 115"Read using invalid file descriptor returns EBADF" 116 117gdb_test continue \ 118"Continuing\\..*lseek 1:.*OK$stop_msg" \ 119"Lseeking CUR a file" 120 121gdb_test continue \ 122"Continuing\\..*lseek 2:.*OK$stop_msg" \ 123"Lseeking END a file" 124 125gdb_test continue \ 126"Continuing\\..*lseek 3:.*OK$stop_msg" \ 127"Lseeking SET a file" 128 129 130gdb_test continue \ 131"Continuing\\..*close 1:.*OK$stop_msg" \ 132"Closing a file" 133 134gdb_test continue \ 135"Continuing\\..*close 2:.*EBADF$stop_msg" \ 136"Closing an invalid file descriptor returns EBADF" 137 138gdb_test continue \ 139"Continuing\\..*stat 1:.*OK$stop_msg" \ 140"Stat a file" 141 142gdb_test continue \ 143 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \ 144"Stat a NULL pathname returns ENOENT or EFAULT" 145 146gdb_test continue \ 147"Continuing\\..*stat 3:.*ENOENT$stop_msg" \ 148"Stat an empty pathname returns ENOENT" 149 150gdb_test continue \ 151"Continuing\\..*stat 4:.*ENOENT$stop_msg" \ 152"Stat a nonexistant file returns ENOENT" 153 154gdb_test continue \ 155"Continuing\\..*fstat 1:.*OK$stop_msg" \ 156"Fstat an open file" 157 158gdb_test continue \ 159"Continuing\\..*fstat 2:.*EBADF$stop_msg" \ 160"Fstat an invalid file descriptor returns EBADF" 161 162gdb_test continue \ 163"Continuing\\..*isatty 1:.*OK$stop_msg" \ 164"Isatty (stdin)" 165 166gdb_test continue \ 167"Continuing\\..*isatty 2:.*OK$stop_msg" \ 168"Isatty (stdout)" 169 170gdb_test continue \ 171"Continuing\\..*isatty 3:.*OK$stop_msg" \ 172"Isatty (stderr)" 173 174gdb_test continue \ 175"Continuing\\..*isatty 4:.*OK$stop_msg" \ 176"Isatty (invalid fd)" 177 178gdb_test continue \ 179"Continuing\\..*isatty 5:.*OK$stop_msg" \ 180"Isatty (open file)" 181 182gdb_test continue \ 183"Continuing\\..*system 1:.*OK$stop_msg" \ 184"System says shell is available" 185 186send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $" 187gdb_test continue \ 188"Continuing\\..*system 2:.*OK$stop_msg" \ 189"System(3) call" 190 191# Is this ok? POSIX says system returns a waitpid status? 192gdb_test continue \ 193"Continuing\\..*system 3:.*OK$stop_msg" \ 194"System with invalid command returns 127" 195 196gdb_test continue \ 197"Continuing\\..*rename 1:.*OK$stop_msg" \ 198"Rename a file" 199 200gdb_test continue \ 201"Continuing\\..*rename 2:.*EISDIR$stop_msg" \ 202"Renaming a file to existing directory returns EISDIR" 203 204set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST" 205gdb_test_multiple continue "${test}" { 206 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" { 207 pass "${test}" 208 } 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 212 # mounted. 213 setup_xfail *-*-*linux* gdb/1502 214 fail "${test}" 215 } 216} 217 218gdb_test continue \ 219"Continuing\\..*rename 4:.*EINVAL$stop_msg" \ 220"Renaming a directory to a subdir of itself returns EINVAL" 221 222gdb_test continue \ 223"Continuing\\..*rename 5:.*ENOENT$stop_msg" \ 224"Renaming a nonexistant file returns ENOENT" 225 226gdb_test continue \ 227"Continuing\\..*unlink 1:.*OK$stop_msg" \ 228"Unlink a file" 229 230# This test fails on Cygwin because unlink() succeeds on Win32 systems 231# in that situation. 232if [ishost *cygwin*] { 233 setup_xfail "*-*-*" 234} 235gdb_test continue \ 236"Continuing\\..*unlink 2:.*EACCES$stop_msg" \ 237"Unlinking a file in a directory w/o write access returns EACCES" 238 239gdb_test continue \ 240"Continuing\\..*unlink 3:.*ENOENT$stop_msg" \ 241"Unlinking a nonexistant file returns ENOENT" 242 243gdb_test continue \ 244"Continuing\\..*time 1:.*OK$stop_msg" \ 245"Time(2) call returns the same value as in parameter" 246 247sleep 2 248gdb_test continue \ 249"Continuing\\..*time 2:.*OK$stop_msg" \ 250"Time(2) returns feasible values" 251 252send_gdb "quit\n" 253send_gdb "y\n" 254 255remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test} 256remote_exec build {sh -xc rm\ -rf\ *.fileio.test} 257 258set timeout $oldtimeout 259return 0 260