1
/* -*- buffer-read-only: t -*- vi: set ro: */
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3
1
/* Test of select() substitute.
4
Copyright (C) 2008-2011 Free Software Foundation, Inc.
2
Copyright (C) 2008-2012 Free Software Foundation, Inc.
6
4
This program is free software: you can redistribute it and/or modify
7
5
it under the terms of the GNU General Public License as published by
87
85
s = socket (AF_INET, SOCK_STREAM, 0);
88
setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
89
90
memset (&ia, 0, sizeof (ia));
90
91
ia.sin_family = AF_INET;
91
92
inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
231
do_select_bad_nfd_nowait (int nfd, select_fn my_select)
237
return my_select (nfd, NULL, NULL, NULL, &tv0);
241
test_bad_nfd (select_fn my_select)
243
if (do_select_bad_nfd_nowait (-1, my_select) != -1 || errno != EINVAL)
244
failed ("invalid errno after negative nfds");
245
/* Can't test FD_SETSIZE + 1 for EINVAL, since some systems allow
246
dynamically larger set size by redefining FD_SETSIZE anywhere up
247
to the actual maximum fd. */
248
/* if (do_select_bad_nfd_nowait (FD_SETSIZE + 1, my_select) != -1 */
249
/* || errno != EINVAL) */
250
/* failed ("invalid errno after bogus nfds"); */
253
/* Test select(2) on invalid file descriptors. */
256
do_select_bad_fd (int fd, int ev, struct timeval *timeout, select_fn my_select)
258
fd_set rfds, wfds, xfds;
270
return my_select (fd + 1, &rfds, &wfds, &xfds, timeout);
271
/* In this case, when fd is invalid, on some platforms, the bit for fd
272
is left alone in the fd_set, whereas on other platforms it is cleared.
273
So, don't check the bit for fd here. */
277
do_select_bad_fd_nowait (int fd, int ev, select_fn my_select)
282
return do_select_bad_fd (fd, ev, &tv0, my_select);
286
test_bad_fd (select_fn my_select)
288
/* This tests fails on OSF/1 and native Windows, even with fd = 16. */
289
#if !(defined __osf__ || defined WINDOWS_NATIVE)
292
/* On Linux, Mac OS X, *BSD, values of fd like 99 or 399 are discarded
293
by the kernel early and therefore do *not* lead to EBADF, as required
295
# if defined __linux__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
301
if (do_select_bad_fd_nowait (fd, SEL_IN, my_select) == 0 || errno != EBADF)
302
failed ("invalid fd among rfds");
303
if (do_select_bad_fd_nowait (fd, SEL_OUT, my_select) == 0 || errno != EBADF)
304
failed ("invalid fd among wfds");
305
if (do_select_bad_fd_nowait (fd, SEL_EXC, my_select) == 0 || errno != EBADF)
306
failed ("invalid fd among xfds");
232
311
/* Test select(2) for unconnected nonblocking sockets. */
365
444
test_function (select_fn my_select)
369
448
#ifdef INTERACTIVE
370
449
printf ("Please press Enter\n");
371
450
test (test_tty, "TTY", my_select);
374
result = test (test_connect_first, my_select, "Unconnected socket test");
453
result += test (test_bad_nfd, my_select, "Invalid nfd test");
454
result += test (test_bad_fd, my_select, "Invalid fd test");
455
result += test (test_connect_first, my_select, "Unconnected socket test");
375
456
result += test (test_socket_pair, my_select, "Connected sockets test");
376
457
result += test (test_accept_first, my_select, "General socket test with fork");
377
458
result += test (test_pipe, my_select, "Pipe test");