Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 2002, 2003, 2004, 2007, 2008 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 CV |
15 | |
16 | # Please email any bugs, comments, and/or additions to this file to: | |
17 | # bug-gdb@prep.ai.mit.edu | |
18 | ||
19 | # This file was written by Corinna Vinschen <vinschen@redhat.com> | |
20 | ||
db488fc1 CV |
21 | if [target_info exists gdb,nofileio] { |
22 | verbose "Skipping fileio.exp because of no fileio capabilities." | |
b257a0d3 AC |
23 | continue |
24 | } | |
25 | ||
6aeb981f CV |
26 | if $tracelevel then { |
27 | strace $tracelevel | |
28 | } | |
29 | ||
30 | set prms_id 0 | |
31 | set bug_id 0 | |
32 | ||
33 | set testfile "fileio" | |
34 | set srcfile ${testfile}.c | |
35 | set binfile ${objdir}/${subdir}/${testfile} | |
36 | ||
37 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
38 | untested fileio.exp |
39 | return -1 | |
6aeb981f CV |
40 | } |
41 | ||
42 | # Create and source the file that provides information about the compiler | |
43 | # used to compile the test case. | |
44 | ||
45 | if [get_compiler_info ${binfile}] { | |
46 | return -1; | |
47 | } | |
48 | ||
225f2bf6 AC |
49 | remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test} |
50 | remote_exec build {sh -xc rm\ -rf\ *.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} | |
61 | send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $" | |
62 | send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $" | |
63 | send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $" | |
64 | ||
65 | ||
66 | if ![runto_main] then { | |
67 | perror "couldn't run to breakpoint" | |
68 | continue | |
69 | } | |
70 | ||
e1c2defa NS |
71 | send_gdb "break stop\n" ; gdb_expect -re "Breakpoint .*$srcfile.*$gdb_prompt $" |
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 | ||
6aeb981f CV |
90 | send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $" |
91 | catch "system \"chmod -f -w nowrt.fileio.test\"" | |
92 | ||
6aeb981f | 93 | gdb_test continue \ |
e1c2defa | 94 | "Continuing\\..*open 5:.*EACCES$stop_msg" \ |
6aeb981f CV |
95 | "Open for write but no write permission returns EACCES" |
96 | ||
6aeb981f | 97 | gdb_test continue \ |
e1c2defa | 98 | "Continuing\\..*write 1:.*OK$stop_msg" \ |
6aeb981f CV |
99 | "Writing to a file" |
100 | ||
6aeb981f | 101 | gdb_test continue \ |
e1c2defa | 102 | "Continuing\\..*write 2:.*EBADF$stop_msg" \ |
6aeb981f CV |
103 | "Write using invalid file descriptor returns EBADF" |
104 | ||
6aeb981f | 105 | gdb_test continue \ |
e1c2defa | 106 | "Continuing\\..*write 3:.*EBADF$stop_msg" \ |
6aeb981f CV |
107 | "Writing to a read-only file returns EBADF" |
108 | ||
6aeb981f | 109 | gdb_test continue \ |
e1c2defa | 110 | "Continuing\\..*read 1:.*OK$stop_msg" \ |
6aeb981f CV |
111 | "Reading from a file" |
112 | ||
6aeb981f | 113 | gdb_test continue \ |
e1c2defa | 114 | "Continuing\\..*read 2:.*EBADF$stop_msg" \ |
6aeb981f CV |
115 | "Read using invalid file descriptor returns EBADF" |
116 | ||
6aeb981f | 117 | gdb_test continue \ |
e1c2defa NS |
118 | "Continuing\\..*lseek 1:.*OK$stop_msg" \ |
119 | "Lseeking CUR a file" | |
120 | ||
121 | gdb_test continue \ | |
122 | "Continuing\\..*lseek 2:.*OK$stop_msg" \ | |
123 | "Lseeking END a file" | |
124 | ||
125 | gdb_test continue \ | |
126 | "Continuing\\..*lseek 3:.*OK$stop_msg" \ | |
127 | "Lseeking SET a file" | |
128 | ||
6aeb981f | 129 | |
6aeb981f | 130 | gdb_test continue \ |
e1c2defa | 131 | "Continuing\\..*close 1:.*OK$stop_msg" \ |
6aeb981f CV |
132 | "Closing a file" |
133 | ||
6aeb981f | 134 | gdb_test continue \ |
e1c2defa | 135 | "Continuing\\..*close 2:.*EBADF$stop_msg" \ |
6aeb981f CV |
136 | "Closing an invalid file descriptor returns EBADF" |
137 | ||
6aeb981f | 138 | gdb_test continue \ |
e1c2defa | 139 | "Continuing\\..*stat 1:.*OK$stop_msg" \ |
6aeb981f CV |
140 | "Stat a file" |
141 | ||
6aeb981f | 142 | gdb_test continue \ |
e1c2defa | 143 | "Continuing\\..*stat 2:.*(ENOENT|EFAULT)$stop_msg" \ |
b257a0d3 | 144 | "Stat a NULL pathname returns ENOENT or EFAULT" |
6aeb981f | 145 | |
6aeb981f | 146 | gdb_test continue \ |
e1c2defa | 147 | "Continuing\\..*stat 3:.*ENOENT$stop_msg" \ |
6aeb981f CV |
148 | "Stat an empty pathname returns ENOENT" |
149 | ||
6aeb981f | 150 | gdb_test continue \ |
e1c2defa | 151 | "Continuing\\..*stat 4:.*ENOENT$stop_msg" \ |
6aeb981f CV |
152 | "Stat a nonexistant file returns ENOENT" |
153 | ||
6aeb981f | 154 | gdb_test continue \ |
e1c2defa | 155 | "Continuing\\..*fstat 1:.*OK$stop_msg" \ |
6aeb981f CV |
156 | "Fstat an open file" |
157 | ||
6aeb981f | 158 | gdb_test continue \ |
e1c2defa | 159 | "Continuing\\..*fstat 2:.*EBADF$stop_msg" \ |
6aeb981f CV |
160 | "Fstat an invalid file descriptor returns EBADF" |
161 | ||
6aeb981f | 162 | gdb_test continue \ |
e1c2defa | 163 | "Continuing\\..*isatty 1:.*OK$stop_msg" \ |
6aeb981f CV |
164 | "Isatty (stdin)" |
165 | ||
6aeb981f | 166 | gdb_test continue \ |
e1c2defa | 167 | "Continuing\\..*isatty 2:.*OK$stop_msg" \ |
6aeb981f CV |
168 | "Isatty (stdout)" |
169 | ||
6aeb981f | 170 | gdb_test continue \ |
e1c2defa | 171 | "Continuing\\..*isatty 3:.*OK$stop_msg" \ |
6aeb981f CV |
172 | "Isatty (stderr)" |
173 | ||
6aeb981f | 174 | gdb_test continue \ |
e1c2defa | 175 | "Continuing\\..*isatty 4:.*OK$stop_msg" \ |
6aeb981f CV |
176 | "Isatty (invalid fd)" |
177 | ||
6aeb981f | 178 | gdb_test continue \ |
e1c2defa | 179 | "Continuing\\..*isatty 5:.*OK$stop_msg" \ |
6aeb981f CV |
180 | "Isatty (open file)" |
181 | ||
6aeb981f | 182 | gdb_test continue \ |
e1c2defa | 183 | "Continuing\\..*system 1:.*OK$stop_msg" \ |
5600ea19 NS |
184 | "System says shell is available" |
185 | ||
186 | send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $" | |
187 | gdb_test continue \ | |
188 | "Continuing\\..*system 2:.*OK$stop_msg" \ | |
6aeb981f CV |
189 | "System(3) call" |
190 | ||
b257a0d3 | 191 | # Is this ok? POSIX says system returns a waitpid status? |
6aeb981f | 192 | gdb_test continue \ |
5600ea19 | 193 | "Continuing\\..*system 3:.*OK$stop_msg" \ |
6aeb981f CV |
194 | "System with invalid command returns 127" |
195 | ||
6aeb981f | 196 | gdb_test continue \ |
e1c2defa | 197 | "Continuing\\..*rename 1:.*OK$stop_msg" \ |
6aeb981f CV |
198 | "Rename a file" |
199 | ||
6aeb981f | 200 | gdb_test continue \ |
e1c2defa | 201 | "Continuing\\..*rename 2:.*EISDIR$stop_msg" \ |
6aeb981f CV |
202 | "Renaming a file to existing directory returns EISDIR" |
203 | ||
a9415475 AC |
204 | set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST" |
205 | gdb_test_multiple continue "${test}" { | |
e1c2defa | 206 | -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST)$stop_msg$gdb_prompt $" { |
a9415475 AC |
207 | pass "${test}" |
208 | } | |
e1c2defa | 209 | -re "Continuing\\..*rename 3:.*EBUSY$stop_msg$gdb_prompt $" { |
a9415475 AC |
210 | # At least version <= 2.6/2004-01-08 of the Linux Kernel gets |
211 | # this wrong (reporting EBUSY) when the file system is NFS | |
212 | # mounted. | |
213 | setup_xfail *-*-*linux* gdb/1502 | |
214 | fail "${test}" | |
215 | } | |
216 | } | |
6aeb981f | 217 | |
6aeb981f | 218 | gdb_test continue \ |
e1c2defa | 219 | "Continuing\\..*rename 4:.*EINVAL$stop_msg" \ |
6aeb981f CV |
220 | "Renaming a directory to a subdir of itself returns EINVAL" |
221 | ||
6aeb981f | 222 | gdb_test continue \ |
e1c2defa | 223 | "Continuing\\..*rename 5:.*ENOENT$stop_msg" \ |
6aeb981f CV |
224 | "Renaming a nonexistant file returns ENOENT" |
225 | ||
6aeb981f | 226 | gdb_test continue \ |
e1c2defa | 227 | "Continuing\\..*unlink 1:.*OK$stop_msg" \ |
6aeb981f CV |
228 | "Unlink a file" |
229 | ||
6aeb981f CV |
230 | # This test fails on Cygwin because unlink() succeeds on Win32 systems |
231 | # in that situation. | |
232 | if [ishost *cygwin*] { | |
233 | setup_xfail "*-*-*" | |
234 | } | |
235 | gdb_test continue \ | |
e1c2defa | 236 | "Continuing\\..*unlink 2:.*EACCES$stop_msg" \ |
6aeb981f CV |
237 | "Unlinking a file in a directory w/o write access returns EACCES" |
238 | ||
6aeb981f | 239 | gdb_test continue \ |
e1c2defa | 240 | "Continuing\\..*unlink 3:.*ENOENT$stop_msg" \ |
6aeb981f CV |
241 | "Unlinking a nonexistant file returns ENOENT" |
242 | ||
6aeb981f | 243 | gdb_test continue \ |
e1c2defa | 244 | "Continuing\\..*time 1:.*OK$stop_msg" \ |
6aeb981f CV |
245 | "Time(2) call returns the same value as in parameter" |
246 | ||
247 | sleep 2 | |
6aeb981f | 248 | gdb_test continue \ |
e1c2defa | 249 | "Continuing\\..*time 2:.*OK$stop_msg" \ |
6aeb981f CV |
250 | "Time(2) returns feasible values" |
251 | ||
252 | send_gdb "quit\n" | |
253 | send_gdb "y\n" | |
254 | ||
225f2bf6 AC |
255 | remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test} |
256 | remote_exec build {sh -xc rm\ -rf\ *.fileio.test} | |
6aeb981f CV |
257 | |
258 | set timeout $oldtimeout | |
259 | return 0 |