#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
-/**************************************************************************
- * TESTS :
+#include <errno.h>
+#include <sys/wait.h>
+/* TESTS :
* - open(const char *pathname, int flags, mode_t mode);
1) Attempt to create file that already exists - EEXIST
2) Attempt to open a directory for writing - EISDIR
Not applicable.
system (const char * string);
-1) Invalid string/command. - returns 127.
+1) Invalid string/command. - returns 127. */
- ***************************************************************************/
+static const char *strerrno (int err);
#define FILENAME "foo.fileio.test"
#define RENAMED "bar.fileio.test"
#define NONEXISTANT "nofoo.fileio.test"
#define NOWRITE "nowrt.fileio.test"
-
#define TESTDIR1 "dir1.fileio.test"
#define TESTDIR2 "dir2.fileio.test"
#define TESTSUBDIR "dir1.fileio.test/subdir.fileio.test"
errno = 0;
ret = open (FILENAME, O_CREAT | O_EXCL | O_WRONLY, S_IWUSR | S_IRUSR);
printf ("open 2: ret = %d, errno = %d %s\n", ret, errno,
- errno == EEXIST ? "OK" : "");
+ strerrno (errno));
if (ret >= 0)
close (ret);
/* Open directory (for writing) */
errno = 0;
ret = open (".", O_WRONLY);
printf ("open 3: ret = %d, errno = %d %s\n", ret, errno,
- errno == EISDIR ? "OK" : "");
+ strerrno (errno));
if (ret >= 0)
close (ret);
/* Opening nonexistant file */
errno = 0;
ret = open (NONEXISTANT, O_RDONLY);
printf ("open 4: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOENT ? "OK" : "");
+ strerrno (errno));
if (ret >= 0)
close (ret);
/* Open for write but no write permission */
errno = 0;
ret = open (NOWRITE, O_WRONLY);
printf ("open 5: ret = %d, errno = %d %s\n", ret, errno,
- errno == EACCES ? "OK" : "");
+ strerrno (errno));
if (ret >= 0)
close (ret);
}
errno = 0;
ret = write (999, STRING, strlen (STRING));
printf ("write 2: ret = %d, errno = %d, %s\n", ret, errno,
- errno == EBADF ? "OK" : "");
+ strerrno (errno));
/* Write to a read-only file */
errno = 0;
fd = open (FILENAME, O_RDONLY);
errno = 0;
ret = write (fd, STRING, strlen (STRING));
printf ("write 3: ret = %d, errno = %d %s\n", ret, errno,
- errno == EBADF ? "OK" : "");
+ strerrno (errno));
}
else
printf ("write 3: ret = %d, errno = %d\n", ret, errno);
errno = 0;
ret = read (999, buf, 16);
printf ("read 2: ret = %d, errno = %d %s\n", ret, errno,
- errno == EBADF ? "OK" : "");
+ strerrno (errno));
}
int
test_lseek ()
{
int fd;
- off_t ret;
+ off_t ret = 0;
/* Test seeking */
errno = 0;
{
errno = 0;
ret = lseek (fd, 0, SEEK_CUR);
- printf ("lseek 1: ret = %ld, errno = %d, %s\n", ret, errno,
+ printf ("lseek 1: ret = %ld, errno = %d, %s\n", (long) ret, errno,
ret == 0 ? "OK" : "");
errno = 0;
ret = lseek (fd, 0, SEEK_END);
- printf ("lseek 2: ret = %ld, errno = %d, %s\n", ret, errno,
+ printf ("lseek 2: ret = %ld, errno = %d, %s\n", (long) ret, errno,
ret == 11 ? "OK" : "");
errno = 0;
ret = lseek (fd, 3, SEEK_SET);
- printf ("lseek 3: ret = %ld, errno = %d, %s\n", ret, errno,
+ printf ("lseek 3: ret = %ld, errno = %d, %s\n", (long) ret, errno,
ret == 3 ? "OK" : "");
close (fd);
}
{
errno = 0;
ret = close (fd);
- printf ("close 1: ret = %ld, errno = %d, %s\n", ret, errno,
+ printf ("close 1: ret = %d, errno = %d, %s\n", ret, errno,
ret == 0 ? "OK" : "");
}
else
/* Close an invalid file descriptor */
errno = 0;
ret = close (999);
- printf ("close 2: ret = %ld, errno = %d, %s\n", ret, errno,
- errno == EBADF ? "OK" : "");
+ printf ("close 2: ret = %d, errno = %d, %s\n", ret, errno,
+ strerrno (errno));
}
int
errno = 0;
ret = stat (NULL, &st);
printf ("stat 2: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOENT ? "OK" : "");
+ strerrno (errno));
/* Empty pathname */
errno = 0;
ret = stat ("", &st);
printf ("stat 3: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOENT ? "OK" : "");
+ strerrno (errno));
/* Nonexistant file */
errno = 0;
ret = stat (NONEXISTANT, &st);
printf ("stat 4: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOENT ? "OK" : "");
+ strerrno (errno));
}
int
errno = 0;
ret = fstat (999, &st);
printf ("fstat 2: ret = %d, errno = %d %s\n", ret, errno,
- errno == EBADF ? "OK" : "");
+ strerrno (errno));
}
int
printf ("isatty 5: file couldn't open\n");
}
+
int
test_system ()
{
printf ("system 1: ret = %d %s\n", ret, ret == 0 ? "OK" : "");
/* Invalid command (just guessing ;-) ) */
ret = system ("wrtzlpfrmpft");
- printf ("system 2: ret = %d %s\n", ret, ret == 127 ? "OK" : "");
+ printf ("system 2: ret = %d %s\n", ret, WEXITSTATUS (ret) == 127 ? "OK" : "");
}
int
errno = 0;
ret = stat (RENAMED, &st);
printf ("rename 1: ret = %d, errno = %d %s\n", ret, errno,
- errno == 0 ? "OK" : "");
+ strerrno (errno));
errno = 0;
}
else
errno = 0;
ret = rename (RENAMED, TESTDIR2);
printf ("rename 2: ret = %d, errno = %d %s\n", ret, errno,
- errno == EISDIR ? "OK" : "");
+ strerrno (errno));
/* newpath is a non-empty directory */
errno = 0;
ret = rename (TESTDIR2, TESTDIR1);
printf ("rename 3: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOTEMPTY || errno == EEXIST ? "OK" : "");
+ strerrno (errno));
/* newpath is a subdirectory of old path */
errno = 0;
ret = rename (TESTDIR1, TESTSUBDIR);
printf ("rename 4: ret = %d, errno = %d %s\n", ret, errno,
- errno == EINVAL ? "OK" : "");
+ strerrno (errno));
/* oldpath does not exist */
errno = 0;
ret = rename (NONEXISTANT, FILENAME);
printf ("rename 5: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOENT ? "OK" : "");
+ strerrno (errno));
}
int
errno = 0;
ret = unlink (RENAMED);
printf ("unlink 1: ret = %d, errno = %d %s\n", ret, errno,
- errno == 0 ? "OK" : "");
+ strerrno (errno));
/* No write access */
sprintf (name, "%s/%s", TESTDIR2, FILENAME);
errno = 0;
errno = 0;
ret = unlink (name);
printf ("unlink 2: ret = %d, errno = %d %s\n", ret, errno,
- errno == EACCES ? "OK" : "");
+ strerrno (errno));
}
else
printf ("unlink 2: ret = %d chmod failed\n", ret, errno);
errno = 0;
ret = unlink (NONEXISTANT);
printf ("unlink 3: ret = %d, errno = %d %s\n", ret, errno,
- errno == ENOENT ? "OK" : "");
+ strerrno (errno));
}
int
errno = 0;
ret = time (&t);
- printf ("time 1: ret = %d, errno = %d, t = %d %s\n", ret, errno, t, ret == t ? "OK" : "");
+ printf ("time 1: ret = %ld, errno = %d, t = %ld %s\n", (long) ret, errno, (long) t, ret == t ? "OK" : "");
errno = 0;
ret = time (NULL);
- printf ("time 2: ret = %d, errno = %d, t = %d %s\n", ret, errno, t,
- ret >= t && ret < t + 10 ? "OK" : "");
+ printf ("time 2: ret = %ld, errno = %d, t = %ld %s\n",
+ (long) ret, errno, (long) t, ret >= t && ret < t + 10 ? "OK" : "");
+}
+
+static const char *
+strerrno (int err)
+{
+ switch (err)
+ {
+ case 0: return "OK";
+#ifdef EACCES
+ case EACCES: return "EACCES";
+#endif
+#ifdef EBADF
+ case EBADF: return "EBADF";
+#endif
+#ifdef EEXIST
+ case EEXIST: return "EEXIST";
+#endif
+#ifdef EFAULT
+ case EFAULT: return "EFAULT";
+#endif
+#ifdef EINVAL
+ case EINVAL: return "EINVAL";
+#endif
+#ifdef EISDIR
+ case EISDIR: return "EISDIR";
+#endif
+#ifdef ENOENT
+ case ENOENT: return "ENOENT";
+#endif
+#ifdef ENOTEMPTY
+ case ENOTEMPTY: return "ENOTEMPTY";
+#endif
+ default: return "E??";
+ }
}
int
# This file was written by Corinna Vinschen <vinschen@redhat.com>
+if [target_info exists gdb,nointerrupts] {
+ verbose "Skipping interrupt.exp because of nointerrupts."
+ continue
+}
+
+if [target_info exists gdb,noinferiorio] {
+ verbose "Skipping interrupt.exp because of noinferiorio."
+ return
+}
if $tracelevel then {
strace $tracelevel
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
-# test only on a remote target board
-if {! [is_remote target]} {
- return 0;
-}
-
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}
return -1;
}
-catch "system \"chmod -f +w dir2.fileio.test\""
-catch "system \"rm -rf *.fileio.test\""
+remote_exec build "test -r dir2.fileio.test && chmod -f +w dir2.fileio.test"
+remote_exec build "rm -rf *.fileio.test"
set oldtimeout $timeout
set timeout [expr "$timeout + 60"]
send_gdb "tbreak 88\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*open 2:.*OK.*test_open \\(\\) at.*$srcfile:88.*" \
+"Continuing\\..*open 2:.*EEXIST.*test_open \\(\\) at.*$srcfile:88.*" \
"Creating already existing file returns EEXIST"
send_gdb "tbreak 95\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*open 3:.*OK.*test_open \\(\\) at.*$srcfile:95.*" \
+"Continuing\\..*open 3:.*EISDIR.*test_open \\(\\) at.*$srcfile:95.*" \
"Open directory for writing returns EISDIR"
send_gdb "tbreak 102\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*open 4:.*OK.*test_open \\(\\) at.*$srcfile:102.*" \
+"Continuing\\..*open 4:.*ENOENT.*test_open \\(\\) at.*$srcfile:102.*" \
"Opening nonexistant file returns ENOENT"
send_gdb "tbreak 109\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "tbreak 119\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*open 5:.*OK.*test_open \\(\\) at.*$srcfile:119.*" \
+"Continuing\\..*open 5:.*EACCES.*test_open \\(\\) at.*$srcfile:119.*" \
"Open for write but no write permission returns EACCES"
send_gdb "tbreak 140\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "tbreak 145\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*write 2:.*OK.*test_write \\(\\) at.*$srcfile:145.*" \
+"Continuing\\..*write 2:.*EBADF.*test_write \\(\\) at.*$srcfile:145.*" \
"Write using invalid file descriptor returns EBADF"
send_gdb "tbreak 156\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*write 3:.*OK.*test_write \\(\\) at.*$srcfile:156.*" \
+"Continuing\\..*write 3:.*EBADF.*test_write \\(\\) at.*$srcfile:156.*" \
"Writing to a read-only file returns EBADF"
send_gdb "tbreak 182\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "tbreak 186\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*read 2:.*OK.*test_read \\(\\) at.*$srcfile:186.*" \
+"Continuing\\..*read 2:.*EBADF.*test_read \\(\\) at.*$srcfile:186.*" \
"Read using invalid file descriptor returns EBADF"
send_gdb "tbreak 221\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "tbreak 245\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*close 2:.*OK.*test_close \\(\\) at.*$srcfile:245.*" \
+"Continuing\\..*close 2:.*EBADF.*test_close \\(\\) at.*$srcfile:245.*" \
"Closing an invalid file descriptor returns EBADF"
send_gdb "tbreak 262\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "tbreak 267\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*stat 2:.*OK.*test_stat \\(\\) at.*$srcfile:267.*" \
-"Stat a NULL pathname returns ENOENT"
+ "Continuing\\..*stat 2:.*(ENOENT|EFAULT).*test_stat \\(\\) at.*$srcfile:267.*" \
+"Stat a NULL pathname returns ENOENT or EFAULT"
send_gdb "tbreak 272\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*stat 3:.*OK.*test_stat \\(\\) at.*$srcfile:272.*" \
+"Continuing\\..*stat 3:.*ENOENT.*test_stat \\(\\) at.*$srcfile:272.*" \
"Stat an empty pathname returns ENOENT"
send_gdb "tbreak 276\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*stat 4:.*OK.*test_stat \\(\\) at.*$srcfile:276.*" \
+"Continuing\\..*stat 4:.*ENOENT.*test_stat \\(\\) at.*$srcfile:276.*" \
"Stat a nonexistant file returns ENOENT"
send_gdb "tbreak 301\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "tbreak 305\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*fstat 2:.*OK.*test_fstat \\(\\) at.*$srcfile:305.*" \
+"Continuing\\..*fstat 2:.*EBADF.*test_fstat \\(\\) at.*$srcfile:305.*" \
"Fstat an invalid file descriptor returns EBADF"
send_gdb "tbreak 314\n" ; gdb_expect -re "$gdb_prompt $"
"Continuing\\..*system 1:.*OK.*test_system \\(\\) at.*$srcfile:347.*" \
"System(3) call"
+# Is this ok? POSIX says system returns a waitpid status?
send_gdb "tbreak 349\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
"Continuing\\..*system 2:.*OK.*test_system \\(\\) at.*$srcfile:349.*" \
send_gdb "tbreak 383\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*rename 2:.*OK.*test_rename \\(\\) at.*$srcfile:383.*" \
+"Continuing\\..*rename 2:.*EISDIR.*test_rename \\(\\) at.*$srcfile:383.*" \
"Renaming a file to existing directory returns EISDIR"
send_gdb "tbreak 388\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*rename 3:.*OK.*test_rename \\(\\) at.*$srcfile:388.*" \
+ "Continuing\\..*rename 3:.*(ENOTEMPTY|EEXIST).*test_rename \\(\\) at.*$srcfile:388.*" \
"Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST"
send_gdb "tbreak 393\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*rename 4:.*OK.*test_rename \\(\\) at.*$srcfile:393.*" \
+"Continuing\\..*rename 4:.*EINVAL.*test_rename \\(\\) at.*$srcfile:393.*" \
"Renaming a directory to a subdir of itself returns EINVAL"
send_gdb "tbreak 397\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*rename 5:.*OK.*test_rename \\(\\) at.*$srcfile:397.*" \
+"Continuing\\..*rename 5:.*ENOENT.*test_rename \\(\\) at.*$srcfile:397.*" \
"Renaming a nonexistant file returns ENOENT"
send_gdb "tbreak 412\n" ; gdb_expect -re "$gdb_prompt $"
setup_xfail "*-*-*"
}
gdb_test continue \
-"Continuing\\..*unlink 2:.*OK.*test_unlink \\(\\) at.*$srcfile:432.*" \
+"Continuing\\..*unlink 2:.*EACCES.*test_unlink \\(\\) at.*$srcfile:432.*" \
"Unlinking a file in a directory w/o write access returns EACCES"
send_gdb "tbreak 436\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*unlink 3:.*OK.*test_unlink \\(\\) at.*$srcfile:436.*" \
+"Continuing\\..*unlink 3:.*ENOENT.*test_unlink \\(\\) at.*$srcfile:436.*" \
"Unlinking a nonexistant file returns ENOENT"
send_gdb "tbreak 446\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "quit\n"
send_gdb "y\n"
-catch "system \"chmod -f +w dir2.fileio.test\""
-catch "system \"rm -rf *.fileio.test\""
+remote_exec build "test -r dir2.fileio.test && chmod -f +w dir2.fileio.test"
+remote_exec build "rm -rf *.fileio.test"
set timeout $oldtimeout
return 0