The test-binary-io unit test fails under MinGW running under Windows XP.
OS: Windows XP
MinGW Version: 20110211
Gnulib Version: 2011-02-28
This test failure can be easily reproduced with the following commands given a skeleton automake project:
$ gnulib-tool --with-tests --import poll
$ Make the modifications to
Makefile.am and
configure.ac as instructed by the tool
$ autoreconf -i
$ ./configure && make
$ cd tests
$ make check
And in the output you can see:
PASS: test-alignof.exe
PASS: test-alloca-opt.exe
PASS: test-arpa_inet.exe
FAIL: test-binary-io.shPASS: test-c-ctype.exe
PASS: test-errno.exe
PASS: test-fcntl-h.exe
PASS: test-gettimeofday.exe
PASS: test-inet_pton.exe
PASS: test-netinet_in.exe
PASS:
test-perror.shPASS: test-pipe.exe
PASS: test-poll-h.exe
Unconnected socket test... passed
Connected sockets test... passed
General socket test with fork... passed
Pipe test... failed (expecting POLLHUP after shutdown)FAIL: test-poll.exeUnconnected socket test... passed
Connected sockets test... passed
General socket test with fork... passed
Pipe test... passed
PASS: test-select.exe
FAIL:
test-select-in.shPASS:
test-select-out.shPASS: test-sockets.exe
PASS: test-stdbool.exe
PASS: test-stddef.exe
PASS: test-stdint.exe
PASS: test-stdio.exe
PASS: test-strerror.exe
PASS: test-string.exe
PASS: test-sys_ioctl.exe
PASS: test-sys_select.exe
PASS: test-sys_socket.exe
PASS: test-sys_time.exe
PASS: test-unistd.exe
PASS: test-verify.exe
PASS:
test-verify.sh====================
3 of 31 tests failed
====================
The root cause for the test-binary-io seems to stem from the file contents of the redirected stdout (the
test-binary-io.sh script calls ./test-binary-io.exe >
t-bin-out1.tmp) not being written immediately upon the call to fclose(stdout) on line 54. Note that I did try to add a a fflush(stdout) prior to the fclose(stdout) statement, but that didn't resolve the issue. Adding a sleep statement after the fclose(stdout) for 2 seconds resolves the failure (interestingly a 1 second delay does NOT resolve it), but that approach is obviously a poor one that is likely system dependent.
Instead, I wrote the following patch which uses a separate temp file as opposed to stdout, but I believe accomplishes the same task of verifying the SET_BINARY macro in a portable fashion.
$ cat
test-binary-io.c.patch--- test-binary-io.c 2011-03-08 16:36:21 -0600
+++
test-binary-io.c.new 2011-03-08 16:51:55 -0600
@@ -49,16 +49,19 @@ main ()
unlink ("t-bin-out2.tmp");
/* Test the SET_BINARY macro. */
- SET_BINARY (1);
- fputs ("Hello\n", stdout);
- fclose (stdout);
- fclose (stderr);
+ {
+ FILE *f = fopen ("t-bin-out3.tmp", "w+");
+ SET_BINARY (fileno (f));
+ fputs ("Hello\n", f);
+ fclose (f);
+ }
{
struct stat statbuf;
- if (stat ("t-bin-out1.tmp", &statbuf) < 0)
+ if (stat ("t-bin-out3.tmp", &statbuf) < 0)
exit (1);
ASSERT (
statbuf.st_size == 6);
}
+ unlink ("t-bin-out3.tmp");
return 0;
}
I also put the new temp file into the
test-binary-io.sh script to ensure it gets cleaned up if there is a failure.
$ cat
test-binary-io.sh.patch---
test-binary-io.sh 2011-03-08 16:36:21 -0600
+++
test-binary-io.sh.new 2011-03-08 16:57:52 -0600
@@ -3,7 +3,7 @@
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
-tmpfiles="$tmpfiles
t-bin-out1.tmp t-bin-out2.tmp"
+tmpfiles="$tmpfiles
t-bin-out1.tmp t-bin-out2.tmp t-bin-out3.tmp"
./test-binary-io${EXEEXT} >
t-bin-out1.tmp || exit 1
rm -fr $tmpfiles
Rerunning make check with the above patches gives:
$ make check
...
PASS: test-alignof.exe
PASS: test-alloca-opt.exe
PASS: test-arpa_inet.exe
PASS: test-binary-io.shPASS: test-c-ctype.exe
PASS: test-errno.exe
PASS: test-fcntl-h.exe
PASS: test-gettimeofday.exe
PASS: test-inet_pton.exe
PASS: test-netinet_in.exe
PASS:
test-perror.shPASS: test-pipe.exe
PASS: test-poll-h.exe
Unconnected socket test... passed
Connected sockets test... passed
General socket test with fork... passed
Pipe test... failed (expecting POLLHUP after shutdown)
FAIL: test-poll.exeUnconnected socket test... passed
Connected sockets test... passed
General socket test with fork... passed
Pipe test... passed
PASS: test-select.exe
FAIL:
test-select-in.shPASS:
test-select-out.shPASS: test-sockets.exe
PASS: test-stdbool.exe
PASS: test-stddef.exe
PASS: test-stdint.exe
PASS: test-stdio.exe
PASS: test-strerror.exe
PASS: test-string.exe
PASS: test-sys_ioctl.exe
PASS: test-sys_select.exe
PASS: test-sys_socket.exe
PASS: test-sys_time.exe
PASS: test-unistd.exe
PASS: test-verify.exe
PASS:
test-verify.sh====================
2 of 31 tests failed
====================
As you can see there are two more failures (Pipe test and test-poll.exe), but I haven't had a chance to look into them yet.
Regards,
David Collins