1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2014 Fujitsu Ltd.
4*49cdfc7eSAndroid Build Coastguard Worker * Author: Zeng Linggang <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * Verify that pselect() fails with:
11*49cdfc7eSAndroid Build Coastguard Worker *
12*49cdfc7eSAndroid Build Coastguard Worker * - EBADF if a file descriptor that was already closed
13*49cdfc7eSAndroid Build Coastguard Worker * - EINVAL if nfds was negative
14*49cdfc7eSAndroid Build Coastguard Worker * - EINVAL if the value contained within timeout was invalid
15*49cdfc7eSAndroid Build Coastguard Worker */
16*49cdfc7eSAndroid Build Coastguard Worker
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker static fd_set read_fds;
20*49cdfc7eSAndroid Build Coastguard Worker static struct timespec time_buf;
21*49cdfc7eSAndroid Build Coastguard Worker
22*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
23*49cdfc7eSAndroid Build Coastguard Worker int nfds;
24*49cdfc7eSAndroid Build Coastguard Worker fd_set *readfds;
25*49cdfc7eSAndroid Build Coastguard Worker struct timespec *timeout;
26*49cdfc7eSAndroid Build Coastguard Worker int exp_errno;
27*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
28*49cdfc7eSAndroid Build Coastguard Worker {128, &read_fds, NULL, EBADF},
29*49cdfc7eSAndroid Build Coastguard Worker {-1, NULL, NULL, EINVAL},
30*49cdfc7eSAndroid Build Coastguard Worker {128, NULL, &time_buf, EINVAL},
31*49cdfc7eSAndroid Build Coastguard Worker };
32*49cdfc7eSAndroid Build Coastguard Worker
setup(void)33*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
34*49cdfc7eSAndroid Build Coastguard Worker {
35*49cdfc7eSAndroid Build Coastguard Worker int fd;
36*49cdfc7eSAndroid Build Coastguard Worker
37*49cdfc7eSAndroid Build Coastguard Worker fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0777);
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker FD_ZERO(&read_fds);
40*49cdfc7eSAndroid Build Coastguard Worker FD_SET(fd, &read_fds);
41*49cdfc7eSAndroid Build Coastguard Worker
42*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(fd);
43*49cdfc7eSAndroid Build Coastguard Worker
44*49cdfc7eSAndroid Build Coastguard Worker time_buf.tv_sec = -1;
45*49cdfc7eSAndroid Build Coastguard Worker time_buf.tv_nsec = 0;
46*49cdfc7eSAndroid Build Coastguard Worker }
47*49cdfc7eSAndroid Build Coastguard Worker
pselect_verify(unsigned int i)48*49cdfc7eSAndroid Build Coastguard Worker static void pselect_verify(unsigned int i)
49*49cdfc7eSAndroid Build Coastguard Worker {
50*49cdfc7eSAndroid Build Coastguard Worker struct tcase *tc = &tcases[i];
51*49cdfc7eSAndroid Build Coastguard Worker
52*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_FAIL(pselect(tc->nfds, tc->readfds, NULL, NULL, tc->timeout, NULL),
53*49cdfc7eSAndroid Build Coastguard Worker tc->exp_errno, "pselect(%i, %p, %p)",
54*49cdfc7eSAndroid Build Coastguard Worker tc->nfds, tc->readfds, tc->timeout);
55*49cdfc7eSAndroid Build Coastguard Worker }
56*49cdfc7eSAndroid Build Coastguard Worker
57*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
58*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(tcases),
59*49cdfc7eSAndroid Build Coastguard Worker .test = pselect_verify,
60*49cdfc7eSAndroid Build Coastguard Worker .setup = setup,
61*49cdfc7eSAndroid Build Coastguard Worker .needs_tmpdir = 1,
62*49cdfc7eSAndroid Build Coastguard Worker };
63