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