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 static int fds[2];
31
sample_fn(int clk_id,long long usec)32 static int sample_fn(int clk_id, long long usec)
33 {
34 struct timeval timeout = tst_us_to_timeval(usec);
35 fd_set sfds;
36
37 FD_ZERO(&sfds);
38
39 FD_SET(fds[0], &sfds);
40
41 tst_timer_start(clk_id);
42 TEST(select(1, &sfds, NULL, NULL, &timeout));
43 tst_timer_stop();
44 tst_timer_sample();
45
46 if (TEST_RETURN != 0) {
47 tst_res(TFAIL | TTERRNO, "select() returned %li", TEST_RETURN);
48 return 1;
49 }
50
51 return 0;
52 }
53
setup(void)54 static void setup(void)
55 {
56 SAFE_PIPE(fds);
57 }
58
cleanup(void)59 static void cleanup(void)
60 {
61 if (fds[0] > 0)
62 SAFE_CLOSE(fds[0]);
63
64 if (fds[1] > 0)
65 SAFE_CLOSE(fds[1]);
66 }
67
68 static struct tst_test test = {
69 .scall = "select()",
70 .sample = sample_fn,
71 .setup = setup,
72 .cleanup = cleanup,
73 };
74