Mercurial > hg > octave-kai > gnulib-hg
changeset 15631:76e03c88266c
Enhance fsync, fdatasync tests.
* tests/test-fsync.c (main): Test both STDIN_FILENO and STDOUT_FILENO.
* tests/test-fdatasync.c (main): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 16 Sep 2011 23:55:06 +0200 |
parents | 4c853bdac60b |
children | c96b3b10e579 |
files | ChangeLog tests/test-fdatasync.c tests/test-fsync.c |
diffstat | 3 files changed, 28 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-09-16 Bruno Haible <bruno@clisp.org> + + Enhance fsync, fdatasync tests. + * tests/test-fsync.c (main): Test both STDIN_FILENO and STDOUT_FILENO. + * tests/test-fdatasync.c (main): Likewise. + 2011-09-16 Bruno Haible <bruno@clisp.org> Support for MSVC compiler: Ensure mode_t gets defined.
--- a/tests/test-fdatasync.c +++ b/tests/test-fdatasync.c @@ -32,21 +32,25 @@ int fd; const char *file = "test-fdatasync.txt"; - if (fdatasync (STDOUT_FILENO) != 0) - { - ASSERT (errno == EINVAL /* POSIX */ - || errno == ENOTSUP /* seen on MacOS X 10.5 */ - || errno == EBADF /* seen on AIX 7.1 */ - ); - } + for (fd = 0; fd < 2; fd++) + if (fdatasync (fd) != 0) + { + ASSERT (errno == EINVAL /* POSIX */ + || errno == ENOTSUP /* seen on MacOS X 10.5 */ + || errno == EBADF /* seen on AIX 7.1 */ + ); + } + errno = 0; ASSERT (fdatasync (-1) == -1); ASSERT (errno == EBADF); + fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644); ASSERT (0 <= fd); ASSERT (write (fd, "hello", 5) == 5); ASSERT (fdatasync (fd) == 0); ASSERT (close (fd) == 0); + #if 0 /* POSIX is self-contradictory on whether fdatasync must fail on read-only file descriptors. Glibc allows it, as does our @@ -58,6 +62,7 @@ ASSERT (errno == EBADF); ASSERT (close (fd) == 0); #endif + ASSERT (unlink (file) == 0); return 0;
--- a/tests/test-fsync.c +++ b/tests/test-fsync.c @@ -32,16 +32,19 @@ int fd; const char *file = "test-fsync.txt"; - if (fsync (STDOUT_FILENO) != 0) - { - ASSERT (errno == EINVAL /* POSIX */ - || errno == ENOTSUP /* seen on MacOS X 10.5 */ - || errno == EBADF /* seen on AIX 7.1 */ - ); - } + for (fd = 0; fd < 2; fd++) + if (fsync (fd) != 0) + { + ASSERT (errno == EINVAL /* POSIX */ + || errno == ENOTSUP /* seen on MacOS X 10.5 */ + || errno == EBADF /* seen on AIX 7.1 */ + ); + } + errno = 0; ASSERT (fsync (-1) == -1); ASSERT (errno == EBADF); + fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644); ASSERT (0 <= fd); ASSERT (write (fd, "hello", 5) == 5);