From 780b9e0b408cf6067ebf2243b2caed3f1ed2a9c3 Mon Sep 17 00:00:00 2001 From: Chuanchang Jia Date: Mon, 30 Jan 2012 22:39:01 +0100 Subject: [PATCH] poll tests: Make test more robust. * tests/test-poll.c: Include macros.h. (test_accept_first, test_pair, test_socket_pair, test_pipe): Verify return value of various I/O operations. * modules/poll-tests (Files): Add tests/macros.h. --- ChangeLog | 9 +++++++++ modules/poll-tests | 3 ++- tests/test-poll.c | 25 ++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f5e23422..be64d3cd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-01-29 Chuanchang Jia (tiny change) + Bruno Haible + + poll tests: Make test more robust. + * tests/test-poll.c: Include macros.h. + (test_accept_first, test_pair, test_socket_pair, test_pipe): Verify + return value of various I/O operations. + * modules/poll-tests (Files): Add tests/macros.h. + 2012-01-29 Bruno Haible sys_stat: Fix support for mingw64 and MSVC. diff --git a/modules/poll-tests b/modules/poll-tests index ab291a090..39d9e04fc 100644 --- a/modules/poll-tests +++ b/modules/poll-tests @@ -1,6 +1,7 @@ Files: -tests/signature.h tests/test-poll.c +tests/signature.h +tests/macros.h Depends-on: stdbool diff --git a/tests/test-poll.c b/tests/test-poll.c index 8738858c9..b525190e6 100644 --- a/tests/test-poll.c +++ b/tests/test-poll.c @@ -36,6 +36,8 @@ SIGNATURE_CHECK (poll, int, (struct pollfd[], nfds_t, int)); #include #include +#include "macros.h" + #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ # define WINDOWS_NATIVE #endif @@ -261,9 +263,10 @@ test_accept_first (void) { addrlen = sizeof (ia); c = accept (s, (struct sockaddr *) &ia, &addrlen); + ASSERT (c >= 0); close (s); - write (c, "foo", 3); - read (c, buf, 3); + ASSERT (write (c, "foo", 3) == 3); + ASSERT (read (c, buf, 3) == 3); shutdown (c, SHUT_RD); close (c); exit (0); @@ -272,15 +275,16 @@ test_accept_first (void) { close (s); c = connect_to_socket (true); + ASSERT (c >= 0); if (poll1_nowait (c, POLLOUT | POLLWRNORM | POLLRDBAND) != (POLLOUT | POLLWRNORM)) failed ("cannot write after blocking connect"); - write (c, "foo", 3); + ASSERT (write (c, "foo", 3) == 3); wait (&pid); if (poll1_wait (c, POLLIN) != POLLIN) failed ("cannot read data left in the socket by closed process"); - read (c, buf, 3); - write (c, "foo", 3); + ASSERT (read (c, buf, 3) == 3); + ASSERT (write (c, "foo", 3) == 3); if ((poll1_wait (c, POLLIN | POLLOUT) & (POLLHUP | POLLERR)) == 0) failed ("expecting POLLHUP after shutdown"); close (c); @@ -304,7 +308,7 @@ test_pair (int rd, int wd) != POLLWRNORM) failed ("expecting POLLWRNORM before writing"); - write (wd, "foo", 3); + ASSERT (write (wd, "foo", 3) == 3); if (poll1_wait (rd, POLLIN | POLLRDNORM) != (POLLIN | POLLRDNORM)) failed ("expecting POLLIN | POLLRDNORM after writing"); if (poll1_nowait (rd, POLLIN) != POLLIN) @@ -312,7 +316,7 @@ test_pair (int rd, int wd) if (poll1_nowait (rd, POLLRDNORM) != POLLRDNORM) failed ("expecting POLLRDNORM after writing"); - read (rd, buf, 3); + ASSERT (read (rd, buf, 3) == 3); } @@ -327,12 +331,15 @@ test_socket_pair (void) int s = open_server_socket (); int c1 = connect_to_socket (false); int c2 = accept (s, (struct sockaddr *) &ia, &addrlen); + ASSERT (s >= 0); + ASSERT (c1 >= 0); + ASSERT (c2 >= 0); close (s); test_pair (c1, c2); close (c1); - write (c2, "foo", 3); + ASSERT (write (c2, "foo", 3) == 3); if ((poll1_nowait (c2, POLLIN | POLLOUT) & (POLLHUP | POLLERR)) == 0) failed ("expecting POLLHUP after shutdown"); @@ -347,7 +354,7 @@ test_pipe (void) { int fd[2]; - pipe (fd); + ASSERT (pipe (fd) >= 0); test_pair (fd[0], fd[1]); close (fd[0]); if ((poll1_wait (fd[1], POLLIN | POLLOUT) & (POLLHUP | POLLERR)) == 0) -- 2.11.0