# HG changeset patch # User Eric Blake # Date 1316214939 21600 # Node ID c96b3b10e57966401cc971f6c0f80f48fb260479 # Parent 76e03c88266cd893caae78cc647d8068cc3c7efc test-fsync: yet another enhancement * tests/test-fsync.c (main): Also test behavior on read-only text file. Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- 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 --- 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;