usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-timespec_get.c
blob22b624a3ef01c0d3d769fb780b69425b07007fe6
1 /* Test of timespec_get() function.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible. */
19 #include <config.h>
21 #include <time.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (timespec_get, int, (struct timespec *ts, int base));
26 #include "macros.h"
28 int
29 main (void)
31 struct timespec ts1;
32 time_t tt2;
33 struct timespec ts3;
34 time_t tt4;
36 ASSERT (timespec_get (&ts1, TIME_UTC));
37 tt2 = time (NULL);
38 ASSERT (timespec_get (&ts3, TIME_UTC));
39 tt4 = time (NULL);
41 /* Verify monotonicity of timespec_get(). */
42 ASSERT (ts1.tv_sec < ts3.tv_sec
43 || (ts1.tv_sec == ts3.tv_sec && ts1.tv_nsec <= ts3.tv_nsec));
45 /* Verify monotonicity of time(). */
46 ASSERT (tt2 <= tt4);
48 /* Verify that the tv_sec field of the result is the same as time(NULL). */
49 /* Note: It's here that the dependency to the 'time' module is needed.
50 Without it, this assertion would sometimes fail on glibc systems, see
51 https://sourceware.org/bugzilla/show_bug.cgi?id=30200 */
52 ASSERT (ts1.tv_sec <= tt2);
53 ASSERT (tt2 <= ts3.tv_sec);
54 ASSERT (ts3.tv_sec <= tt4);
56 return test_exit_status;