The CI reports test failures of the readutmp and boot-time tests on
CentOS 7:
FAIL: test-boot-time
====================
../../gltests/test-boot-time.c:46: assertion 'tim >= now - 157680000' failed
Boot time (UTC): 2020-11-13 01:54:24.000000000
FAIL test-boot-time (exit status: 1)
FAIL: test-readutmp
===================
Here are the read_utmp results.
Flags: B = Boot, U = User Process
Termiā Flags
Time (GMT) User Device PID nation Exit B U
Host
------------------- ------------------ ----------- ---------- ------ ---- - -
----
2020-11-13 01:54:24 reboot ~ 0 0 0 X
../../gltests/test-readutmp.c:145: assertion 'first >= now - 157680000' failed
FAIL test-readutmp (exit status: 1)
It's apparently due to the way the Docker container for CentOS 7 is built.
This patch avoids the failures.
2025-11-17 Bruno Haible <[email protected]>
readutmp, boot-time tests: Fix test failure in CentOS 7 CI environments.
* tests/test-boot-time.c: Include <stdlib.h>.
(main): Skip the 5-years test in environments where $USER is not set.
* tests/test-readutmp.c (main): Likewise.
diff --git a/tests/test-boot-time.c b/tests/test-boot-time.c
index d9777de3e8..d217f96bb1 100644
--- a/tests/test-boot-time.c
+++ b/tests/test-boot-time.c
@@ -22,6 +22,7 @@
#include <stddef.h>
#include <stdio.h>
+#include <stdlib.h>
#include <time.h>
#include "macros.h"
@@ -41,9 +42,13 @@ main (int argc, char *argv[])
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. */
+ 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);
- ASSERT (tim >= now - 157680000);
+ if (getenv ("USER") != NULL)
+ ASSERT (tim >= now - 157680000);
ASSERT (tim <= now + 604800);
return test_exit_status;
diff --git a/tests/test-readutmp.c b/tests/test-readutmp.c
index a691ad4ab0..5c0807c625 100644
--- a/tests/test-readutmp.c
+++ b/tests/test-readutmp.c
@@ -138,11 +138,15 @@ main (int argc, char *argv[])
fflush (stdout);
/* If the first time is more than 5 years in the past or the last time
- is more than a week in the future, the time_t members are wrong. */
+ is more than a week in the future, the time_t members are 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 first = UT_TIME_MEMBER (&entries[0]);
time_t last = UT_TIME_MEMBER (&entries[num_entries - 1]);
time_t now = time (NULL);
- ASSERT (first >= now - 157680000);
+ if (getenv ("USER") != NULL)
+ ASSERT (first >= now - 157680000);
ASSERT (last <= now + 604800);
/* read_utmp should not produce multiple BOOT_TIME entries. */