select: enhance test
authorEric Blake <eblake@redhat.com>
Wed, 3 Oct 2012 01:38:24 +0000 (19:38 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 3 Oct 2012 01:38:24 +0000 (19:38 -0600)
Make sure the test is not picking up stale errno values, and add
a test for nfds validation.

* tests/test-select.h (do_select_bad_nfd_nowait, test_bad_nfd):
New functions.
(test_function): Enhance test.
(do_select_bad_fd): Avoid any stale errno values.

ChangeLog
tests/test-select.h

index c27db0d..38a0f3f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2012-10-02  Eric Blake  <eblake@redhat.com>
 
+       select: enhance test
+       * tests/test-select.h (do_select_bad_nfd_nowait, test_bad_nfd):
+       New functions.
+       (test_function): Enhance test.
+       (do_select_bad_fd): Avoid any stale errno values.
+
        ptsname: reject invalid file descriptors
        http://www.austingroupbugs.net/view.php?id=503
        * m4/ptsname.m4 (gl_FUNC_PTSNAME): Probe for FreeBSD bug.
index af0e38c..e9cb7d0 100644 (file)
@@ -227,6 +227,29 @@ test_tty (select_fn my_select)
 #endif
 
 
+static int
+do_select_bad_nfd_nowait (int nfd, select_fn my_select)
+{
+  struct timeval tv0;
+  tv0.tv_sec = 0;
+  tv0.tv_usec = 0;
+  errno = 0;
+  return my_select (nfd, NULL, NULL, NULL, &tv0);
+}
+
+static void
+test_bad_nfd (select_fn my_select)
+{
+  if (do_select_bad_nfd_nowait (-1, my_select) != -1 || errno != EINVAL)
+    failed ("invalid errno after negative nfds");
+  /* Can't test FD_SETSIZE + 1 for EINVAL, since some systems allow
+     dynamically larger set size by redefining FD_SETSIZE anywhere up
+     to the actual maximum fd.  */
+  /* if (do_select_bad_nfd_nowait (FD_SETSIZE + 1, my_select) != -1 */
+  /*     || errno != EINVAL) */
+  /*   failed ("invalid errno after bogus nfds"); */
+}
+
 /* Test select(2) on invalid file descriptors.  */
 
 static int
@@ -243,6 +266,7 @@ do_select_bad_fd (int fd, int ev, struct timeval *timeout, select_fn my_select)
     FD_SET (fd, &wfds);
   if (ev & SEL_EXC)
     FD_SET (fd, &xfds);
+  errno = 0;
   return my_select (fd + 1, &rfds, &wfds, &xfds, timeout);
   /* In this case, when fd is invalid, on some platforms, the bit for fd
      is left alone in the fd_set, whereas on other platforms it is cleared.
@@ -426,6 +450,7 @@ test_function (select_fn my_select)
   test (test_tty, "TTY", my_select);
 #endif
 
+  result += test (test_bad_nfd, my_select, "Invalid nfd test");
   result += test (test_bad_fd, my_select, "Invalid fd test");
   result += test (test_connect_first, my_select, "Unconnected socket test");
   result += test (test_socket_pair, my_select, "Connected sockets test");