• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2015-2017 Cyril Hrubis <chrubis@suse.cz>
4  */
5 
6 /*
7  * Check that poll() timeouts correctly.
8  */
9 #include <errno.h>
10 #include <fcntl.h>
11 #include <sys/wait.h>
12 #include <sys/poll.h>
13 
14 #include "tst_timer_test.h"
15 
16 static int fds[2];
17 
sample_fn(int clk_id,long long usec)18 int sample_fn(int clk_id, long long usec)
19 {
20 	unsigned int sleep_ms = usec / 1000;
21 
22 	struct pollfd pfds[] = {
23 		{.fd = fds[0], .events = POLLIN}
24 	};
25 
26 	tst_timer_start(clk_id);
27 	TEST(poll(pfds, 1, sleep_ms));
28 	tst_timer_stop();
29 	tst_timer_sample();
30 
31 	if (TST_RET != 0) {
32 		tst_res(TFAIL | TTERRNO, "poll() returned %li", TST_RET);
33 		return 1;
34 	}
35 
36 	return 0;
37 }
38 
setup(void)39 static void setup(void)
40 {
41 	SAFE_PIPE(fds);
42 }
43 
cleanup(void)44 static void cleanup(void)
45 {
46 	if (fds[0] > 0)
47 		SAFE_CLOSE(fds[0]);
48 
49 	if (fds[1] > 0)
50 		SAFE_CLOSE(fds[1]);
51 }
52 
53 static struct tst_test test = {
54 	.scall = "poll()",
55 	.sample = sample_fn,
56 	.setup = setup,
57 	.cleanup = cleanup,
58 };
59