1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
4  */
5  /*
6   * This is basic test for pselect() returning without error.
7   */
8 #include <stdio.h>
9 #include <fcntl.h>
10 #include <sys/select.h>
11 #include <sys/time.h>
12 #include <sys/types.h>
13 #include <time.h>
14 #include <unistd.h>
15 #include <errno.h>
16 
17 #include "tst_test.h"
18 
19 static int fd;
20 
verify_pselect(void)21 static void verify_pselect(void)
22 {
23 	fd_set readfds;
24 	struct timespec tv = {0};
25 
26 	FD_ZERO(&readfds);
27 	FD_SET(fd, &readfds);
28 
29 	TEST(pselect(fd, &readfds, 0, 0, &tv, NULL));
30 	if (TST_RET >= 0)
31 		tst_res(TPASS, "pselect() succeeded retval=%li", TST_RET);
32 	else
33 		tst_res(TFAIL | TTERRNO, "pselect() failed unexpectedly");
34 }
35 
setup(void)36 static void setup(void)
37 {
38 	fd = SAFE_OPEN("pselect03_file", O_CREAT | O_RDWR, 0777);
39 }
40 
cleanup(void)41 static void cleanup(void)
42 {
43 	if (fd > 0)
44 		SAFE_CLOSE(fd);
45 }
46 
47 static struct tst_test test = {
48 	.needs_tmpdir = 1,
49 	.setup = setup,
50 	.cleanup = cleanup,
51 	.test_all = verify_pselect,
52 };
53