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