1 /* Test for ppoll timeout
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
23 #include <support/check.h>
24 #include <support/xtime.h>
25 #include <support/timespec.h>
26 #include <support/support.h>
29 static int test_ppoll_timeout (bool zero_tmo
)
31 /* We wait for half a second. */
33 xclock_gettime (CLOCK_REALTIME
, &ts
);
34 struct timespec timeout
= make_timespec (0, zero_tmo
? 0 : TIMESPEC_HZ
/2);
35 ts
= timespec_add (ts
, timeout
);
37 /* Ignore fds - just wait for timeout. */
38 struct pollfd fds
= { -1, 0, 0 };
39 TEST_COMPARE (ppoll (&fds
, 1, &timeout
, 0), 0);
41 TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME
, ts
);
47 test_ppoll_large_timeout (void)
49 support_create_timer (0, 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
);
59 /* Check if ppoll exits immediately. */
60 test_ppoll_timeout (true);
62 /* Check if ppoll exits after specified timeout. */
63 test_ppoll_timeout (false);
65 /* Check if ppoll with large timeout. */
66 test_ppoll_large_timeout ();
71 #include <support/test-driver.c>