1 /* Test of timespec_get() function.
2 Copyright (C) 2021-2025 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. */
23 #include "signature.h"
24 SIGNATURE_CHECK (timespec_get
, int, (struct timespec
*ts
, int base
));
36 ASSERT (timespec_get (&ts1
, TIME_UTC
));
38 ASSERT (timespec_get (&ts3
, TIME_UTC
));
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(). */
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
;