diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-01 21:54:19 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-01 21:54:19 +0000 |
commit | a7c39d3d3fb4a529b29d432b81769617093965d8 (patch) | |
tree | d63d59fe676604f9095b3b742a1759c28d220f68 /testsuites/fstests/fserror/test.c | |
parent | 2011-08-01 Xiang Cui <medivhc@gmail.com> (diff) | |
download | rtems-a7c39d3d3fb4a529b29d432b81769617093965d8.tar.bz2 |
2011-08-01 Xiang Cui <medivhc@gmail.com>
* imfs_fslink/Makefile.am, imfs_fssymlink/Makefile.am,
mimfs_fslink/Makefile.am, mimfs_fssymlink/Makefile.am,
mrfs_fslink/Makefile.am, mrfs_fssymlink/Makefile.am,
mrfs_support/fs_config.h: Correcting from previous commit of
incorrect tarball.
* fserror/fserror.doc, fserror/test.c, fspatheval/patheval.doc,
fspatheval/test.c, fspermission/fspermission.doc,
fspermission/test.c, fsrdwr/fsrdwr.doc, fsrdwr/init.c,
fstime/fstime.doc, fstime/test.c, imfs_fserror/.cvsignore,
imfs_fserror/Makefile.am, imfs_fslink/.cvsignore,
imfs_fspatheval/.cvsignore, imfs_fspatheval/Makefile.am,
imfs_fspermission/.cvsignore, imfs_fspermission/Makefile.am,
imfs_fsrdwr/.cvsignore, imfs_fsrdwr/Makefile.am,
imfs_fssymlink/.cvsignore, imfs_fstime/.cvsignore,
imfs_fstime/Makefile.am, imfs_support/fs_supprot.h,
mdosfs_fserror/.cvsignore, mdosfs_fserror/Makefile.am,
mdosfs_fspatheval/.cvsignore, mdosfs_fspatheval/Makefile.am,
mdosfs_fsrdwr/.cvsignore, mdosfs_fsrdwr/Makefile.am,
mdosfs_fstime/.cvsignore, mdosfs_fstime/Makefile.am,
mimfs_fserror/.cvsignore, mimfs_fserror/Makefile.am,
mimfs_fslink/.cvsignore, mimfs_fspatheval/.cvsignore,
mimfs_fspatheval/Makefile.am, mimfs_fspermission/.cvsignore,
mimfs_fspermission/Makefile.am, mimfs_fsrdwr/.cvsignore,
mimfs_fsrdwr/Makefile.am, mimfs_fssymlink/.cvsignore,
mimfs_fstime/.cvsignore, mimfs_fstime/Makefile.am,
mrfs_fserror/.cvsignore, mrfs_fserror/Makefile.am,
mrfs_fslink/.cvsignore, mrfs_fspatheval/.cvsignore,
mrfs_fspatheval/Makefile.am, mrfs_fspermission/.cvsignore,
mrfs_fspermission/Makefile.am, mrfs_fsrdwr/.cvsignore,
mrfs_fsrdwr/Makefile.am, mrfs_fssymlink/.cvsignore,
mrfs_fstime/.cvsignore, mrfs_fstime/Makefile.am: New files.
Diffstat (limited to 'testsuites/fstests/fserror/test.c')
-rw-r--r-- | testsuites/fstests/fserror/test.c | 372 |
1 files changed, 372 insertions, 0 deletions
diff --git a/testsuites/fstests/fserror/test.c b/testsuites/fstests/fserror/test.c new file mode 100644 index 0000000000..d30eb5c6d9 --- /dev/null +++ b/testsuites/fstests/fserror/test.c @@ -0,0 +1,372 @@ +/* + * COPYRIGHT (c) 1989-2011. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id Exp $ + */ + +#include <sys/stat.h> +#include <limits.h> +#include <fcntl.h> +#include <errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "fstest.h" + +void open_mkdir_error (void) +{ + int fd; + int status; + char *name01 = "name01"; + char *name02 = "name02"; + char *name03 = "name03"; + + char name[20]; + + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + + const char *wd = __func__; + + /* + * Create a new directory and change the current directory to this + */ + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); + + + /* + * Create a file and a directory for test. + */ + fd = creat (name01, mode); + status = close (fd); + rtems_test_assert (status == 0); + status = mkdir (name02, mode); + rtems_test_assert (status == 0); + + /* + * O_CREAT and O_EXCL are set, and the named file exists. + */ + EXPECT_ERROR (EEXIST, open, name01, O_CREAT | O_EXCL); + + EXPECT_ERROR (EEXIST, mkdir, name01, mode); + /* + * The named file is a directory + * and oflag includes O_WRONLY or O_RDWR. + */ + EXPECT_ERROR (EISDIR, open, name02, O_WRONLY); + EXPECT_ERROR (EISDIR, open, name02, O_RDWR); + + /* + * O_CREAT is not set and the named file does not exist + * or O_CREAT is set and either the path prefix does not exist or + * the path argument points to an empty string. + */ + + sprintf (name, "%s/%s", name03, name02); + EXPECT_ERROR (ENOENT, open, name, O_WRONLY); + EXPECT_ERROR (ENOENT, open, "", O_WRONLY); + EXPECT_ERROR (ENOENT, open, name03, O_WRONLY); + + EXPECT_ERROR (ENOENT, mkdir, name, mode); + EXPECT_ERROR (ENOENT, mkdir, "", mode); + + /* + * A component of the path prefix is not a directory. + */ + + sprintf (name, "%s/%s", name01, name02); + EXPECT_ERROR (ENOTDIR, open, name, O_WRONLY); + + EXPECT_ERROR (ENOTDIR, mkdir, name, mode); + /* + * The fildes argument is not a valid file descriptor. + */ + EXPECT_ERROR (EBADF, close, -1); + EXPECT_ERROR (EBADF, close, 100); + + /* + * Go back to parent directory + */ + status = chdir (".."); + rtems_test_assert (status == 0); + +} + +void rename_error (void) +{ + + int fd; + int status; + char *name01 = "name01"; + char *name02 = "name02"; + char *name03 = "name03"; + char *nonexistence = "name04"; + + char name[20]; + + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + const char *wd = __func__; + + /* + *Create a new directory and change the current directory to this + */ + + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); + + + /* + * Create a new directory and a new directory in it + */ + + status = mkdir (name01, mode); + rtems_test_assert (status == 0); + status = mkdir (name02, mode); + rtems_test_assert (status == 0); + sprintf (name, "%s/%s", name01, name03); + status = mkdir (name, mode); + rtems_test_assert (status == 0); + + /* + * The link named by new is a directory that is + * not an empty directory. + */ + status = rename (name02, name01); + rtems_test_assert (status != 0); + rtems_test_assert (errno == EEXIST || errno == ENOTEMPTY); + /* + * The new directory pathname contains a path prefix + * that names the old directory. + */ + EXPECT_ERROR (EINVAL, rename, name01, name); + /* + * The new argument points to a directory and + * the old argument points to a file that is not a directory. + */ + fd = creat (name03, mode); + status = close (fd); + rtems_test_assert (status == 0); + EXPECT_ERROR (EISDIR, rename, name03, name02); + + /* + * The link named by old does not name an existing file, + * or either old or new points to an empty string. + */ + + EXPECT_ERROR (ENOENT, rename, nonexistence, name01); + EXPECT_ERROR (ENOENT, rename, "", name01); + EXPECT_ERROR (ENOENT, rename, name01, ""); + + /* + * A component of either path prefix is not a directory; + * or the old argument names a directory and new argument names + * a non-directory file. + */ + + sprintf (name, "%s/%s", name03, name01); + EXPECT_ERROR (ENOTDIR, rename, name, name03); + EXPECT_ERROR (ENOTDIR, rename, name03, name); + EXPECT_ERROR (ENOTDIR, rename, name02, name03); + + /* + * Go back to parent directory + */ + status = chdir (".."); + rtems_test_assert (status == 0); +} + +void truncate_error (void) +{ + + int fd; + int status; + char *file = "name"; + + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + + const char *wd = __func__; + + /* + *Create a new directory and change the current directory to this + */ + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); + /* + * Create a file + */ + fd = creat (file, mode); + status = close (fd); + rtems_test_assert (status == 0); + + + /* + * The length argument was less than 0. + */ + EXPECT_ERROR (EINVAL, truncate, file, -1); + + /* + * Go back to parent directory + */ + status = chdir (".."); + rtems_test_assert (status == 0); +} + + +void rmdir_unlink_error (void) +{ + int status; + int fd; + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + char *nonexistence = "name04"; + + const char *wd = __func__; + + /* + * Create a new directory and change the current directory to this + */ + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); + + /* + * Create a new directory and a file in it for test + */ + status = mkdir ("tmp", mode); + rtems_test_assert (status == 0); + fd = creat ("tmp/file", mode); + status = close (fd); + rtems_test_assert (status == 0); + + + + /* + * The path argument names a directory that is not an empty directory, + * or there are hard links to the directory other than dot or a single entry in dot-dot. + */ + + EXPECT_ERROR (ENOTEMPTY, rmdir, ".."); + EXPECT_ERROR (ENOTEMPTY, rmdir, "tmp"); + + + /* + * The path argument contains a last component that is dot. + */ + + + EXPECT_ERROR (EINVAL, rmdir, "."); + EXPECT_ERROR (EINVAL, rmdir, "tmp/."); + + /* + * A component of path does not name an existing file, + * or the path argument names a nonexistent directory or points to an empty string + */ + EXPECT_ERROR (ENOENT, rmdir, ""); + EXPECT_ERROR (ENOENT, rmdir, nonexistence); + + EXPECT_ERROR (ENOENT, unlink, ""); + EXPECT_ERROR (ENOENT, unlink, nonexistence); + + /* + * component of path is not a directory. + */ + + EXPECT_ERROR (ENOTDIR, rmdir, "tmp/file"); + + EXPECT_ERROR (ENOTDIR, unlink, "tmp/file/dir"); + /* + * Go back to parent directory + */ + status = chdir (".."); + rtems_test_assert (status == 0); + + +} + +void rdwr_error (void) +{ + + int status; + int fd; + char *file01 = "name01"; + char *databuf = "test"; + char *readbuf[10]; + + + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + const char *wd = __func__; + + /* + * Create a new directory and change the current directory to this + */ + status = mkdir (wd, mode); + rtems_test_assert (status == 0); + status = chdir (wd); + rtems_test_assert (status == 0); + + fd = open (file01, O_WRONLY | O_CREAT, mode); + + /* + * The fildes argument is not a valid file descriptor open for reading. + */ + + EXPECT_ERROR (EBADF, read, fd, readbuf, 10); + EXPECT_ERROR (EBADF, read, 100, readbuf, 10); + + status = close (fd); + rtems_test_assert (status == 0); + /* + * The fildes argument is not a valid file descriptor open for writing. + */ + fd = open (file01, O_RDONLY, mode); + + EXPECT_ERROR (EBADF, write, fd, databuf, 10); + EXPECT_ERROR (EBADF, write, 100, readbuf, 10); + + /* + * The whence argument is not a proper value, + * or the resulting file offset would be negative for a regular file, + * block special file, or directory. + */ + + EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_END); + EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_CUR); + EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_SET); + + status = close (fd); + rtems_test_assert (status == 0); + + EXPECT_ERROR (EBADF, lseek, fd, -100, SEEK_SET); + /* + * Go back to parent directory + */ + status = chdir (".."); + rtems_test_assert (status == 0); + +} + +void test (void) +{ + + puts ("\n\n*** ERROR TEST ***"); + open_mkdir_error (); + rename_error (); + truncate_error (); + rmdir_unlink_error (); + rdwr_error (); + puts ("*** END OF ERROR TEST ***"); +} |