Hi,
As discussed in [1], I created a new fstest to check the rename()
implementation against the POSIX specification [2].
What the attached patch does not test:
- Testing the existance of a link visible to other processes during the
rename process (ensuring that there is always a reference to the file).
Not sure about the best way to test this.
- Testing that after all processes close their references to a file
after it was removed by rename() the file contents are removed (or
marked as free space, I guess). I only found platform dependent ways of
dealing with disk block's.
- Testing errno values in error situations. There is already a fstest
named fserror which purpose seems to be checking errno values for a
bunch of functions (rename included, but with some errno values
missing). Not sure if I should put them in this test or add to fserror.
This test uses the MOUNTED IMFS filesystem, for no particular reason, so
if that's an issue please let me know.
[1] - http://www.rtems.org/pipermail/rtems-users/2014-January/012378.html
[2] - http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
--André Marques
>From fe91c9c1072112c5d191a231da0ef4c04159dce6 Mon Sep 17 00:00:00 2001
From: Andre Marques <andre.lousa.marq...@gmail.com>
Date: Sat, 8 Feb 2014 11:40:49 +0000
Subject: [PATCH] New fstest to check rename POSIX conformance
---
testsuites/fstests/Makefile.am | 1 +
testsuites/fstests/configure.ac | 1 +
testsuites/fstests/fsrename/fsrename.doc | 19 +
testsuites/fstests/fsrename/fsrename.scn | 166 +++++
testsuites/fstests/fsrename/test.c | 788 +++++++++++++++++++++
testsuites/fstests/mimfs_fsrename/Makefile.am | 31 +
.../fstests/mimfs_fsrename/mimfs_fsrename.scn | 174 +++++
7 files changed, 1180 insertions(+)
create mode 100644 testsuites/fstests/fsrename/fsrename.doc
create mode 100644 testsuites/fstests/fsrename/fsrename.scn
create mode 100644 testsuites/fstests/fsrename/test.c
create mode 100644 testsuites/fstests/mimfs_fsrename/Makefile.am
create mode 100644 testsuites/fstests/mimfs_fsrename/mimfs_fsrename.scn
diff --git a/testsuites/fstests/Makefile.am b/testsuites/fstests/Makefile.am
index ed87f1b..539a220 100644
--- a/testsuites/fstests/Makefile.am
+++ b/testsuites/fstests/Makefile.am
@@ -31,6 +31,7 @@ SUBDIRS += mimfs_fspermission
SUBDIRS += mimfs_fsrdwr
SUBDIRS += mimfs_fssymlink
SUBDIRS += mimfs_fstime
+SUBDIRS += mimfs_fsrename
SUBDIRS += mrfs_fserror
SUBDIRS += mrfs_fslink
SUBDIRS += mrfs_fspatheval
diff --git a/testsuites/fstests/configure.ac b/testsuites/fstests/configure.ac
index 571f428..e1337cb 100644
--- a/testsuites/fstests/configure.ac
+++ b/testsuites/fstests/configure.ac
@@ -107,6 +107,7 @@ mimfs_fspermission/Makefile
mimfs_fsrdwr/Makefile
mimfs_fssymlink/Makefile
mimfs_fstime/Makefile
+mimfs_fsrename/Makefile
mrfs_fserror/Makefile
mrfs_fslink/Makefile
mrfs_fspatheval/Makefile
diff --git a/testsuites/fstests/fsrename/fsrename.doc b/testsuites/fstests/fsrename/fsrename.doc
new file mode 100644
index 0000000..c99f915
--- /dev/null
+++ b/testsuites/fstests/fsrename/fsrename.doc
@@ -0,0 +1,19 @@
+# COPYRIGHT (c) 2014 - .
+# Andre Marques <andre.lousa.marq...@gmail.com>
+#
+# 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.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: fsrename
+
+directives:
+
+ + rename
+
+concepts:
+
+ + check if rename implementation conforms to POSIX.1-2008
\ No newline at end of file
diff --git a/testsuites/fstests/fsrename/fsrename.scn b/testsuites/fstests/fsrename/fsrename.scn
new file mode 100644
index 0000000..703a656
--- /dev/null
+++ b/testsuites/fstests/fsrename/fsrename.scn
@@ -0,0 +1,166 @@
+*** RENAME TEST ***
+
+Old is a simbolic link and rename operates on the simbolic link itself
+
+Testing rename with arguments: symlink01, name02 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 65
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+Testing access with arguments: symlink01, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 71
+Testing if name02 is now a symlink
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 81
+
+New is a simbolic link and rename operates on the simbolic link itself
+
+Testing rename with arguments: name02, symlink01 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 107
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: symlink01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name02, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 113
+Testing that symlink01 is not a symlink
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 123
+
+Rename an open file
+
+Testing write with arguments: fd, test_data, len EXPECT "len"
+PASS
+Testing rename with arguments: name01, name02 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 205
+Testing access with arguments: name01, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 212
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+Testing lseek with arguments: fd, 0, 0 EXPECT "0"
+PASS
+Testing read with arguments: fd, data_buf, len EXPECT "len"
+PASS
+Testing parent folder timestamp update
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 227
+
+Rename file with itself
+
+Testing rename with arguments: name01, name01 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 287
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+
+Rename file with itself through a hard link in another directory
+
+Testing rename with arguments: name01, name EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 305
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+
+Rename directory with file
+
+Testing rename with arguments: dir01, name01 EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename file with directory
+
+Testing rename with arguments: name01, dir01 EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename directory with ancestor directory
+
+Testing rename with arguments: dir02, name EXPECT "-1"
+PASS
+Testing access with arguments: dir02, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+
+Rename directory with non empty directory
+
+Testing rename with arguments: dir01, dir02 EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+Testing access with arguments: dir02, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+
+Rename empty directory with another empty directory
+
+Testing rename with arguments: dir03, dir04 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 453
+Testing access with arguments: dir03, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 455
+Testing access with arguments: dir04, 0 EXPECT "0"
+PASS
+
+Rename file with non existant file
+
+Testing rename with arguments: name01, name02 EXPECT "0"
+PASS
+Testing access with arguments: name01, 0 EXPECT "-1"
+PASS
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+
+Rename directory with non existant directory
+
+Testing rename with arguments: dir01, dir02 EXPECT "0"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "-1"
+PASS
+Testing access with arguments: dir02, 0 EXPECT "0"
+PASS
+
+Rename directory with current directory
+
+Testing rename with arguments: "." , dir01 EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+Testing rename with arguments: dir01, "." EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename directory with previous directory
+
+Testing rename with arguments: ".." , dir01 EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+Testing rename with arguments: dir01, ".." EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename two files on a directory with no write permission
+
+Testing rename with arguments: name01 , name02 EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+
+Rename two files in different dirs, with and without write access
+
+Testing rename with arguments: name01 , name EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+*** END OF RENAME TEST ***
\ No newline at end of file
diff --git a/testsuites/fstests/fsrename/test.c b/testsuites/fstests/fsrename/test.c
new file mode 100644
index 0000000..c133476
--- /dev/null
+++ b/testsuites/fstests/fsrename/test.c
@@ -0,0 +1,788 @@
+/*
+ * COPYRIGHT (c) 2014 - .
+ * Andre Marques <andre.lousa.marq...@gmail.com>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "fstest.h"
+#include "pmacros.h"
+
+static void symbolic_link_test (void)
+{
+
+ uint32_t fd;
+ uint32_t status;
+ char *name01 = "name01";
+ char *name02 = "name02";
+
+ char *symlink01 = "slink01";
+
+ mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
+ const char *wd = __func__;
+
+ struct stat statbuf;
+
+ /*
+ * 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);
+
+ /*
+ * The new argument points to a file and
+ * the old argument points to a symbolic link to another file.
+ */
+
+ puts("\nOld is a simbolic link and rename operates on the simbolic link itself\n");
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ fd = creat (name02, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ status = symlink (name01, symlink01);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, symlink01, name02);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, name02, F_OK);
+
+ EXPECT_EQUAL (-1, access, symlink01, F_OK);
+
+ status = lstat (name02, &statbuf);
+ rtems_test_assert (status == 0);
+
+ puts("Testing if name02 is now a symlink");
+
+ if(S_ISLNK(statbuf.st_mode) != 0)
+ FS_PASS ();
+ else
+ FS_FAIL ();
+
+ unlink (name01);
+
+ unlink (name02);
+
+ unlink (symlink01);
+
+ /*
+ * The new argument points to a symbolic link to another file and
+ * the old argument points to a file.
+ */
+
+ puts("\nNew is a simbolic link and rename operates on the simbolic link itself\n");
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ fd = creat (name02, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ status = symlink (name01, symlink01);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, name02, symlink01);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, symlink01, F_OK);
+
+ EXPECT_EQUAL (-1, access, name02, F_OK);
+
+ status = lstat(symlink01, &statbuf);
+ rtems_test_assert (status == 0);
+
+ puts("Testing that symlink01 is not a symlink");
+
+ if(S_ISLNK(statbuf.st_mode) == 0)
+ FS_PASS ();
+ else
+ FS_FAIL ();
+
+ /*
+ * Clear directory
+ */
+
+ unlink (name01);
+
+ unlink (name02);
+
+ unlink (symlink01);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+static void open_file_test (void)
+{
+
+ uint32_t fd;
+ uint32_t status;
+ char *name01 = "name01";
+ char *name02 = "name02";
+
+ char* test_data = "Test Data";
+ char data_buf[10];
+ size_t len = strlen (test_data);
+
+ mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
+ const char *wd = __func__;
+
+ struct stat statbuf;
+
+ time_t st_ctim01;
+ time_t st_ctim02;
+
+ /*
+ * 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);
+
+ /*
+ * The new argument points to a file and
+ * the old argument points to another file.
+ */
+
+ puts("\nRename an open file\n");
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ fd = creat (name02, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ fd = open (name02, O_RDWR);
+
+ EXPECT_EQUAL (len, write ,fd, test_data, len);
+
+ status = stat(".", &statbuf);
+ rtems_test_assert (status == 0);
+
+ st_ctim01 = statbuf.st_ctime;
+
+ sleep (1000);
+
+ EXPECT_EQUAL (0, rename, name01, name02);
+
+ status = stat(".", &statbuf);
+ rtems_test_assert (status == 0);
+
+ st_ctim02 = statbuf.st_ctime;
+
+ EXPECT_EQUAL (-1, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, name02, F_OK);
+
+ EXPECT_EQUAL (0, lseek, fd, SEEK_SET, 0);
+
+ EXPECT_EQUAL (len, read, fd, data_buf, len);
+
+ status = close(fd);
+
+ puts("Testing parent folder timestamp update");
+
+ if(st_ctim01 != st_ctim02)
+ FS_PASS ();
+ else
+ FS_FAIL ();
+
+ /*
+ * Clear directory
+ */
+
+ unlink (name01);
+
+ unlink (name02);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+static void same_file_test (void)
+{
+
+ uint32_t fd;
+ uint32_t status;
+ char *name01 = "name01";
+ char *name02 = "name02";
+
+ char *dir01 = "dir01";
+
+ char name[30];
+
+ 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);
+
+ /*
+ * The new argument points to a file and
+ * the old argument points to the same file on the same directory.
+ */
+
+ puts("\nRename file with itself\n");
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, name01, name01);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ /*
+ * The new argument points to a file and
+ * the old argument points to the same file from another directory.
+ */
+
+ puts("\nRename file with itself through a hard link in another directory\n");
+
+ status = mkdir (dir01, mode);
+ rtems_test_assert (status == 0);
+
+ sprintf (name, "%s/%s", dir01, name02);
+ status = link (name01, name);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, name01, name);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, name, F_OK);
+
+ /*
+ * Clear directory
+ */
+
+ unlink (name01);
+
+ unlink (name);
+
+ rmdir (dir01);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+static void directory_test (void)
+{
+
+ uint32_t fd;
+ uint32_t status;
+ char *name01 = "name01";
+ char *name02 = "name02";
+
+ char *dir01 = "dir01";
+ char *dir02 = "dir02";
+ char *dir03 = "dir03";
+ char *dir04 = "dir04";
+
+ char name[30];
+
+ 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 = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ status = mkdir (dir01, mode);
+ rtems_test_assert (status == 0);
+
+ /*
+ * The new argument points to a file and
+ * the old argument points to a directory.
+ */
+
+ puts("\nRename directory with file\n");
+
+ EXPECT_EQUAL (-1, rename, dir01, name01);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ /*
+ * The new argument points to a directory and
+ * the old argument points to a file.
+ */
+
+ puts("\nRename file with directory\n");
+
+ EXPECT_EQUAL (-1, rename, name01, dir01);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ /*
+ * The new argument points to an empty directory and
+ * the old argument points to an ancestor directory of new.
+ */
+
+ puts("\nRename directory with ancestor directory\n");
+
+ status = mkdir (dir02, mode);
+ rtems_test_assert (status == 0);
+
+ sprintf (name, "%s/%s", dir02, dir01);
+ status = mkdir (name, mode);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (-1, rename, dir02, name);
+
+ EXPECT_EQUAL (0, access, dir02, F_OK);
+
+ EXPECT_EQUAL (0, access, name, F_OK);
+
+ rmdir (name);
+
+ /*
+ * The new argument points to an empty directory and
+ * the old argument points to a non empty directory.
+ */
+
+ puts("\nRename directory with non empty directory\n");
+
+ sprintf (name, "%s/%s", dir02, name02);
+ fd = creat (name, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (-1, rename, dir01, dir02);
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ EXPECT_EQUAL (0, access, dir02, F_OK);
+
+ EXPECT_EQUAL (0, access, name, F_OK);
+
+ unlink (name);
+
+ /*
+ * The new argument points to an empty directory and
+ * the old argument points to other empty directory.
+ */
+
+ puts("\nRename empty directory with another empty directory\n");
+
+ status = mkdir (dir03, mode);
+ rtems_test_assert (status == 0);
+
+ status = mkdir (dir04, mode);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, dir03, dir04);
+
+ EXPECT_EQUAL (-1, access, dir03, F_OK);
+
+ EXPECT_EQUAL (0, access, dir04, F_OK);
+
+ /*
+ * Clear directory
+ */
+
+ unlink (name01);
+
+ rmdir (dir01);
+
+ rmdir (dir02);
+
+ rmdir (dir03);
+
+ rmdir (dir04);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+static void empty_new_arg_test (void)
+{
+
+ uint32_t fd;
+ uint32_t status;
+ char *name01 = "name01";
+ char *name02 = "name02";
+
+ char *dir01 = "dir01";
+ char *dir02 = "dir02";
+
+ 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);
+
+ /*
+ * The new argument points to a non existant file and
+ * the old argument points to a file.
+ */
+
+ puts("\nRename file with non existant file\n");
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, name01, name02);
+
+ EXPECT_EQUAL (-1, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, name02, F_OK);
+
+ /*
+ * The new argument points to a non existant directory and
+ * the old argument points to a directory.
+ */
+
+ puts("\nRename directory with non existant directory\n");
+
+ status = mkdir (dir01, mode);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (0, rename, dir01, dir02);
+
+ EXPECT_EQUAL (-1, access, dir01, F_OK);
+
+ EXPECT_EQUAL (0, access, dir02, F_OK);
+
+ /*
+ * Clear directory
+ */
+
+ unlink (name01);
+
+ unlink (name02);
+
+ rmdir (dir01);
+
+ rmdir (dir02);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+static void arg_format_test (void)
+{
+ uint32_t status;
+ char *dir01 = "dir01";
+
+ 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);
+
+ /*
+ * The new argument points to a directory and
+ * the old argument points to current directory.
+ */
+
+ puts("\nRename directory with current directory\n");
+
+ status = mkdir (dir01, mode);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (-1, rename, "." , dir01);
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ /*
+ * The new argument points to current directory and
+ * the old argument points to a directory.
+ */
+
+ EXPECT_EQUAL (-1, rename, dir01, ".");
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ /*
+ * The new argument points to a directory and
+ * the old argument points to previous directory.
+ */
+
+ puts("\nRename directory with previous directory\n");
+
+ EXPECT_EQUAL (-1, rename, ".." , dir01);
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ /*
+ * The new argument points to previous directory and
+ * the old argument points to a directory.
+ */
+
+ EXPECT_EQUAL (-1, rename, dir01, "..");
+
+ EXPECT_EQUAL (0, access, dir01, F_OK);
+
+ /*
+ * Clear directory
+ */
+
+ rmdir (dir01);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+static void write_permission_test (void)
+{
+ uint32_t fd;
+ uint32_t status;
+ char *name01 = "name01";
+ char *name02 = "name02";
+
+ char *dir01 = "dir01";
+ char *dir02 = "dir02";
+
+ char name[20];
+
+ mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
+ mode_t no_write_access = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP
+ | S_IROTH | S_IXOTH;
+
+ 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);
+
+ /*
+ * The new argument points to a file and
+ * the old argument points to another file,
+ * both inside a directory with no write permission.
+ */
+
+ puts("\nRename two files on a directory with no write permission \n");
+
+ status = mkdir (dir01, mode);
+ rtems_test_assert (status == 0);
+
+ status = chdir (dir01);
+ rtems_test_assert (status == 0);
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ fd = creat (name02, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ status = chmod (".", no_write_access);
+ rtems_test_assert (status == 0);
+
+ EXPECT_EQUAL (-1, rename, name01 , name02);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, name02, F_OK);
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * The new argument points to a file in a directory with no write access and
+ * the old argument points to another file on a directory with write acess.
+ */
+
+ puts("\nRename two files in different dirs, with and without write access\n");
+
+ status = mkdir (dir02, mode);
+ rtems_test_assert (status == 0);
+
+ status = chdir (dir02);
+ rtems_test_assert (status == 0);
+
+ fd = creat (name01, mode);
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ sprintf (name, "../%s/%s", dir01, name02);
+
+ EXPECT_EQUAL (-1, rename, name01 , name);
+
+ EXPECT_EQUAL (0, access, name01, F_OK);
+
+ EXPECT_EQUAL (0, access, name, F_OK);
+
+ unlink (name01);
+
+ sprintf (name, "../%s", dir01);
+ status = chmod (name, mode);
+ rtems_test_assert (status == 0);
+
+ sprintf (name, "../%s/%s", dir01, name01);
+ unlink (name);
+
+ sprintf (name, "../%s/%s", dir01, name02);
+ unlink (name);
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Clear directory
+ */
+
+ rmdir (dir01);
+
+ rmdir (dir02);
+
+ /*
+ * Go back to parent directory
+ */
+
+ status = chdir ("..");
+ rtems_test_assert (status == 0);
+
+ /*
+ * Remove test directory
+ */
+
+ status = rmdir (wd);
+ rtems_test_assert (status == 0);
+}
+
+void test (void)
+{
+
+ puts ("\n\n*** RENAME TEST ***");
+ symbolic_link_test ();
+ open_file_test ();
+ same_file_test ();
+ directory_test ();
+ empty_new_arg_test ();
+ arg_format_test ();
+ write_permission_test ();
+ puts ("*** END OF RENAME TEST ***");
+}
diff --git a/testsuites/fstests/mimfs_fsrename/Makefile.am b/testsuites/fstests/mimfs_fsrename/Makefile.am
new file mode 100644
index 0000000..531347d
--- /dev/null
+++ b/testsuites/fstests/mimfs_fsrename/Makefile.am
@@ -0,0 +1,31 @@
+
+rtems_tests_PROGRAMS = mimfs_fsrename
+mimfs_fsrename_SOURCES = ../fsrename/test.c
+mimfs_fsrename_SOURCES += ../support/fstest_support.c
+mimfs_fsrename_SOURCES += ../support/fstest_support.h
+mimfs_fsrename_SOURCES += ../support/fstest.h
+mimfs_fsrename_SOURCES += ../../psxtests/include/pmacros.h
+mimfs_fsrename_SOURCES += ../mimfs_support/fs_support.c
+mimfs_fsrename_SOURCES += ../mimfs_support/fs_config.h
+
+dist_rtems_tests_DATA = mimfs_fsrename.scn
+#dist_rtems_tests_DATA += mimfs_fsrename.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+
+AM_CPPFLAGS += -I$(top_srcdir)/support
+AM_CPPFLAGS += -I$(top_srcdir)/mimfs_support
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+AM_CPPFLAGS += -I$(top_srcdir)/../psxtests/include
+
+LINK_OBJS = $(mimfs_fsrename_OBJECTS)
+LINK_LIBS = $(mimfs_fsrename_LDLIBS)
+
+mimfs_fsrename$(EXEEXT): $(mimfs_fsrename_OBJECTS) $(mimfs_fsrename_DEPENDENCIES)
+ @rm -f mimfs_fsrename$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/fstests/mimfs_fsrename/mimfs_fsrename.scn b/testsuites/fstests/mimfs_fsrename/mimfs_fsrename.scn
new file mode 100644
index 0000000..170e11c
--- /dev/null
+++ b/testsuites/fstests/mimfs_fsrename/mimfs_fsrename.scn
@@ -0,0 +1,174 @@
+*** FILE SYSTEM TEST ( MOUNTED IMFS ) ***
+Initializing filesystem MOUNTED IMFS
+
+
+*** RENAME TEST ***
+
+Old is a simbolic link and rename operates on the simbolic link itself
+
+Testing rename with arguments: symlink01, name02 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 65
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+Testing access with arguments: symlink01, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 71
+Testing if name02 is now a symlink
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 81
+
+New is a simbolic link and rename operates on the simbolic link itself
+
+Testing rename with arguments: name02, symlink01 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 107
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: symlink01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name02, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 113
+Testing that symlink01 is not a symlink
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 123
+
+Rename an open file
+
+Testing write with arguments: fd, test_data, len EXPECT "len"
+PASS
+Testing rename with arguments: name01, name02 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 205
+Testing access with arguments: name01, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 212
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+Testing lseek with arguments: fd, 0, 0 EXPECT "0"
+PASS
+Testing read with arguments: fd, data_buf, len EXPECT "len"
+PASS
+Testing parent folder timestamp update
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 227
+
+Rename file with itself
+
+Testing rename with arguments: name01, name01 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 287
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+
+Rename file with itself through a hard link in another directory
+
+Testing rename with arguments: name01, name EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 305
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+
+Rename directory with file
+
+Testing rename with arguments: dir01, name01 EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename file with directory
+
+Testing rename with arguments: name01, dir01 EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename directory with ancestor directory
+
+Testing rename with arguments: dir02, name EXPECT "-1"
+PASS
+Testing access with arguments: dir02, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+
+Rename directory with non empty directory
+
+Testing rename with arguments: dir01, dir02 EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+Testing access with arguments: dir02, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+
+Rename empty directory with another empty directory
+
+Testing rename with arguments: dir03, dir04 EXPECT "0"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 453
+Testing access with arguments: dir03, 0 EXPECT "-1"
+FAIL ../../../../../../../../Code/c/src/../../testsuites/fstests/mimfs_fsrename/../fsrename/test.c: 455
+Testing access with arguments: dir04, 0 EXPECT "0"
+PASS
+
+Rename file with non existant file
+
+Testing rename with arguments: name01, name02 EXPECT "0"
+PASS
+Testing access with arguments: name01, 0 EXPECT "-1"
+PASS
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+
+Rename directory with non existant directory
+
+Testing rename with arguments: dir01, dir02 EXPECT "0"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "-1"
+PASS
+Testing access with arguments: dir02, 0 EXPECT "0"
+PASS
+
+Rename directory with current directory
+
+Testing rename with arguments: "." , dir01 EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+Testing rename with arguments: dir01, "." EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename directory with previous directory
+
+Testing rename with arguments: ".." , dir01 EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+Testing rename with arguments: dir01, ".." EXPECT "-1"
+PASS
+Testing access with arguments: dir01, 0 EXPECT "0"
+PASS
+
+Rename two files on a directory with no write permission
+
+Testing rename with arguments: name01 , name02 EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name02, 0 EXPECT "0"
+PASS
+
+Rename two files in different dirs, with and without write access
+
+Testing rename with arguments: name01 , name EXPECT "-1"
+PASS
+Testing access with arguments: name01, 0 EXPECT "0"
+PASS
+Testing access with arguments: name, 0 EXPECT "0"
+PASS
+*** END OF RENAME TEST ***
+
+
+Shutting down filesystem MOUNTED IMFS
+*** END OF FILE SYSTEM TEST ( MOUNTED IMFS ) ***
\ No newline at end of file
--
1.8.3.2
_______________________________________________
rtems-devel mailing list
rtems-devel@rtems.org
http://www.rtems.org/mailman/listinfo/rtems-devel