bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] test-fsync: yet another enhancement


From: Eric Blake
Subject: [PATCH] test-fsync: yet another enhancement
Date: Fri, 16 Sep 2011 17:16:30 -0600

* tests/test-fsync.c (main): Also test behavior on read-only text
file.

Signed-off-by: Eric Blake <address@hidden>
---

I've tested Linux so far, we'll see what testing on other platforms reveals.

 ChangeLog          |    6 ++++++
 tests/test-fsync.c |   15 +++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7a9a868..97633be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-09-16  Eric Blake  <address@hidden>
+
+       test-fsync: yet another enhancement
+       * tests/test-fsync.c (main): Also test behavior on read-only text
+       file.
+
 2011-09-16  Bruno Haible  <address@hidden>

        Enhance fsync, fdatasync tests.
diff --git a/tests/test-fsync.c b/tests/test-fsync.c
index e866248..b9f0fb0 100644
--- a/tests/test-fsync.c
+++ b/tests/test-fsync.c
@@ -32,6 +32,8 @@ main (void)
   int fd;
   const char *file = "test-fsync.txt";

+  /* Assuming stdin and stdout are ttys, fsync is allowed to fail, but
+     may succeed as an extension.  */
   for (fd = 0; fd < 2; fd++)
     if (fsync (fd) != 0)
       {
@@ -41,6 +43,7 @@ main (void)
                 );
       }

+  /* fsync must fail on invalid fd.  */
   errno = 0;
   ASSERT (fsync (-1) == -1);
   ASSERT (errno == EBADF);
@@ -50,6 +53,18 @@ main (void)
   ASSERT (write (fd, "hello", 5) == 5);
   ASSERT (fsync (fd) == 0);
   ASSERT (close (fd) == 0);
+
+  /* For a read-only regular file input file descriptor, fsync should
+     succeed (since at least atime changes can be synchronized).  */
+  fd = open (file, O_RDONLY);
+  ASSERT (0 <= fd);
+  {
+    char buf[1];
+    ASSERT (read (fd, buf, sizeof buf) == sizeof buf);
+  }
+  ASSERT (fsync (fd) == 0);
+  ASSERT (close (fd) == 0);
+
   ASSERT (unlink (file) == 0);

   return 0;
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]