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