]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/fileio.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / fileio.exp
1 # Copyright 2002-2024 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 require {!target_info exists gdb,nofileio}
19
20 standard_testfile
21
22 if {[is_remote host]} {
23 set outdir .
24 } else {
25 set outdir [standard_output_file {}]
26 }
27
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
29 executable \
30 [list debug "additional_flags=-DOUTDIR=\"$outdir/\""]] != "" } {
31 untested "failed to compile"
32 return -1
33 }
34
35 set dir2 [standard_output_file dir2.fileio.test]
36 if {[file exists $dir2] && ![file writable $dir2]} {
37 system "chmod +w $dir2"
38 }
39 system "rm -rf [standard_output_file *.fileio.test]"
40
41 set oldtimeout $timeout
42 set timeout [expr "$timeout + 60"]
43
44 clean_restart $binfile
45 gdb_test_no_output "set print sevenbit-strings"
46 gdb_test_no_output "set print address off"
47 gdb_test_no_output "set width 0"
48
49 if {![runto_main]} {
50 return
51 }
52
53 gdb_test "break stop" "Breakpoint .*$srcfile.*"
54
55 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(void\\) {}.*"
56
57 gdb_test continue \
58 "Continuing\\..*open 1:.*OK$stop_msg" \
59 "Open a file"
60
61 gdb_test continue \
62 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
63 "Creating already existing file returns EEXIST"
64
65 gdb_test continue \
66 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
67 "Open directory for writing returns EISDIR"
68
69 gdb_test continue \
70 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
71 "Opening nonexistant file returns ENOENT"
72
73 gdb_test "continue" ".*" ""
74
75 catch "system \"chmod -f -w [standard_output_file nowrt.fileio.test]\""
76
77 # If the user is root, we will always have write permission.
78 if { [root_user] } {
79 setup_xfail *-*-*
80 }
81 gdb_test continue \
82 "Continuing\\..*open 5:.*EACCES$stop_msg" \
83 "Open for write but no write permission returns EACCES"
84
85 gdb_test continue \
86 "Continuing\\..*write 1:.*OK$stop_msg" \
87 "Writing to a file"
88
89 gdb_test continue \
90 "Continuing\\..*write 2:.*EBADF$stop_msg" \
91 "Write using invalid file descriptor returns EBADF"
92
93 gdb_test continue \
94 "Continuing\\..*write 3:.*EBADF$stop_msg" \
95 "Writing to a read-only file returns EBADF"
96
97 gdb_test continue \
98 "Continuing\\..*read 1:.*OK$stop_msg" \
99 "Reading from a file"
100
101 gdb_test continue \
102 "Continuing\\..*read 2:.*EBADF$stop_msg" \
103 "Read using invalid file descriptor returns EBADF"
104
105 gdb_test continue \
106 "Continuing\\..*lseek 1:.*OK$stop_msg" \
107 "Lseeking CUR a file"
108
109 gdb_test continue \
110 "Continuing\\..*lseek 2:.*OK$stop_msg" \
111 "Lseeking END a file"
112
113 gdb_test continue \
114 "Continuing\\..*lseek 3:.*OK$stop_msg" \
115 "Lseeking SET a file"
116
117
118 gdb_test continue \
119 "Continuing\\..*close 1:.*OK$stop_msg" \
120 "Closing a file"
121
122 gdb_test continue \
123 "Continuing\\..*close 2:.*EBADF$stop_msg" \
124 "Closing an invalid file descriptor returns EBADF"
125
126 gdb_test continue \
127 "Continuing\\..*stat 1:.*OK$stop_msg" \
128 "Stat a file"
129
130 gdb_test continue \
131 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
132 "Stat a NULL pathname returns ENOENT or EFAULT"
133
134 gdb_test continue \
135 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
136 "Stat an empty pathname returns ENOENT"
137
138 gdb_test continue \
139 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
140 "Stat a nonexistant file returns ENOENT"
141
142 gdb_test continue \
143 "Continuing\\..*fstat 1:.*OK$stop_msg" \
144 "Fstat an open file"
145
146 gdb_test continue \
147 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
148 "Fstat an invalid file descriptor returns EBADF"
149
150 gdb_test continue \
151 "Continuing\\..*isatty 1:.*OK$stop_msg" \
152 "Isatty (stdin)"
153
154 gdb_test continue \
155 "Continuing\\..*isatty 2:.*OK$stop_msg" \
156 "Isatty (stdout)"
157
158 gdb_test continue \
159 "Continuing\\..*isatty 3:.*OK$stop_msg" \
160 "Isatty (stderr)"
161
162 gdb_test continue \
163 "Continuing\\..*isatty 4:.*OK$stop_msg" \
164 "Isatty (invalid fd)"
165
166 gdb_test continue \
167 "Continuing\\..*isatty 5:.*OK$stop_msg" \
168 "Isatty (open file)"
169
170 gdb_test_no_output "set debug remote 1"
171 set msg "System says shell is not available"
172 gdb_test_multiple "continue" $msg {
173 -re "Continuing\\..*Fsystem.*system 1:.*OK$stop_msg\r\n$gdb_prompt $" {
174 pass $msg
175 }
176 -re ".*Fsystem.*$gdb_prompt $" {
177 fail $msg
178 }
179 -re "$gdb_prompt $" {
180 unsupported $msg
181 }
182 }
183 gdb_test_no_output "set debug remote 0"
184
185 gdb_test_no_output "set remote system-call-allowed 1"
186
187 gdb_test continue \
188 "Continuing\\..*system 2:.*OK$stop_msg" \
189 "System says shell is available"
190
191 gdb_test continue \
192 "Continuing\\..*system 3:.*OK$stop_msg" \
193 "System(3) call"
194
195 # Is this ok? POSIX says system returns a waitpid status?
196 gdb_test continue \
197 "Continuing\\..*system 4:.*OK$stop_msg" \
198 "System with invalid command returns 127"
199
200 # Prepare the directory for rename tests in case that test_system
201 # failed to create.
202 set dir1 [file join $outdir "dir1.fileio.test" "subdir.fileio.test"]
203 remote_exec host "mkdir -p $dir1"
204 set dir1 [file join $outdir "dir2.fileio.test"]
205 remote_exec host "mkdir $dir1"
206
207 gdb_test continue \
208 "Continuing\\..*rename 1:.*OK$stop_msg" \
209 "Rename a file"
210
211 gdb_test continue \
212 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
213 "Renaming a file to existing directory returns EISDIR"
214
215 set test "renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
216 gdb_test_multiple continue "${test}" {
217 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" {
218 pass "${test}"
219 }
220 -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" {
221 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
222 # this wrong (reporting EBUSY) when the file system is NFS
223 # mounted.
224 setup_xfail *-*-*linux* gdb/1502
225 fail "${test}"
226 }
227 }
228
229 gdb_test continue \
230 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
231 "Renaming a directory to a subdir of itself returns EINVAL"
232
233 gdb_test continue \
234 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
235 "Renaming a nonexistant file returns ENOENT"
236
237 gdb_test continue \
238 "Continuing\\..*unlink 1:.*OK$stop_msg" \
239 "Unlink a file"
240
241 # This test fails on Cygwin because unlink() succeeds on Win32 systems
242 # in that situation.
243 if [ishost *cygwin*] {
244 setup_xfail "*-*-*"
245 }
246 # If the user is root, we will always have write permission.
247 if { [root_user] } {
248 setup_xfail *-*-*
249 }
250 gdb_test continue \
251 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
252 "Unlinking a file in a directory w/o write access returns EACCES"
253
254 gdb_test continue \
255 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
256 "Unlinking a nonexistant file returns ENOENT"
257
258 gdb_test continue \
259 "Continuing\\..*time 1:.*OK$stop_msg" \
260 "Time(2) call returns the same value as in parameter"
261
262 sleep 2
263 gdb_test continue \
264 "Continuing\\..*time 2:.*OK$stop_msg" \
265 "Time(2) returns feasible values"
266
267 gdb_exit
268
269 # Make dir2 writable again so rm -rf of a build tree Just Works.
270 if {[file exists $dir2] && ![file writable $dir2]} {
271 system "chmod +w $dir2"
272 }
273
274 set timeout $oldtimeout