mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
* tests/from-glibc/tst-stdbit.h (TEST_STDBIT_T): * tests/jit/test-cache.c, tests/test-boot-time.c: * tests/test-ceilf2.c, tests/test-fflush.c, tests/test-floorf2.c: * tests/test-mbrtoc32-regular.c, tests/test-mbrtoc32.c: * tests/test-mbrtowc-w32utf8.c, tests/test-mbrtowc.c: * tests/test-mbsnrtoc32s.c, tests/test-mbsnrtowcs.c: * tests/test-mbsrtoc32s.c, tests/test-mbsrtowcs.c: * tests/test-mbstoc32s.c, tests/test-mbstowcs.c: * tests/test-sameacls.c, tests/test-towctrans.c: * tests/test-truncf2.c, tests/test-wcscmp.c, tests/test-wcsncmp.c: * tests/test-wmemcmp.c: (main) * tests/test-c32isalnum.c, tests/test-c32isalpha.c: * tests/test-c32isblank.c, tests/test-c32iscntrl.c: * tests/test-c32isdigit.c, tests/test-c32isgraph.c: * tests/test-c32islower.c, tests/test-c32isprint.c: * tests/test-c32ispunct.c, tests/test-c32isspace.c: * tests/test-c32isupper.c, tests/test-c32isxdigit.c: * tests/test-c32tolower.c, tests/test-c32toupper.c: * tests/test-iswdigit.c, tests/test-iswpunct.c, tests/test-iswxdigit.c: (for_character): * tests/test-c32rtomb.c, tests/test-wcrtomb.c: (check_character): * tests/test-mbrtoc32-w32.c, tests/test-mbrtowc-w32.c: (test_one_locale): * tests/test-snprintf-posix.h, tests/test-sprintf-posix.h: * tests/test-vasnprintf-posix.c, tests/test-vasnwprintf-posix.c: * tests/test-vasprintf-posix.c: (test_function): * tests/test-stat-time.c (initialize_filenames): * tests/uniwidth/test-uc_width2.c (finish_interval): Use compound literal when it is safer than a cast and it pacifies -Wuseless-cast. Also, omit unnecessary casts to a type when the context is already that type and omitting pacifies -Wuseless-cast.
56 lines
1.8 KiB
C
56 lines
1.8 KiB
C
/* Test of getting the boot time.
|
|
Copyright (C) 2023-2026 Free Software Foundation, Inc.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
|
|
/* Written by Bruno Haible <bruno@clisp.org>, 2023. */
|
|
|
|
#include <config.h>
|
|
|
|
#include "boot-time.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
#include "macros.h"
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
struct timespec boot_time;
|
|
ASSERT (get_boot_time (&boot_time) == 0);
|
|
|
|
time_t tim = boot_time.tv_sec;
|
|
struct tm *gmt = gmtime (&tim);
|
|
ASSERT (gmt != NULL);
|
|
char timbuf[100];
|
|
ASSERT (strftime (timbuf, sizeof (timbuf), "%Y-%m-%d %H:%M:%S", gmt) > 0);
|
|
|
|
printf ("Boot time (UTC): %s.%09ld\n", timbuf, (long) {boot_time.tv_nsec});
|
|
|
|
/* If the boot time is more than 5 years in the past or more than a week
|
|
in the future, the value must be wrong.
|
|
Except that CI environments built on Docker sometimes have a boot time
|
|
long ago in the past, such as 2020-11-13 for CentOS 7. Such CI
|
|
environments lack the USER environment variable. */
|
|
time_t now = time (NULL);
|
|
if (getenv ("USER") != NULL)
|
|
ASSERT (tim >= now - 157680000);
|
|
ASSERT (tim <= now + 604800);
|
|
|
|
return test_exit_status;
|
|
}
|