8d419f
From c9fe9526f07ad24d29842fa853ee458b68660896 Mon Sep 17 00:00:00 2001
8d419f
From: Frantisek Sumsal <frantisek@sumsal.cz>
8d419f
Date: Fri, 22 Apr 2022 18:03:14 +0200
8d419f
Subject: [PATCH] test: extend the "hashed" unit names coverage a bit
8d419f
8d419f
Follow-up to #22759.
8d419f
8d419f
(cherry picked from commit 98f8c316389177169c6599e67010ebb1789a6b26)
8d419f
8d419f
Related: #2083493
8d419f
---
8d419f
 test/units/testsuite-64.sh | 19 ++++++++++++++++---
8d419f
 1 file changed, 16 insertions(+), 3 deletions(-)
8d419f
8d419f
diff --git a/test/units/testsuite-64.sh b/test/units/testsuite-64.sh
8d419f
index 218b2ee8d1..5f9aeee261 100755
8d419f
--- a/test/units/testsuite-64.sh
8d419f
+++ b/test/units/testsuite-64.sh
8d419f
@@ -646,7 +646,7 @@ testcase_iscsi_lvm() {
8d419f
 }
8d419f
 
8d419f
 testcase_long_sysfs_path() {
8d419f
-    local link logfile mpoint
8d419f
+    local cursor link logfile mpoint
8d419f
     local expected_symlinks=(
8d419f
         "/dev/disk/by-label/data_vol"
8d419f
         "/dev/disk/by-label/swap_vol"
8d419f
@@ -657,6 +657,12 @@ testcase_long_sysfs_path() {
8d419f
         "/dev/disk/by-uuid/deadbeef-dead-dead-beef-222222222222"
8d419f
     )
8d419f
 
8d419f
+    # Create a cursor file to skip messages generated by udevd in initrd, as it
8d419f
+    # might not be the same up-to-date version as we currently run (hence generating
8d419f
+    # messages we check for later and making the test fail)
8d419f
+    cursor="$(mktemp)"
8d419f
+    journalctl --cursor-file="${cursor:?}" -n0 -q
8d419f
+
8d419f
     # Make sure the test device is connected and show its "wonderful" path
8d419f
     stat /sys/block/vda
8d419f
     readlink -f /sys/block/vda/dev
8d419f
@@ -685,13 +691,20 @@ testcase_long_sysfs_path() {
8d419f
     udevadm settle
8d419f
 
8d419f
     logfile="$(mktemp)"
8d419f
-    [[ "$(journalctl -b -q --no-pager -o short-monotonic -p info --grep "Device path.*vda.?' too long to fit into unit name" | wc -l)" -eq 0 ]]
8d419f
+    # Check state of affairs after https://github.com/systemd/systemd/pull/22759
8d419f
+    # Note: can't use `--cursor-file` here, since we don't want to update the cursor
8d419f
+    #       after using it
8d419f
+    [[ "$(journalctl --after-cursor="$(<"$cursor")" -q --no-pager -o short-monotonic -p info --grep "Device path.*vda.?' too long to fit into unit name" | wc -l)" -eq 0 ]]
8d419f
+    [[ "$(journalctl --after-cursor="$(<"$cursor")" -q --no-pager -o short-monotonic --grep "Unit name .*vda.?\.device\" too long, falling back to hashed unit name" | wc -l)" -gt 0 ]]
8d419f
+    # Check if the respective "hashed" units exist and are active (plugged)
8d419f
+    systemctl status --no-pager "$(readlink -f /sys/block/vda/vda1)"
8d419f
+    systemctl status --no-pager "$(readlink -f /sys/block/vda/vda2)"
8d419f
     # Make sure we don't unnecessarily spam the log
8d419f
     { journalctl -b -q --no-pager -o short-monotonic -p info --grep "/sys/devices/.+/vda[0-9]?" _PID=1 + UNIT=systemd-udevd.service || :;} | tee "$logfile"
8d419f
     [[ "$(wc -l <"$logfile")" -lt 10 ]]
8d419f
 
8d419f
     : >/etc/fstab
8d419f
-    rm -fr "${logfile:?}" "${mpoint:?}"
8d419f
+    rm -fr "${cursor:?}" "${logfile:?}" "${mpoint:?}"
8d419f
 }
8d419f
 
8d419f
 : >/failed