]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: rework dmsetup test to wait for device to disappear
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 4 Nov 2025 16:54:11 +0000 (16:54 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 4 Nov 2025 19:08:44 +0000 (04:08 +0900)
There might be a delay between an umount and a refcounted device
to disappear, so the test can be flaky:

[   36.107128] TEST-50-DISSECT.sh[1662]: ++ dmsetup ls
[   36.108314] TEST-50-DISSECT.sh[1663]: ++ grep loop
[   36.109283] TEST-50-DISSECT.sh[1664]: ++ grep -c verity
[   36.110284] TEST-50-DISSECT.sh[1360]: + test 1 -eq 1
[   36.111555] TEST-50-DISSECT.sh[1360]: + umount -R /tmp/TEST-50-IMAGES.hxm/mount
[   36.112237] TEST-50-DISSECT.sh[1668]: ++ dmsetup ls
[   36.113039] TEST-50-DISSECT.sh[1669]: ++ grep loop
[   36.113833] TEST-50-DISSECT.sh[1670]: ++ grep -c verity
[   36.114517] TEST-50-DISSECT.sh[1360]: + test 0 -eq 1
[   36.116734] TEST-50-DISSECT.sh[1000]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/TEST-50-DISSECT.dissect.sh failed'

https://github.com/systemd/systemd/actions/runs/19062162467/job/54444112653?pr=39540#logs

Switch to searching for the dm entry and check for it specifically,
and wait for it to disappear before checking that it is no longer
in the dm table.

Follow-up for 10fc43e504da5962fa5f04341ae8ba92a9981be9

test/units/TEST-50-DISSECT.dissect.sh

index 6eac920c8d774613e42618d2efb32dbd83db63de..922dca0cf820bb9209cfddfb03d2c94e56aeb9f8 100755 (executable)
@@ -80,14 +80,20 @@ systemd-dissect --umount "$IMAGE_DIR/mount2"
 
 # Ensure the deferred close flag is set up correctly and we don't leak verity devices
 # when sharing is disabled
-set +o pipefail
 # The devices are named 'loopXYZ-verity' when sharing is disabled
-n_before=$(dmsetup ls | grep loop | grep -c verity || true)
 SYSTEMD_VERITY_SHARING=0 systemd-dissect --mount "$MINIMAL_IMAGE.raw" "$IMAGE_DIR/mount"
-test $((n_before + 1)) -eq "$(dmsetup ls | grep loop | grep -c verity || true)"
+d=""
+for f in /dev/mapper/*; do
+    if [[ "$(basename "$f")" =~ ^loop.*-verity ]] && veritysetup status "$(basename "$f")" | grep -q "$MINIMAL_IMAGE.raw"; then
+        d="$f"
+        break
+    fi
+done
+test -n "$d"
+dmsetup ls | grep -q "$(basename "$d")"
 umount -R "$IMAGE_DIR/mount"
-test "$n_before" -eq "$(dmsetup ls | grep loop | grep -c verity || true)"
-set -o pipefail
+timeout 60 bash -c "while test -e $d; do sleep 0.1; done"
+( ! dmsetup ls | grep -q "$(basename "$d")")
 
 # Test BindLogSockets=
 systemd-run --wait -p RootImage="$MINIMAL_IMAGE.raw" mountpoint /run/systemd/journal/socket