2 * Copyright 2022-2024 Free Software Foundation, Inc.
3 * Written by Paul Eggert.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
27 long int res
= gettime_res ();
28 printf ("gettime_res returned %ld ns\n", res
);
32 fprintf (stderr
, "gettime_res value %ld not positive\n", res
);
36 if (res
< TIMESPEC_HZ
)
38 if (TIMESPEC_HZ
% res
!= 0)
41 ("gettime_res value %ld ns is smaller than %d"
42 " but does not divide it\n"),
49 if (res
% TIMESPEC_HZ
!= 0)
52 ("gettime_res value %ld ns is larger than %d"
53 " but is not a multiple of it\n"),
61 for (int i
= 0; i
< 100000; i
++)
63 struct timespec t
= current_timespec ();
65 ? t
.tv_nsec
% res
!= 0
66 : t
.tv_nsec
!= 0 || t
.tv_sec
% (res
/ TIMESPEC_HZ
) != 0)
69 ("current_timespec returned %lld.%09ld which is not"
70 " a multiple of the resolution, %ld ns\n"),
71 (long long) t
.tv_sec
, t
.tv_nsec
, res
);
75 ? (t
.tv_nsec
/ res
% 2 != 0
76 || t
.tv_nsec
/ res
% 5 != 0)
77 : (t
.tv_sec
/ (res
/ TIMESPEC_HZ
) % 2 != 0
78 || t
.tv_sec
/ (res
/ TIMESPEC_HZ
) % 5 != 0))
84 ("warning: all timestamps had coarser"
85 " resolution than %ld ns\n"),