diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-10-23 16:10:26 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-10-31 13:18:50 +0100 |
commit | facf9dcea6ee0f97d4404a1734909c762e91559b (patch) | |
tree | 6eea3929a60657daad04b8b8c48400c2b569e6d3 /testsuite/syscalls01 | |
parent | sleep01: New test (diff) | |
download | rtems-libbsd-facf9dcea6ee0f97d4404a1734909c762e91559b.tar.bz2 |
Use select() from FreeBSD
Diffstat (limited to 'testsuite/syscalls01')
-rw-r--r-- | testsuite/syscalls01/test_main.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/testsuite/syscalls01/test_main.c b/testsuite/syscalls01/test_main.c index 6f64c21e..7e4db14a 100644 --- a/testsuite/syscalls01/test_main.c +++ b/testsuite/syscalls01/test_main.c @@ -32,6 +32,7 @@ #include <sys/cdefs.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/select.h> #include <sys/socket.h> #include <sys/filio.h> #include <netinet/in.h> @@ -1206,6 +1207,79 @@ test_socket_recv_and_recvfrom_and_recvmsg(void) assert(rtems_resource_snapshot_check(&snapshot)); } +static void +no_mem_socket_select(int fd) +{ + struct fd_set set; + int nfds; + int rv; + + FD_ZERO(&set); + FD_SET(fd, &set); + nfds = fd + 1; + + errno = 0; + rv = select(nfds, &set, NULL, NULL, NULL); + assert(rv == -1); + assert(errno == ENOMEM); +} + +static void +test_socket_select(void) +{ + rtems_resource_snapshot snapshot; + struct fd_set set; + int nfds; + int sd; + int rv; + + puts("test socket select"); + + sd = socket(PF_INET, SOCK_DGRAM, 0); + assert(sd >= 0); + + rv = close(sd); + assert(rv == 0); + + FD_ZERO(&set); + FD_SET(sd, &set); + nfds = sd + 1; + + errno = 0; + rv = select(nfds, &set, NULL, NULL, NULL); + assert(rv == -1); + assert(errno == EBADF); + + rtems_resource_snapshot_take(&snapshot); + + sd = socket(PF_INET, SOCK_DGRAM, 0); + assert(sd >= 0); + + do_no_mem_test(no_mem_socket_select, sd); + + FD_ZERO(&set); + nfds = -1; + + errno = 0; + rv = select(nfds, &set, NULL, NULL, NULL); + assert(rv == -1); + assert(errno == EINVAL); + + rv = close(sd); + assert(rv == 0); + + FD_ZERO(&set); + FD_SET(sd, &set); + nfds = sd + 1; + + errno = 0; + rv = select(nfds, &set, NULL, NULL, NULL); + assert(rv == -1); + assert(errno == EBADF); + + assert(rtems_resource_snapshot_check(&snapshot)); +} + static const char prog_name[] = "prog"; static int @@ -1412,6 +1486,7 @@ test_main(void) test_socket_read_and_write(); test_socket_send_and_sendto_and_sendmsg(); test_socket_recv_and_recvfrom_and_recvmsg(); + test_socket_select(); test_bsd_program(); test_warn(); |