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