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