summaryrefslogtreecommitdiff
path: root/tests/test-fsync.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-09-16 17:15:39 -0600
committerEric Blake <eblake@redhat.com>2011-09-16 17:15:39 -0600
commitabd89efaeb4366d99ad6407c415bce8d6bafb316 (patch)
tree93a20a9e3bcb628dbf7cb267a0dd5c43441476e8 /tests/test-fsync.c
parentf52a5c387483cc1e0a87952f1b60a9a288425c7a (diff)
downloadgnulib-abd89efaeb4366d99ad6407c415bce8d6bafb316.tar.gz
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>
Diffstat (limited to 'tests/test-fsync.c')
-rw-r--r--tests/test-fsync.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test-fsync.c b/tests/test-fsync.c
index e86624862a..b9f0fb0e95 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;