bug-gnulib
[Top][All Lists]
Advanced

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

select tests: Avoid test failure on Cygwin


From: Bruno Haible
Subject: select tests: Avoid test failure on Cygwin
Date: Thu, 13 Dec 2018 22:27:34 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-138-generic; KDE/5.18.0; x86_64; ; )

When running the gnulib unit tests in sed-4.5.48-58eb on Cygwin, I see
a failure of the select tests:

  failed (invalid fd among rfds)
  failed (invalid fd among wfds)
  failed (invalid fd among xfds)

The sed-4.5.48-58eb snapshot is built with an Autoconf snapshot that
contains a bug: it reports

  checking whether we are cross compiling... yes

(instead of 'no'), and as a consequence

  checking whether select detects invalid fds... guessing no

(instead of 'yes'), leading to REPLACE_SELECT=1, and the gnulib
override in select.c sets errno to EINVAL, not EBADF, when
invoked with fd = 99 and nfds = 100 (apparently unlike the
original Cygwin select() function - cf. the comment in test-select.h
function test_bad_nfd).

This patch fixes the test in gnulib. The bug in Autoconf is separate.


2018-12-13  Bruno Haible  <address@hidden>

        select tests: Avoid test failure on Cygwin.
        * tests/test-select.h (test_bad_fd): Use an fd < FD_SETSIZE.

diff --git a/tests/test-select.h b/tests/test-select.h
index eae26b0..b0f17f3 100644
--- a/tests/test-select.h
+++ b/tests/test-select.h
@@ -242,9 +242,11 @@ test_bad_nfd (select_fn my_select)
   /* 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"); */
+#if 0
+  if (do_select_bad_nfd_nowait (FD_SETSIZE + 1, my_select) != -1
+      || errno != EINVAL)
+    failed ("invalid errno after bogus nfds");
+#endif
 }
 
 /* Test select(2) on invalid file descriptors.  */
@@ -294,6 +296,11 @@ test_bad_fd (select_fn my_select)
 # else
   fd = 99;
 # endif
+  /* Even on the best POSIX compliant platforms, values of fd >= FD_SETSIZE
+     require an nfds argument that is > FD_SETSIZE and thus may lead to EINVAL,
+     not EBADF.  */
+  if (fd >= FD_SETSIZE)
+    fd = FD_SETSIZE - 1;
   close (fd);
 
   if (do_select_bad_fd_nowait (fd, SEL_IN, my_select) == 0 || errno != EBADF)




reply via email to

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