bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnulib] compilation warning


From: Bruno Haible
Subject: Re: [gnulib] compilation warning
Date: Mon, 30 Jan 2012 22:43:07 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Hi,

Chuanchang Jia wrote:
> I'm compiling libvirt project, and I met the following compilation warning
> when run 'make check',
> I saw our codes haven't done any check for return value of 'read', 'write'
> and 'pipe' operations in
> test-poll.c. IMHO, we should check related return value, although it's just
> a test case.

Thanks. I like your patch, not because it fixes some warnings, but because
it makes the test more reliable.

Applied like this. (The "tiny change" marker is not meant to minimize
your effort, rather it indicates that we can accept it in gnulib without
having a format copyrigh assignment from you.)

Bruno


2012-01-29  Chuanchang Jia  <address@hidden>  (tiny change)
            Bruno Haible  <address@hidden>

        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.

--- modules/poll-tests.orig     Mon Jan 30 22:33:14 2012
+++ modules/poll-tests  Mon Jan 30 21:48:17 2012
@@ -1,6 +1,7 @@
 Files:
-tests/signature.h
 tests/test-poll.c
+tests/signature.h
+tests/macros.h
 
 Depends-on:
 stdbool
--- tests/test-poll.c.orig      Mon Jan 30 22:33:14 2012
+++ tests/test-poll.c   Mon Jan 30 21:46:55 2012
@@ -36,6 +36,8 @@
 #include <sys/ioctl.h>
 #include <errno.h>
 
+#include "macros.h"
+
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 # define WINDOWS_NATIVE
 #endif
@@ -261,9 +263,10 @@
     {
       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 @@
     {
       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 @@
       != 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 @@
   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 @@
   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 @@
 {
   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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]