diff options
Diffstat (limited to 'usr/src/test')
| -rw-r--r-- | usr/src/test/libc-tests/runfiles/default.run | 3 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/Makefile | 1 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/select/Makefile | 64 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/select/select.sh | 41 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/select/select_test.c | 126 |
5 files changed, 235 insertions, 0 deletions
diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run index baff3372da..9ac4e183cd 100644 --- a/usr/src/test/libc-tests/runfiles/default.run +++ b/usr/src/test/libc-tests/runfiles/default.run @@ -54,6 +54,9 @@ outputdir = /var/tmp/test_results [/opt/libc-tests/tests/random/arc4random_preforksig] [/opt/libc-tests/tests/random/arc4key.ksh] +[/opt/libc-tests/tests/select/select.sh] +timeout = 600 + [/opt/libc-tests/tests/aligned_alloc.32] [/opt/libc-tests/tests/aligned_alloc.64] [/opt/libc-tests/tests/c11_threads.32] diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index a259d28c89..586ac08383 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -22,6 +22,7 @@ SUBDIRS = \ nl_langinfo \ priv_gettext \ random \ + select \ strerror \ symbols \ threads \ diff --git a/usr/src/test/libc-tests/tests/select/Makefile b/usr/src/test/libc-tests/tests/select/Makefile new file mode 100644 index 0000000000..d7d6fa7641 --- /dev/null +++ b/usr/src/test/libc-tests/tests/select/Makefile @@ -0,0 +1,64 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# Copyright 2016, Richard Lowe. + +include $(SRC)/Makefile.master +include $(SRC)/Makefile.master.64 +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/cmd/Makefile.cmd.64 + +ROOTOPTPKG = $(ROOT)/opt/libc-tests +TESTDIR = $(ROOTOPTPKG)/tests/select +ROOTBINDIR = $(ROOTOPTPKG)/bin + +PROGS= select_test + +C99MODE= $(C99_ENABLE) + +select_test: select_test.c + $(LINK64.c) -o $@ select_test.c $(LDLIBS64) + $(POST_PROCESS) + +SCRIPTS=select.sh +CMDS = $(PROGS:%=$(TESTDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%) + +$(SCRIPTS) $(CMDS) := FILEMODE = 0555 + +$(CMDS): $(TESTDIR) $(PROGS) + +all: $(PROGS) + +clean: + +clobber: clean + -$(RM) $(PROGS) + +install: all $(CMDS) + +lint: + +$(ROOTBINDIR): + $(INS.dir) + +$(ROOTBINDIR)/%: % + $(INS.file) + +$(TESTDIR): + $(INS.dir) + +$(TESTDIR)/%: % + $(INS.file) + +$(TESTDIR)/%: % + $(INS.file) + +.KEEP_STATE: diff --git a/usr/src/test/libc-tests/tests/select/select.sh b/usr/src/test/libc-tests/tests/select/select.sh new file mode 100644 index 0000000000..f0bd25c68f --- /dev/null +++ b/usr/src/test/libc-tests/tests/select/select.sh @@ -0,0 +1,41 @@ +#! /usr/bin/sh +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# Copyright 2016, Richard Lowe. + +select_test=$(dirname $0)/select_test + + +# Below the stack and bulk alloc limits +i=0 +while (( $i < 500 )); do + i=$(($i + 1)) + + $select_test 512 || exit 1 +done; + +# above the stack limit +i=0 +while (( $i < 500 )); do + i=$(($i + 1)) + + $select_test 2048 || exit 1 +done; + +# above the bulk limit +i=0 +while (( $i < 500 )); do + i=$(($i + 1)) + + $select_test 9001 || exit 1 +done; diff --git a/usr/src/test/libc-tests/tests/select/select_test.c b/usr/src/test/libc-tests/tests/select/select_test.c new file mode 100644 index 0000000000..f6af3718cb --- /dev/null +++ b/usr/src/test/libc-tests/tests/select/select_test.c @@ -0,0 +1,126 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* Copyright 2016, Richard Lowe. */ + +#include <sys/select.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> + +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +void +diff_sets(fd_set *a, fd_set *b, size_t size) +{ + for (int i = 0; i < size; i++) { + if (FD_ISSET(i, a) != FD_ISSET(i, b)) + printf("fd %d: %d should be %d\n", i, FD_ISSET(i, a), + FD_ISSET(i, b)); + } +} + +void +print_set(fd_set *a, size_t size) +{ + for (int i = 0; i < size; i++) { + if (FD_ISSET(i, a)) + putc('1', stdout); + else + putc('0', stdout); + } + + putc('\n', stdout); +} + +int +main(int argc, char **argv) +{ + struct timeval tv = {0, 0}; + fd_set check, proto; + fd_set *sread = NULL, *swrite = NULL, *serr = NULL; + int null, zero, maxfd = -1, nfds; + char buf[1]; + + if (argc != 2) + errx(1, "usage: select_test <number of fds>"); + + nfds = atoi(argv[1]); + if (errno != 0) + err(1, "couldn't convert %s to int", argv[1]); + + if (nfds > FD_SETSIZE) + errx(1, "can't have more fds than FD_SETSIZE %d", FD_SETSIZE); + + FD_ZERO(&proto); + FD_ZERO(&check); + + switch (arc4random_uniform(3)) { + case 0: + sread = ✓ + break; + case 1: + swrite = ✓ + break; + case 2: + serr = ✓ + break; + } + + closefrom(3); + + if ((null = open("/dev/null", O_RDONLY)) == -1) + err(1, "couldn't open /dev/null"); + read(null, &buf, 1); + read(null, &buf, 1); + + if ((zero = open("/dev/zero", O_RDWR)) == -1) + err(1, "couldn't open /dev/zero"); + + for (int i = zero; i < (zero + nfds); i++) { + int fd = (serr != NULL) ? null : zero; + if (arc4random_uniform(100) > 90) { + FD_SET(i, &proto); + } + + if (dup2(fd, i) == -1) + err(1, "couldn't dup fd to fd %d", i); + maxfd = i; + } + + if (swrite != NULL) + puts("write"); + else if (sread != NULL) + puts("read"); + else if (serr != NULL) + puts("err"); + + print_set(&proto, 80); + + memcpy(&check, &proto, sizeof (check)); + + if (select(maxfd + 1, sread, swrite, serr, &tv) == -1) + err(1, "select failed"); + + if (memcmp(&check, &proto, sizeof (check)) != 0) { + diff_sets(&check, &proto, sizeof (check)); + warnx("fd set mismatch: check: %p proto: %p", &check, &proto); + abort(); + } + + return (0); +} |
