1 | /* Test for ppoll timeout |
2 | Copyright (C) 2021-2024 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <time.h> |
20 | #include <poll.h> |
21 | #include <errno.h> |
22 | #include <intprops.h> |
23 | #include <support/check.h> |
24 | #include <support/xtime.h> |
25 | #include <support/timespec.h> |
26 | #include <support/support.h> |
27 | #include <stdbool.h> |
28 | |
29 | static int test_ppoll_timeout (bool zero_tmo) |
30 | { |
31 | /* We wait for half a second. */ |
32 | struct timespec ts; |
33 | xclock_gettime (CLOCK_REALTIME, ts: &ts); |
34 | struct timespec timeout = make_timespec (s: 0, ns: zero_tmo ? 0 : TIMESPEC_HZ/2); |
35 | ts = timespec_add (ts, timeout); |
36 | |
37 | /* Ignore fds - just wait for timeout. */ |
38 | struct pollfd fds = { -1, 0, 0 }; |
39 | TEST_COMPARE (ppoll (&fds, 1, &timeout, 0), 0); |
40 | |
41 | TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); |
42 | |
43 | return 0; |
44 | } |
45 | |
46 | static void |
47 | test_ppoll_large_timeout (void) |
48 | { |
49 | support_create_timer (sec: 0, nsec: 100000000, false, NULL); |
50 | struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; |
51 | struct pollfd fds = { -1, 0, 0 }; |
52 | TEST_COMPARE (ppoll (&fds, 1, &ts, 0), -1); |
53 | TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); |
54 | } |
55 | |
56 | static int |
57 | do_test (void) |
58 | { |
59 | /* Check if ppoll exits immediately. */ |
60 | test_ppoll_timeout (true); |
61 | |
62 | /* Check if ppoll exits after specified timeout. */ |
63 | test_ppoll_timeout (false); |
64 | |
65 | /* Check if ppoll with large timeout. */ |
66 | test_ppoll_large_timeout (); |
67 | |
68 | return 0; |
69 | } |
70 | |
71 | #include <support/test-driver.c> |
72 | |