• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17  /*
18   * This is basic test for pselect() returning without error.
19   */
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <sys/select.h>
23 #include <sys/time.h>
24 #include <sys/types.h>
25 #include <time.h>
26 #include <unistd.h>
27 #include <errno.h>
28 
29 #include "tst_test.h"
30 
31 static int fd;
32 
verify_pselect(void)33 static void verify_pselect(void)
34 {
35 	fd_set readfds;
36 	struct timespec tv = {0};
37 
38 	FD_ZERO(&readfds);
39 	FD_SET(fd, &readfds);
40 
41 	TEST(pselect(fd, &readfds, 0, 0, &tv, NULL));
42 	if (TST_RET >= 0)
43 		tst_res(TPASS, "pselect() succeeded retval=%li", TST_RET);
44 	else
45 		tst_res(TFAIL | TTERRNO, "pselect() failed unexpectedly");
46 }
47 
setup(void)48 static void setup(void)
49 {
50 	fd = SAFE_OPEN("pselect03_file", O_CREAT | O_RDWR, 0777);
51 }
52 
cleanup(void)53 static void cleanup(void)
54 {
55 	if (fd > 0)
56 		SAFE_CLOSE(fd);
57 }
58 
59 static struct tst_test test = {
60 	.needs_tmpdir = 1,
61 	.setup = setup,
62 	.cleanup = cleanup,
63 	.test_all = verify_pselect,
64 };
65