changeset 17122:134fbc73d583

select: enhance test 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.
author Eric Blake <eblake@redhat.com>
date Tue, 02 Oct 2012 19:38:24 -0600
parents 4e2101c3d42c
children e71d6495bb31
files ChangeLog tests/test-select.h
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/tests/test-select.h
+++ b/tests/test-select.h
@@ -227,6 +227,29 @@
 #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 @@
     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 (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");