# HG changeset patch # User Eric Blake # Date 1349228304 21600 # Node ID 134fbc73d583925609bd9f89c8d692882aa8d8cc # Parent 4e2101c3d42cdc7ea6bc3b43e181e2314ad83126 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2012-10-02 Eric Blake + 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. diff --git a/tests/test-select.h b/tests/test-select.h --- 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");