[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] test-fsync: enhance tests
From: |
Bruno Haible |
Subject: |
Re: [PATCH 1/2] test-fsync: enhance tests |
Date: |
Fri, 16 Sep 2011 22:37:49 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Eric Blake wrote:
>
> - if (fsync (0) != 0)
> + if (fsync (STDOUT_FILENO) != 0)
> {
> ASSERT (errno == EINVAL /* POSIX */
> || errno == ENOTSUP /* seen on MacOS X 10.5 */
> || errno == EBADF /* seen on AIX 7.1 */
> - );
> + );
> }
The original intent of that code was to test the behaviour of fsync on a
read-only file descriptor, and STDIN_FILENO is one. Why should it be better
to test STDOUT_FILENO?
Why not test both? Like this proposed patch. (Which also add blank
lines as separators, to make the test more readable.)
--- tests/test-fsync.c.orig Fri Sep 16 22:35:05 2011
+++ tests/test-fsync.c Fri Sep 16 22:34:09 2011
@@ -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);
--
In memoriam Georgiy Gongadze <http://en.wikipedia.org/wiki/Georgiy_Gongadze>