1 /* Test for timerfd related functions
2 Copyright (C) 2021-2022 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/>. */
22 #include <support/check.h>
23 #include <support/support.h>
24 #include <support/xunistd.h>
25 #include <support/timespec.h>
27 #include <sys/timerfd.h>
32 struct itimerspec settings
= { { 0, 0 }, { 2, 0 } };
33 struct itimerspec val
;
36 fd
= timerfd_create (CLOCK_REALTIME
, 0);
38 FAIL_EXIT1 ("*** timerfd_create failed: %m");
41 ret
= timerfd_settime (fd
, 0, &settings
, NULL
);
43 FAIL_EXIT1 ("*** timerfd_settime failed: %m\n");
45 /* Sleep for 1 second. */
46 ret
= usleep (1000000);
48 FAIL_EXIT1 ("*** usleep failed: %m\n");
50 /* Read the timer just after sleep. */
51 ret
= timerfd_gettime (fd
, &val
);
53 FAIL_EXIT1 ("*** timerfd_gettime failed: %m\n");
55 /* Check difference between timerfd_gettime calls. */
56 TEST_COMPARE (support_timespec_check_in_range
57 ((struct timespec
) { 1, 0 }, val
.it_value
, 0.9, 1.0), 1);
63 timerfd_large_timeout (void)
65 int fd
= timerfd_create (CLOCK_REALTIME
, 0);
66 TEST_VERIFY (fd
!= -1);
67 support_create_timer (0, 100000000, false, NULL
);
68 struct itimerspec it
= { { 0, 0 }, { TYPE_MAXIMUM (time_t), 0 } };
69 int r
= timerfd_settime (fd
, 0, &it
, NULL
);
73 TEST_COMPARE (read (fd
, &buf
, sizeof (buf
)), -1);
74 TEST_VERIFY (errno
== EINTR
);
77 TEST_COMPARE (errno
, EOVERFLOW
);
84 timerfd_large_timeout ();
88 #include <support/test-driver.c>