]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp tests: Add test against today's bug.
authorBruno Haible <bruno@clisp.org>
Tue, 15 Aug 2023 21:32:27 +0000 (23:32 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 15 Aug 2023 21:32:27 +0000 (23:32 +0200)
* tests/test-readutmp.c (main): Verify that there is exactly one
BOOT_TIME entry.

ChangeLog
tests/test-readutmp.c

index f71a982cd245dc859915bc418541ef7924200e79..fc8269e23db20650fcbb193fdbbcebf73d362817 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-08-15  Bruno Haible  <bruno@clisp.org>
 
+       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.
index a11e247bf507d07961c11ffb9909a8fea7516511..6b2e579c3f102b44c6c846857ebd9cb5be540322 100644 (file)
@@ -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);