usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-boot-time.c
blob1021844bc13ab85d90cf7609f9d059cbbb72a92f
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. */
19 #include <config.h>
21 #include "boot-time.h"
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <time.h>
27 #include "macros.h"
29 int
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);
37 ASSERT (gmt != NULL);
38 char timbuf[100];
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;