• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015-2017 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
12  * the 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, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * Check that select() timeouts correctly.
21  */
22 #include <unistd.h>
23 #include <errno.h>
24 #include <sys/time.h>
25 #include <sys/types.h>
26 #include <fcntl.h>
27 
28 #include "tst_timer_test.h"
29 
30 #include "select_var.h"
31 
32 static int fds[2];
33 
sample_fn(int clk_id,long long usec)34 static int sample_fn(int clk_id, long long usec)
35 {
36 	struct timeval timeout = tst_us_to_timeval(usec);
37 	fd_set sfds;
38 
39 	FD_ZERO(&sfds);
40 
41 	FD_SET(fds[0], &sfds);
42 
43 	tst_timer_start(clk_id);
44 	TEST(do_select(1, &sfds, NULL, NULL, &timeout));
45 	tst_timer_stop();
46 	tst_timer_sample();
47 
48 	if (TST_RET != 0) {
49 		tst_res(TFAIL | TTERRNO, "select() returned %li", TST_RET);
50 		return 1;
51 	}
52 
53 	return 0;
54 }
55 
setup(void)56 static void setup(void)
57 {
58 	select_info();
59 
60 	SAFE_PIPE(fds);
61 }
62 
cleanup(void)63 static void cleanup(void)
64 {
65 	if (fds[0] > 0)
66 		SAFE_CLOSE(fds[0]);
67 
68 	if (fds[1] > 0)
69 		SAFE_CLOSE(fds[1]);
70 }
71 
72 static struct tst_test test = {
73 	.scall = "select()",
74 	.sample = sample_fn,
75 	.setup = setup,
76 	.test_variants = TEST_VARIANTS,
77 	.cleanup = cleanup,
78 };
79