2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Based on test by Dr. David Alan Gilbert <dave@treblig.org>
35 #include <sys/select.h>
37 static fd_set set[0x1000000 / sizeof(fd_set)];
46 .tv = { .tv_sec = 0xc0de1, .tv_usec = 0xc0de2 },
47 .pad = { 0xdeadbeef, 0xbadc0ded }
51 perror_msg_and_fail("pipe");
54 * Start with a nice simple select.
59 int rc = syscall(TEST_SYSCALL_NR, fds[1] + 1, set, set, set, NULL);
61 perror_msg_and_skip(TEST_SYSCALL_STR);
63 printf("%s(%d, [%d %d], [%d %d], [%d %d], NULL) = 1 ()\n",
64 TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
65 fds[0], fds[1], fds[0], fds[1]);
68 * Another simple one, with a timeout.
74 assert(syscall(TEST_SYSCALL_NR, fds[1] + 1, NULL, set, NULL, &tm.tv) == 3);
75 printf("%s(%d, NULL, [1 2 %d %d], NULL, {tv_sec=%lld, tv_usec=%lld})"
76 " = 3 (out [1 2 %d], left {tv_sec=%lld, tv_usec=%lld})\n",
77 TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
78 (long long) tm_in.tv.tv_sec, (long long) tm_in.tv.tv_usec,
80 (long long) tm.tv.tv_sec, (long long) tm.tv.tv_usec);
83 * Now the crash case that trinity found, negative nfds
84 * but with a pointer to a large chunk of valid memory.
88 assert(syscall(TEST_SYSCALL_NR, -1, NULL, set, NULL, NULL) == -1);
89 printf("%s(-1, NULL, %p, NULL, NULL) = -1 EINVAL (%m)\n",
90 TEST_SYSCALL_STR, set);
93 * Another variant, with nfds exceeding FD_SETSIZE limit.
99 assert(syscall(TEST_SYSCALL_NR, FD_SETSIZE + 1, set, set + 1, NULL, &tm.tv) == 0);
100 printf("%s(%d, [%d], [], NULL, {tv_sec=0, tv_usec=123}) = 0 (Timeout)\n",
101 TEST_SYSCALL_STR, FD_SETSIZE + 1, fds[0]);
103 puts("+++ exited with 0 +++");