changeset 15632:c96b3b10e579

test-fsync: yet another enhancement * tests/test-fsync.c (main): Also test behavior on read-only text file. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Fri, 16 Sep 2011 17:15:39 -0600
parents 76e03c88266c
children c2c292001fc0
files ChangeLog tests/test-fsync.c
diffstat 2 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-09-16  Eric Blake  <eblake@redhat.com>
+
+	test-fsync: yet another enhancement
+	* tests/test-fsync.c (main): Also test behavior on read-only text
+	file.
+
 2011-09-16  Bruno Haible  <bruno@clisp.org>
 
 	Enhance fsync, fdatasync tests.
--- a/tests/test-fsync.c
+++ b/tests/test-fsync.c
@@ -32,6 +32,8 @@
   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 @@
                 );
       }
 
+  /* fsync must fail on invalid fd.  */
   errno = 0;
   ASSERT (fsync (-1) == -1);
   ASSERT (errno == EBADF);
@@ -50,6 +53,18 @@
   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;