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