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