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