[rtems commit] fstests/fsrdwr: Add test case

Sebastian Huber sebh at rtems.org
Wed Feb 20 08:21:07 UTC 2013


Module:    rtems
Branch:    master
Commit:    4ddeb343a14dfdc0d05577aae78bdc476e60d666
Changeset: http://git.rtems.org/rtems/commit/?id=4ddeb343a14dfdc0d05577aae78bdc476e60d666

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sun Feb 17 12:57:27 2013 +0100

fstests/fsrdwr: Add test case

---

 testsuites/fstests/fsrdwr/init.c                 |   57 ++++++++++++++++++++++
 testsuites/fstests/imfs_fsrdwr/imfs_fsrdwr.scn   |    2 +-
 testsuites/fstests/mimfs_fsrdwr/mimfs_fsrdwr.scn |    1 +
 3 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/testsuites/fstests/fsrdwr/init.c b/testsuites/fstests/fsrdwr/init.c
index 9821cff..e8576b4 100644
--- a/testsuites/fstests/fsrdwr/init.c
+++ b/testsuites/fstests/fsrdwr/init.c
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <memory.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "fstest.h"
 #include "pmacros.h"
@@ -748,6 +749,61 @@ block_read_and_write (void)
   test_case_leave ();
 }
 
+static void
+write_until_no_space_is_left (void)
+{
+  static const char file [] = "zero";
+  int fd;
+  struct stat st;
+  int status;
+  blksize_t block_size;
+  char *out;
+  ssize_t chunk_size;
+  ssize_t written;
+  off_t total;
+
+  /* Use the root directory to account for some FAT12 or FAT16 specialities */
+  printf ("test case: %s\n", __func__);
+
+  fd = open (file, O_RDWR | O_CREAT | O_TRUNC, mode);
+  rtems_test_assert (fd >= 0);
+
+  status = fstat (fd, &st);
+  rtems_test_assert (status == 0);
+  rtems_test_assert (st.st_size == 0);
+  rtems_test_assert (st.st_blksize > 0);
+  block_size = st.st_blksize;
+
+  out = calloc (1, block_size);
+  rtems_test_assert (out != NULL);
+
+  total = 0;
+  chunk_size = block_size / 2;
+  do {
+    errno = 0;
+
+    written = write (fd, out, chunk_size);
+    if (written > 0) {
+      total += written;
+    }
+
+    chunk_size = block_size;
+  } while (written > 0);
+
+  rtems_test_assert (written == -1);
+  rtems_test_assert (errno == ENOSPC || errno == EFBIG);
+
+  status = close (fd);
+  rtems_test_assert (status == 0);
+
+  /* Do not use fstat() to do the path evaluation again */
+  status = lstat (file, &st);
+  rtems_test_assert (status == 0);
+  rtems_test_assert (st.st_size == total);
+
+  free (out);
+}
+
 void
 test (void)
 {
@@ -756,4 +812,5 @@ test (void)
   truncate_test03 ();
   truncate_to_zero ();
   block_read_and_write ();
+  write_until_no_space_is_left ();
 }
diff --git a/testsuites/fstests/imfs_fsrdwr/imfs_fsrdwr.scn b/testsuites/fstests/imfs_fsrdwr/imfs_fsrdwr.scn
index d0bef8e..bc50588 100644
--- a/testsuites/fstests/imfs_fsrdwr/imfs_fsrdwr.scn
+++ b/testsuites/fstests/imfs_fsrdwr/imfs_fsrdwr.scn
@@ -15,8 +15,8 @@ test case: block_rw_case_1
 test case: block_rw_case_2
 test case: block_rw_case_3
 test case: block_rw_case_4
+test case: write_until_no_space_is_left
 
 
 Shutting down filesystem IMFS
 *** END OF FILE SYSTEM TEST ( IMFS ) ***
-
diff --git a/testsuites/fstests/mimfs_fsrdwr/mimfs_fsrdwr.scn b/testsuites/fstests/mimfs_fsrdwr/mimfs_fsrdwr.scn
index 37ea03c..2ba20b7 100644
--- a/testsuites/fstests/mimfs_fsrdwr/mimfs_fsrdwr.scn
+++ b/testsuites/fstests/mimfs_fsrdwr/mimfs_fsrdwr.scn
@@ -15,6 +15,7 @@ test case: block_rw_case_1
 test case: block_rw_case_2
 test case: block_rw_case_3
 test case: block_rw_case_4
+test case: write_until_no_space_is_left
 
 
 Shutting down filesystem MOUNTED IMFS




More information about the vc mailing list