Reviewed and approved by Daniel Jacobowitz <drow@false.org>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / fileio.exp
CommitLineData
a9415475 1# Copyright 2002, 2003, 2004
6aeb981f
CV
2# Free Software Foundation, Inc.
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
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
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.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# This file was written by Corinna Vinschen <vinschen@redhat.com>
22
db488fc1
CV
23if [target_info exists gdb,nofileio] {
24 verbose "Skipping fileio.exp because of no fileio capabilities."
b257a0d3
AC
25 continue
26}
27
6aeb981f
CV
28if $tracelevel then {
29 strace $tracelevel
30}
31
32set prms_id 0
33set bug_id 0
34
35set testfile "fileio"
36set srcfile ${testfile}.c
37set binfile ${objdir}/${subdir}/${testfile}
38
39if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41}
42
43# Create and source the file that provides information about the compiler
44# used to compile the test case.
45
46if [get_compiler_info ${binfile}] {
47 return -1;
48}
49
225f2bf6
AC
50remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
51remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
6aeb981f
CV
52
53set oldtimeout $timeout
54set timeout [expr "$timeout + 60"]
55
56# Start with a fresh gdb.
57
58gdb_exit
59gdb_start
60gdb_reinitialize_dir $srcdir/$subdir
61gdb_load ${binfile}
62send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
63send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
64send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
65
66
67if ![runto_main] then {
68 perror "couldn't run to breakpoint"
69 continue
70}
71
72send_gdb "tbreak 81\n" ; gdb_expect -re "$gdb_prompt $"
73gdb_test continue \
74"Continuing\\..*open 1:.*OK.*test_open \\(\\) at.*$srcfile:81.*" \
75"Open a file"
76
77send_gdb "tbreak 88\n" ; gdb_expect -re "$gdb_prompt $"
78gdb_test continue \
b257a0d3 79"Continuing\\..*open 2:.*EEXIST.*test_open \\(\\) at.*$srcfile:88.*" \
6aeb981f
CV
80"Creating already existing file returns EEXIST"
81
82send_gdb "tbreak 95\n" ; gdb_expect -re "$gdb_prompt $"
83gdb_test continue \
b257a0d3 84"Continuing\\..*open 3:.*EISDIR.*test_open \\(\\) at.*$srcfile:95.*" \
6aeb981f
CV
85"Open directory for writing returns EISDIR"
86
87send_gdb "tbreak 102\n" ; gdb_expect -re "$gdb_prompt $"
88gdb_test continue \
b257a0d3 89"Continuing\\..*open 4:.*ENOENT.*test_open \\(\\) at.*$srcfile:102.*" \
6aeb981f
CV
90"Opening nonexistant file returns ENOENT"
91
92send_gdb "tbreak 109\n" ; gdb_expect -re "$gdb_prompt $"
93send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $"
94catch "system \"chmod -f -w nowrt.fileio.test\""
95
96send_gdb "tbreak 119\n" ; gdb_expect -re "$gdb_prompt $"
97gdb_test continue \
b257a0d3 98"Continuing\\..*open 5:.*EACCES.*test_open \\(\\) at.*$srcfile:119.*" \
6aeb981f
CV
99"Open for write but no write permission returns EACCES"
100
101send_gdb "tbreak 140\n" ; gdb_expect -re "$gdb_prompt $"
102gdb_test continue \
103"Continuing\\..*write 1:.*OK.*test_write \\(\\) at.*$srcfile:140.*" \
104"Writing to a file"
105
106send_gdb "tbreak 145\n" ; gdb_expect -re "$gdb_prompt $"
107gdb_test continue \
b257a0d3 108"Continuing\\..*write 2:.*EBADF.*test_write \\(\\) at.*$srcfile:145.*" \
6aeb981f
CV
109"Write using invalid file descriptor returns EBADF"
110
111send_gdb "tbreak 156\n" ; gdb_expect -re "$gdb_prompt $"
112gdb_test continue \
b257a0d3 113"Continuing\\..*write 3:.*EBADF.*test_write \\(\\) at.*$srcfile:156.*" \
6aeb981f
CV
114"Writing to a read-only file returns EBADF"
115
116send_gdb "tbreak 182\n" ; gdb_expect -re "$gdb_prompt $"
117gdb_test continue \
118"Continuing\\..*read 1:.*OK.*test_read \\(\\) at.*$srcfile:182.*" \
119"Reading from a file"
120
121send_gdb "tbreak 186\n" ; gdb_expect -re "$gdb_prompt $"
122gdb_test continue \
b257a0d3 123"Continuing\\..*read 2:.*EBADF.*test_read \\(\\) at.*$srcfile:186.*" \
6aeb981f
CV
124"Read using invalid file descriptor returns EBADF"
125
126send_gdb "tbreak 221\n" ; gdb_expect -re "$gdb_prompt $"
127gdb_test continue \
128"Continuing\\..*lseek 1:.*OK.*lseek 2:.*OK.*lseek 3:.*OK.*test_lseek \\(\\) at.*$srcfile:221.*" \
129"Lseeking a file"
130
131send_gdb "tbreak 241\n" ; gdb_expect -re "$gdb_prompt $"
132gdb_test continue \
133"Continuing\\..*close 1:.*OK.*test_close \\(\\) at.*$srcfile:241.*" \
134"Closing a file"
135
136send_gdb "tbreak 245\n" ; gdb_expect -re "$gdb_prompt $"
137gdb_test continue \
b257a0d3 138"Continuing\\..*close 2:.*EBADF.*test_close \\(\\) at.*$srcfile:245.*" \
6aeb981f
CV
139"Closing an invalid file descriptor returns EBADF"
140
141send_gdb "tbreak 262\n" ; gdb_expect -re "$gdb_prompt $"
142gdb_test continue \
143"Continuing\\..*stat 1:.*OK.*test_stat \\(\\) at.*$srcfile:262.*" \
144"Stat a file"
145
146send_gdb "tbreak 267\n" ; gdb_expect -re "$gdb_prompt $"
147gdb_test continue \
b257a0d3
AC
148 "Continuing\\..*stat 2:.*(ENOENT|EFAULT).*test_stat \\(\\) at.*$srcfile:267.*" \
149"Stat a NULL pathname returns ENOENT or EFAULT"
6aeb981f
CV
150
151send_gdb "tbreak 272\n" ; gdb_expect -re "$gdb_prompt $"
152gdb_test continue \
b257a0d3 153"Continuing\\..*stat 3:.*ENOENT.*test_stat \\(\\) at.*$srcfile:272.*" \
6aeb981f
CV
154"Stat an empty pathname returns ENOENT"
155
156send_gdb "tbreak 276\n" ; gdb_expect -re "$gdb_prompt $"
157gdb_test continue \
b257a0d3 158"Continuing\\..*stat 4:.*ENOENT.*test_stat \\(\\) at.*$srcfile:276.*" \
6aeb981f
CV
159"Stat a nonexistant file returns ENOENT"
160
161send_gdb "tbreak 301\n" ; gdb_expect -re "$gdb_prompt $"
162gdb_test continue \
163"Continuing\\..*fstat 1:.*OK.*test_fstat \\(\\) at.*$srcfile:301.*" \
164"Fstat an open file"
165
166send_gdb "tbreak 305\n" ; gdb_expect -re "$gdb_prompt $"
167gdb_test continue \
b257a0d3 168"Continuing\\..*fstat 2:.*EBADF.*test_fstat \\(\\) at.*$srcfile:305.*" \
6aeb981f
CV
169"Fstat an invalid file descriptor returns EBADF"
170
171send_gdb "tbreak 314\n" ; gdb_expect -re "$gdb_prompt $"
172gdb_test continue \
173"Continuing\\..*isatty 1:.*OK.*test_isatty \\(\\) at.*$srcfile:314.*" \
174"Isatty (stdin)"
175
176send_gdb "tbreak 315\n" ; gdb_expect -re "$gdb_prompt $"
177gdb_test continue \
178"Continuing\\..*isatty 2:.*OK.*test_isatty \\(\\) at.*$srcfile:315.*" \
179"Isatty (stdout)"
180
181send_gdb "tbreak 317\n" ; gdb_expect -re "$gdb_prompt $"
182gdb_test continue \
183"Continuing\\..*isatty 3:.*OK.*test_isatty \\(\\) at.*$srcfile:317.*" \
184"Isatty (stderr)"
185
186send_gdb "tbreak 319\n" ; gdb_expect -re "$gdb_prompt $"
187gdb_test continue \
188"Continuing\\..*isatty 4:.*OK.*test_isatty \\(\\) at.*$srcfile:319.*" \
189"Isatty (invalid fd)"
190
191send_gdb "tbreak 327\n" ; gdb_expect -re "$gdb_prompt $"
192gdb_test continue \
193"Continuing\\..*isatty 5:.*OK.*test_isatty \\(\\) at.*$srcfile:327.*" \
194"Isatty (open file)"
195
196send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
197send_gdb "tbreak 347\n" ; gdb_expect -re "$gdb_prompt $"
198gdb_test continue \
199"Continuing\\..*system 1:.*OK.*test_system \\(\\) at.*$srcfile:347.*" \
200"System(3) call"
201
b257a0d3 202# Is this ok? POSIX says system returns a waitpid status?
6aeb981f
CV
203send_gdb "tbreak 349\n" ; gdb_expect -re "$gdb_prompt $"
204gdb_test continue \
205"Continuing\\..*system 2:.*OK.*test_system \\(\\) at.*$srcfile:349.*" \
206"System with invalid command returns 127"
207
208send_gdb "tbreak 378\n" ; gdb_expect -re "$gdb_prompt $"
209gdb_test continue \
210"Continuing\\..*rename 1:.*OK.*test_rename \\(\\) at.*$srcfile:378.*" \
211"Rename a file"
212
213send_gdb "tbreak 383\n" ; gdb_expect -re "$gdb_prompt $"
214gdb_test continue \
b257a0d3 215"Continuing\\..*rename 2:.*EISDIR.*test_rename \\(\\) at.*$srcfile:383.*" \
6aeb981f
CV
216"Renaming a file to existing directory returns EISDIR"
217
218send_gdb "tbreak 388\n" ; gdb_expect -re "$gdb_prompt $"
a9415475
AC
219set test "Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
220gdb_test_multiple continue "${test}" {
7049b4b8 221 -re "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST).*test_rename \\(\\) at.*$srcfile:388.*$gdb_prompt $" {
a9415475
AC
222 pass "${test}"
223 }
7049b4b8 224 -re "Continuing\\..*rename 3:.*EBUSY.*test_rename \\(\\) at.*$srcfile:388.*$gdb_prompt $" {
a9415475
AC
225 # At least version <= 2.6/2004-01-08 of the Linux Kernel gets
226 # this wrong (reporting EBUSY) when the file system is NFS
227 # mounted.
228 setup_xfail *-*-*linux* gdb/1502
229 fail "${test}"
230 }
231}
6aeb981f
CV
232
233send_gdb "tbreak 393\n" ; gdb_expect -re "$gdb_prompt $"
234gdb_test continue \
b257a0d3 235"Continuing\\..*rename 4:.*EINVAL.*test_rename \\(\\) at.*$srcfile:393.*" \
6aeb981f
CV
236"Renaming a directory to a subdir of itself returns EINVAL"
237
238send_gdb "tbreak 397\n" ; gdb_expect -re "$gdb_prompt $"
239gdb_test continue \
b257a0d3 240"Continuing\\..*rename 5:.*ENOENT.*test_rename \\(\\) at.*$srcfile:397.*" \
6aeb981f
CV
241"Renaming a nonexistant file returns ENOENT"
242
243send_gdb "tbreak 412\n" ; gdb_expect -re "$gdb_prompt $"
244gdb_test continue \
245"Continuing\\..*unlink 1:.*OK.*test_unlink \\(\\) at.*$srcfile:412.*" \
246"Unlink a file"
247
248send_gdb "tbreak 432\n" ; gdb_expect -re "$gdb_prompt $"
249# This test fails on Cygwin because unlink() succeeds on Win32 systems
250# in that situation.
251if [ishost *cygwin*] {
252 setup_xfail "*-*-*"
253}
254gdb_test continue \
b257a0d3 255"Continuing\\..*unlink 2:.*EACCES.*test_unlink \\(\\) at.*$srcfile:432.*" \
6aeb981f
CV
256"Unlinking a file in a directory w/o write access returns EACCES"
257
258send_gdb "tbreak 436\n" ; gdb_expect -re "$gdb_prompt $"
259gdb_test continue \
b257a0d3 260"Continuing\\..*unlink 3:.*ENOENT.*test_unlink \\(\\) at.*$srcfile:436.*" \
6aeb981f
CV
261"Unlinking a nonexistant file returns ENOENT"
262
263send_gdb "tbreak 446\n" ; gdb_expect -re "$gdb_prompt $"
264gdb_test continue \
265"Continuing\\..*time 1:.*OK.*test_time \\(\\) at.*$srcfile:446.*" \
266"Time(2) call returns the same value as in parameter"
267
268sleep 2
269send_gdb "tbreak 450\n" ; gdb_expect -re "$gdb_prompt $"
270gdb_test continue \
271"Continuing\\..*time 2:.*OK.*test_time \\(\\) at.*$srcfile:450.*" \
272"Time(2) returns feasible values"
273
274send_gdb "quit\n"
275send_gdb "y\n"
276
225f2bf6
AC
277remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
278remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
6aeb981f
CV
279
280set timeout $oldtimeout
281return 0
This page took 0.322094 seconds and 4 git commands to generate.