1 /* Test for sigtimedwait timeout.
2 Copyright (C) 2021-2023 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>
30 test_sigtimedwait_timeout (bool zero_tmo
)
32 /* We wait for half a second. */
34 xclock_gettime (CLOCK_REALTIME
, &ts
);
35 struct timespec timeout
= make_timespec (0, zero_tmo
? 0 : TIMESPEC_HZ
/2);
36 ts
= timespec_add (ts
, timeout
);
38 /* Set sigset to just wait for timeout. */
40 sigemptyset (&ss_usr1
);
41 sigaddset (&ss_usr1
, SIGUSR1
);
43 int ret
= sigtimedwait (&ss_usr1
, NULL
, &timeout
);
45 FAIL_EXIT1 ("sigtimedwait failed: %m\n");
47 TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME
, ts
);
53 test_sigtimedwait_large_timeout (void)
55 support_create_timer (0, 100000000, false, NULL
);
56 struct timespec ts
= { TYPE_MAXIMUM (time_t), 0 };
59 sigemptyset (&ss_usr1
);
60 sigaddset (&ss_usr1
, SIGUSR1
);
62 TEST_COMPARE (sigtimedwait (&ss_usr1
, NULL
, &ts
), -1);
63 TEST_VERIFY (errno
== EINTR
|| errno
== EOVERFLOW
);
69 /* Check if sigtimedwait exits immediately. */
70 test_sigtimedwait_timeout (true);
72 /* Check if sigtimedwait exits after specified timeout. */
73 test_sigtimedwait_timeout (false);
75 test_sigtimedwait_large_timeout ();
80 #include <support/test-driver.c>