From: Bruno Haible Date: Tue, 15 Aug 2023 21:32:27 +0000 (+0200) Subject: readutmp tests: Add test against today's bug. X-Git-Tag: v1.0~903 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c671d81011e0f448d361007bfaa1899b54819f86;p=gnulib.git readutmp tests: Add test against today's bug. * tests/test-readutmp.c (main): Verify that there is exactly one BOOT_TIME entry. --- diff --git a/ChangeLog b/ChangeLog index f71a982cd2..fc8269e23d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2023-08-15 Bruno Haible + readutmp tests: Add test against today's bug. + * tests/test-readutmp.c (main): Verify that there is exactly one + BOOT_TIME entry. + readutmp: Fix for platforms without ut_type (regression 2023-08-08). * lib/readutmp.h (UT_TYPE_BOOT_TIME, UT_TYPE_USER_PROCESS): Don't use UT_TYPE_EQ macro. diff --git a/tests/test-readutmp.c b/tests/test-readutmp.c index a11e247bf5..6b2e579c3f 100644 --- a/tests/test-readutmp.c +++ b/tests/test-readutmp.c @@ -101,6 +101,7 @@ main (int argc, char *argv[]) merge_sort_inplace (entries, num_entries, XNMALLOC (num_entries, STRUCT_UTMP)); + idx_t boot_time_count = 0; idx_t i; for (i = 0; i < num_entries; i++) { @@ -131,6 +132,9 @@ main (int argc, char *argv[]) UT_TYPE_BOOT_TIME (entry) ? 'X' : ' ', UT_TYPE_USER_PROCESS (entry) ? 'X' : ' ', host); + + if (UT_TYPE_BOOT_TIME (entry)) + boot_time_count++; } fflush (stdout); @@ -141,6 +145,13 @@ main (int argc, char *argv[]) time_t now = time (NULL); ASSERT (first >= now - 157680000); ASSERT (last <= now + 604800); + + /* read_utmp should not produce multiple BOOT_TIME entries. */ + ASSERT (boot_time_count <= 1); + + /* read_utmp should fake a BOOT_TIME entry if needed. + Platform specific hacks go into lib/boot-time-aux.h. */ + ASSERT (boot_time_count >= 1); } free (entries);