From abd89efaeb4366d99ad6407c415bce8d6bafb316 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 16 Sep 2011 17:15:39 -0600 Subject: [PATCH] test-fsync: yet another enhancement * tests/test-fsync.c (main): Also test behavior on read-only text file. Signed-off-by: Eric Blake --- ChangeLog | 6 ++++++ tests/test-fsync.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7a9a86805..97633beb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-09-16 Eric Blake + + test-fsync: yet another enhancement + * tests/test-fsync.c (main): Also test behavior on read-only text + file. + 2011-09-16 Bruno Haible Enhance fsync, fdatasync tests. diff --git a/tests/test-fsync.c b/tests/test-fsync.c index e86624862..b9f0fb0e9 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; -- 2.11.0