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