localedata: dz_BT, bo_CN: convert to UTF-8
[glibc.git] / sysdeps / unix / sysv / linux / tst-sigtimedwait.c
blobc2cb795fabd212da07b1d4613bb1e507f15dc7bb
1 /* Test for sigtimedwait 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/>. */
19 #include <time.h>
20 #include <intprops.h>
21 #include <errno.h>
22 #include <signal.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>
29 static int
30 test_sigtimedwait_timeout (bool zero_tmo)
32 /* We wait for half a second. */
33 struct timespec ts;
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. */
39 sigset_t ss_usr1;
40 sigemptyset (&ss_usr1);
41 sigaddset (&ss_usr1, SIGUSR1);
43 int ret = sigtimedwait (&ss_usr1, NULL, &timeout);
44 if (ret != -1)
45 FAIL_EXIT1 ("sigtimedwait failed: %m\n");
47 TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts);
49 return 0;
52 static void
53 test_sigtimedwait_large_timeout (void)
55 support_create_timer (0, 100000000, false, NULL);
56 struct timespec ts = { TYPE_MAXIMUM (time_t), 0 };
58 sigset_t ss_usr1;
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);
66 static int
67 do_test (void)
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 ();
77 return 0;
80 #include <support/test-driver.c>