1 /* Test of getting the boot time.
2 Copyright (C) 2023-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 <bruno@clisp.org>, 2023. */
21 #include "boot-time.h"
30 main (int argc
, char *argv
[])
32 struct timespec boot_time
;
33 ASSERT (get_boot_time (&boot_time
) == 0);
35 time_t tim
= boot_time
.tv_sec
;
36 struct tm
*gmt
= gmtime (&tim
);
39 ASSERT (strftime (timbuf
, sizeof (timbuf
), "%Y-%m-%d %H:%M:%S", gmt
) > 0);
41 printf ("Boot time (UTC): %s.%09ld\n", timbuf
, (long) boot_time
.tv_nsec
);
43 /* If the boot time is more than 5 years in the past or more than a week
44 in the future, the value must be wrong. */
45 time_t now
= time (NULL
);
46 ASSERT (tim
>= now
- 157680000);
47 ASSERT (tim
<= now
+ 604800);
49 return test_exit_status
;