Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / fileio.exp
blob6a708ed00edb0edb448fb34371df0c7124baab27
1 # Copyright 2002-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Corinna Vinschen <vinschen@redhat.com>
18 require {!target_info exists gdb,nofileio}
20 standard_testfile
22 if {[is_remote host]} {
23 set outdir .
24 } else {
25 set outdir [standard_output_file {}]
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
35 set dir2 [standard_output_file dir2.fileio.test]
36 if {[file exists $dir2] && ![file writable $dir2]} {
37 system "chmod +w $dir2"
39 system "rm -rf [standard_output_file *.fileio.test]"
41 set oldtimeout $timeout
42 set timeout [expr "$timeout + 60"]
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"
49 if {![runto_main]} {
50 return
53 gdb_test "break stop" "Breakpoint .*$srcfile.*"
55 set stop_msg ".*Breakpoint .* stop \\(\\) at.*$srcfile:.*static void stop \\(void\\) {}.*"
57 gdb_test continue \
58 "Continuing\\..*open 1:.*OK$stop_msg" \
59 "Open a file"
61 gdb_test continue \
62 "Continuing\\..*open 2:.*EEXIST$stop_msg" \
63 "Creating already existing file returns EEXIST"
65 gdb_test continue \
66 "Continuing\\..*open 3:.*EISDIR$stop_msg" \
67 "Open directory for writing returns EISDIR"
69 gdb_test continue \
70 "Continuing\\..*open 4:.*ENOENT$stop_msg" \
71 "Opening nonexistant file returns ENOENT"
73 gdb_test "continue" ".*" ""
75 catch "system \"chmod -f -w [standard_output_file nowrt.fileio.test]\""
77 # If the user is root, we will always have write permission.
78 if { [root_user] } {
79 setup_xfail *-*-*
81 gdb_test continue \
82 "Continuing\\..*open 5:.*EACCES$stop_msg" \
83 "Open for write but no write permission returns EACCES"
85 gdb_test continue \
86 "Continuing\\..*write 1:.*OK$stop_msg" \
87 "Writing to a file"
89 gdb_test continue \
90 "Continuing\\..*write 2:.*EBADF$stop_msg" \
91 "Write using invalid file descriptor returns EBADF"
93 gdb_test continue \
94 "Continuing\\..*write 3:.*EBADF$stop_msg" \
95 "Writing to a read-only file returns EBADF"
97 gdb_test continue \
98 "Continuing\\..*read 1:.*OK$stop_msg" \
99 "Reading from a file"
101 gdb_test continue \
102 "Continuing\\..*read 2:.*EBADF$stop_msg" \
103 "Read using invalid file descriptor returns EBADF"
105 gdb_test continue \
106 "Continuing\\..*lseek 1:.*OK$stop_msg" \
107 "Lseeking CUR a file"
109 gdb_test continue \
110 "Continuing\\..*lseek 2:.*OK$stop_msg" \
111 "Lseeking END a file"
113 gdb_test continue \
114 "Continuing\\..*lseek 3:.*OK$stop_msg" \
115 "Lseeking SET a file"
118 gdb_test continue \
119 "Continuing\\..*close 1:.*OK$stop_msg" \
120 "Closing a file"
122 gdb_test continue \
123 "Continuing\\..*close 2:.*EBADF$stop_msg" \
124 "Closing an invalid file descriptor returns EBADF"
126 gdb_test continue \
127 "Continuing\\..*stat 1:.*OK$stop_msg" \
128 "Stat a file"
130 gdb_test continue \
131 "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \
132 "Stat a NULL pathname returns ENOENT or EFAULT"
134 gdb_test continue \
135 "Continuing\\..*stat 3:.*ENOENT$stop_msg" \
136 "Stat an empty pathname returns ENOENT"
138 gdb_test continue \
139 "Continuing\\..*stat 4:.*ENOENT$stop_msg" \
140 "Stat a nonexistant file returns ENOENT"
142 gdb_test continue \
143 "Continuing\\..*fstat 1:.*OK$stop_msg" \
144 "Fstat an open file"
146 gdb_test continue \
147 "Continuing\\..*fstat 2:.*EBADF$stop_msg" \
148 "Fstat an invalid file descriptor returns EBADF"
150 gdb_test continue \
151 "Continuing\\..*isatty 1:.*OK$stop_msg" \
152 "Isatty (stdin)"
154 gdb_test continue \
155 "Continuing\\..*isatty 2:.*OK$stop_msg" \
156 "Isatty (stdout)"
158 gdb_test continue \
159 "Continuing\\..*isatty 3:.*OK$stop_msg" \
160 "Isatty (stderr)"
162 gdb_test continue \
163 "Continuing\\..*isatty 4:.*OK$stop_msg" \
164 "Isatty (invalid fd)"
166 gdb_test continue \
167 "Continuing\\..*isatty 5:.*OK$stop_msg" \
168 "Isatty (open file)"
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
176 -re ".*Fsystem.*$gdb_prompt $" {
177 fail $msg
179 -re "$gdb_prompt $" {
180 unsupported $msg
183 gdb_test_no_output "set debug remote 0"
185 gdb_test_no_output "set remote system-call-allowed 1"
187 gdb_test continue \
188 "Continuing\\..*system 2:.*OK$stop_msg" \
189 "System says shell is available"
191 gdb_test continue \
192 "Continuing\\..*system 3:.*OK$stop_msg" \
193 "System(3) call"
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"
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"
207 gdb_test continue \
208 "Continuing\\..*rename 1:.*OK$stop_msg" \
209 "Rename a file"
211 gdb_test continue \
212 "Continuing\\..*rename 2:.*EISDIR$stop_msg" \
213 "Renaming a file to existing directory returns EISDIR"
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}"
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}"
229 gdb_test continue \
230 "Continuing\\..*rename 4:.*EINVAL$stop_msg" \
231 "Renaming a directory to a subdir of itself returns EINVAL"
233 gdb_test continue \
234 "Continuing\\..*rename 5:.*ENOENT$stop_msg" \
235 "Renaming a nonexistant file returns ENOENT"
237 gdb_test continue \
238 "Continuing\\..*unlink 1:.*OK$stop_msg" \
239 "Unlink a file"
241 # This test fails on Cygwin because unlink() succeeds on Win32 systems
242 # in that situation.
243 if [ishost *cygwin*] {
244 setup_xfail "*-*-*"
246 # If the user is root, we will always have write permission.
247 if { [root_user] } {
248 setup_xfail *-*-*
250 gdb_test continue \
251 "Continuing\\..*unlink 2:.*EACCES$stop_msg" \
252 "Unlinking a file in a directory w/o write access returns EACCES"
254 gdb_test continue \
255 "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \
256 "Unlinking a nonexistant file returns ENOENT"
258 gdb_test continue \
259 "Continuing\\..*time 1:.*OK$stop_msg" \
260 "Time(2) call returns the same value as in parameter"
262 sleep 2
263 gdb_test continue \
264 "Continuing\\..*time 2:.*OK$stop_msg" \
265 "Time(2) returns feasible values"
267 gdb_exit
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"
274 set timeout $oldtimeout