]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use 'until' instead of 'while !'
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 6 Sep 2023 12:51:07 +0000 (14:51 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Sep 2023 18:54:29 +0000 (19:54 +0100)
In general, it's better to avoid a negation. And "!" is special, because it is
used for history expansion, i.e. the same command would behave differently if
pasted on the command line.

Inspired by 4a899c5a239eb50df3f596af4ff145f4a2d33f23.

18 files changed:
.semaphore/semaphore-runner.sh
test/testsuite-23.units/testsuite-23-namespaced.service
test/testsuite-23.units/testsuite-23-non-namespaced.service
test/units/testsuite-03.sh
test/units/testsuite-04.SYSTEMD_JOURNAL_COMPRESS.sh
test/units/testsuite-04.journal-remote.sh
test/units/testsuite-04.journal.sh
test/units/testsuite-07.issue-2467.sh
test/units/testsuite-13.machinectl.sh
test/units/testsuite-13.nss-mymachines.sh
test/units/testsuite-17.02.sh
test/units/testsuite-23.Upholds.sh
test/units/testsuite-35.sh
test/units/testsuite-36.sh
test/units/testsuite-50.sh
test/units/testsuite-60.sh
test/units/testsuite-63.sh
test/units/testsuite-64.sh

index 63c5fdfea768ccef4247589bfcff209840830cd9..13456609ad04370e73ab12e13a14c47a682d2ee3 100755 (executable)
@@ -30,7 +30,7 @@ create_container() {
     sudo lxc-attach -n "$CONTAINER" -- sh -ex <<EOF
 sed 's/^deb/deb-src/' /etc/apt/sources.list >>/etc/apt/sources.list.d/sources.list
 # We might attach the console too soon
-while ! systemctl --quiet --wait is-system-running; do sleep 1; done
+until systemctl --quiet --wait is-system-running; do sleep 1; done
 # Manpages database trigger takes a lot of time and is not useful in a CI
 echo 'man-db man-db/auto-update boolean false' | debconf-set-selections
 # Speed up dpkg, image is thrown away after the test
index 5f30b55e00e4c6fbbd1607ddae7c26cdde019355..5a6f5cd873a0f39649b099245e0cbbcc2c740567 100644 (file)
@@ -10,4 +10,4 @@ PrivateTmp=yes
 BindPaths=/run/testsuite-23-marker-fixed:/tmp/testfile-marker-fixed
 InaccessiblePaths=/run/inaccessible
 ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile-marker-fixed
-ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile-marker-fixed'
+ExecStart=/bin/sh -c 'systemd-notify --ready; until grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile-marker-fixed'
index 058ecb4769597a67225d516a7f3d20d33a386bc2..6f93c3bde57070564f19112ef885219c8291584a 100644 (file)
@@ -3,4 +3,4 @@
 RuntimeMaxSec=5
 Type=notify
 RemainAfterExit=yes
-ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; exit 0'
+ExecStart=/bin/sh -c 'systemd-notify --ready; until grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; exit 0'
index e9ef31d94616bc3b6ebf66dde7dca30340320c16..e3567c2d7c598777542038dc12407ce55c7399d6 100755 (executable)
@@ -16,7 +16,7 @@ systemctl daemon-reexec
 systemctl start --no-block hello-after-sleep.target
 
 systemctl list-jobs >/root/list-jobs.txt
-while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
+until grep 'sleep\.service.*running' /root/list-jobs.txt; do
     systemctl list-jobs >/root/list-jobs.txt
 done
 
index 06c52b284974fc666c094bcd1ccd13692cdc90b3..8fdf1b132e0474f98cb4986468d6b3c8b939d388 100755 (executable)
@@ -19,7 +19,7 @@ EOF
     ID="$(systemd-id128 new)"
     systemd-cat -t "$ID" /bin/bash -c "for ((i=0;i<100;i++)); do echo -n hoge with ${c}; done; echo"
     journalctl --sync
-    timeout 10 bash -c "while ! SYSTEMD_LOG_LEVEL=debug journalctl --verify --quiet --file /var/log/journal/$MACHINE_ID/system.journal 2>&1 | grep -q -F 'compress=${c}'; do sleep .5; done"
+    timeout 10 bash -c "until SYSTEMD_LOG_LEVEL=debug journalctl --verify --quiet --file /var/log/journal/$MACHINE_ID/system.journal 2>&1 | grep -q -F 'compress=${c}'; do sleep .5; done"
 
     # $SYSTEMD_JOURNAL_COMPRESS= also works for journal-remote
     if [[ -x /usr/lib/systemd/systemd-journal-remote ]]; then
index 6bdc3ccdec532a1cbb5917d99d57f10feeda811c..c0b95caec34fb99e5dcc29f82fc9f8dbbf5c7b56 100755 (executable)
@@ -81,11 +81,11 @@ systemd-analyze cat-config systemd/journal-upload.conf
 
 systemctl restart systemd-journal-remote.socket
 systemctl restart systemd-journal-upload
-timeout 15 bash -xec 'while ! systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
+timeout 15 bash -xec 'until systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
 systemctl status systemd-journal-{remote,upload}
 
 # It may take a bit until the whole journal is transferred
-timeout 30 bash -xec "while ! journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
+timeout 30 bash -xec "until journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
 
 systemctl stop systemd-journal-upload
 systemctl stop systemd-journal-remote.{socket,service}
@@ -184,11 +184,11 @@ systemd-analyze cat-config systemd/journal-upload.conf
 
 systemctl restart systemd-journal-remote.socket
 systemctl restart systemd-journal-upload
-timeout 15 bash -xec 'while ! systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
+timeout 15 bash -xec 'until systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
 systemctl status systemd-journal-{remote,upload}
 
 # It may take a bit until the whole journal is transferred
-timeout 30 bash -xec "while ! journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
+timeout 30 bash -xec "until journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
 
 systemctl stop systemd-journal-upload
 systemctl stop systemd-journal-remote.{socket,service}
index c733ff332c2b21ac53d1049418c49374b095346b..2b3929324cca3d1ba0e8e3d5c11aaad035cd61f7 100755 (executable)
@@ -207,9 +207,9 @@ ID="$(systemd-id128 new)"
 journalctl -t "$ID" --follow --cursor-file=/tmp/issue-26746-cursor | tee /tmp/issue-26746-log &
 systemd-cat -t "$ID" /bin/sh -c 'echo hogehoge'
 # shellcheck disable=SC2016
-timeout 10 bash -c 'while ! [[ -f /tmp/issue-26746-log && "$(cat /tmp/issue-26746-log)" =~ hogehoge ]]; do sleep .5; done'
+timeout 10 bash -c 'until [[ -f /tmp/issue-26746-log && "$(cat /tmp/issue-26746-log)" =~ hogehoge ]]; do sleep .5; done'
 pkill -TERM journalctl
-timeout 10 bash -c 'while ! test -f /tmp/issue-26746-cursor; do sleep .5; done'
+timeout 10 bash -c 'until test -f /tmp/issue-26746-cursor; do sleep .5; done'
 CURSOR_FROM_FILE="$(cat /tmp/issue-26746-cursor)"
 CURSOR_FROM_JOURNAL="$(journalctl -t "$ID" --output=export MESSAGE=hogehoge | sed -n -e '/__CURSOR=/ { s/__CURSOR=//; p }')"
 test "$CURSOR_FROM_FILE" = "$CURSOR_FROM_JOURNAL"
index 0d8c16e65a2a3826d98f736ababf37ec018aab22..de0577b97800f0719b4fe82f48446397ce3dd01a 100755 (executable)
@@ -13,5 +13,5 @@ nc -i20 -w20 -U /run/test.ctl || :
 # TriggerLimitIntervalSec= by default is set to 2s. A "sleep 10" should give
 # systemd enough time even on slower machines, to reach the trigger limit.
 # shellcheck disable=SC2016
-timeout 10 bash -c 'while ! [[ "$(systemctl show issue2467.socket -P ActiveState)" == failed ]]; do sleep .5; done'
+timeout 10 bash -c 'until [[ "$(systemctl show issue2467.socket -P ActiveState)" == failed ]]; do sleep .5; done'
 [[ "$(systemctl show issue2467.socket -P Result)" == trigger-limit-hit ]]
index e27bb36270cf4c6a24735109e6a5ccd6100138b2..b5f90f6d0c6bdb81955bd7b539bee3ea26ced649 100755 (executable)
@@ -13,7 +13,7 @@ at_exit() {
     set +e
 
     machinectl status long-running >/dev/null && machinectl kill --signal=KILL long-running
-    mountpoint -q /var/lib/machines && timeout 10 sh -c "while ! umount /var/lib/machines; do sleep .5; done"
+    mountpoint -q /var/lib/machines && timeout 10 sh -c "until umount /var/lib/machines; do sleep .5; done"
     [[ -n "${NSPAWN_FRAGMENT:-}" ]] && rm -f "/etc/systemd/nspawn/$NSPAWN_FRAGMENT" "/var/lib/machines/$NSPAWN_FRAGMENT"
     rm -f /run/systemd/nspawn/*.nspawn
 }
@@ -90,15 +90,15 @@ machinectl disable long-running long-running long-running container1
 # Equivalent to machinectl kill --signal=SIGRTMIN+4 --kill-whom=leader
 rm -f /var/lib/machines/long-running/poweroff
 machinectl poweroff long-running
-timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/poweroff; do sleep .5; done"
+timeout 10 bash -c "until test -e /var/lib/machines/long-running/poweroff; do sleep .5; done"
 # Equivalent to machinectl kill --signal=SIGINT --kill-whom=leader
 rm -f /var/lib/machines/long-running/reboot
 machinectl reboot long-running
-timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/reboot; do sleep .5; done"
+timeout 10 bash -c "until test -e /var/lib/machines/long-running/reboot; do sleep .5; done"
 # Skip machinectl terminate for now, as it doesn't play well with our "init"
 rm -f /var/lib/machines/long-running/trap
 machinectl kill --signal=SIGTRAP --kill-whom=leader long-running
-timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/trap; do sleep .5; done"
+timeout 10 bash -c "until test -e /var/lib/machines/long-running/trap; do sleep .5; done"
 # Multiple machines at once
 machinectl poweroff long-running long-running long-running
 machinectl reboot long-running long-running long-running
@@ -183,7 +183,7 @@ machinectl import-fs /tmp/container.dir container-dir
 machinectl start container-dir
 rm -fr /tmp/container.dir
 
-timeout 10 bash -c "while ! machinectl clean --all; do sleep .5; done"
+timeout 10 bash -c "until machinectl clean --all; do sleep .5; done"
 
 NSPAWN_FRAGMENT="machinectl-test-$RANDOM.nspawn"
 cat >"/var/lib/machines/$NSPAWN_FRAGMENT" <<EOF
index f5ffeab7123b6fb4510fad1c5db6110b5c481e01..b566c7343d0707fe36aebd8425c883282ef27603 100755 (executable)
@@ -11,7 +11,7 @@ at_exit() {
     set +e
 
     machinectl kill --signal=KILL nss-mymachines-{noip,singleip,manyips}
-    mountpoint -q /var/lib/machines && timeout 10 sh -c "while ! umount /var/lib/machines; do sleep .5; done"
+    mountpoint -q /var/lib/machines && timeout 10 sh -c "until umount /var/lib/machines; do sleep .5; done"
     rm -f /run/systemd/nspawn/*.nspawn
 }
 
index f5b5f372d165a1472839a69e8bca3a07b14e4b10..b232fca66808bc54da855b12c05fdad2210fd2e1 100755 (executable)
@@ -172,7 +172,7 @@ EOF
     done
     test -n "$found"
 
-    timeout 30 bash -c "while ! journalctl _PID=1 _COMM=systemd --since $since | grep -q 'foobar: systemd-udevd failed to process the device, ignoring: File exists'; do sleep 1; done"
+    timeout 30 bash -c "until journalctl _PID=1 _COMM=systemd --since $since | grep -q 'foobar: systemd-udevd failed to process the device, ignoring: File exists'; do sleep 1; done"
     # check if the invalid SYSTEMD_ALIAS property for the interface foobar is ignored by PID1
     assert_eq "$(systemctl show --property=SysFSPath --value /sys/subsystem/net/devices/hoge)" "/sys/devices/virtual/net/hoge"
 }
index bce4d7205b960034527c57d732bee59f29c7bd6d..e62f9c64dea1c2b2cf2da3f9eaa4af92b5788262 100755 (executable)
@@ -46,7 +46,7 @@ rm -f /tmp/testsuite-23-retry-fail
 systemctl start testsuite-23-retry-uphold.service
 systemctl is-active testsuite-23-upheldby-install.service
 
-while ! systemctl is-failed testsuite-23-retry-fail.service ; do
+until systemctl is-failed testsuite-23-retry-fail.service ; do
     sleep .5
 done
 
@@ -54,7 +54,7 @@ done
 
 touch /tmp/testsuite-23-retry-fail
 
-while ! systemctl is-active testsuite-23-retry-upheld.service ; do
+until systemctl is-active testsuite-23-retry-upheld.service ; do
     sleep .5
 done
 
index f784575c993bb9c8c62574d04a1d56e207a53794..291d156e88ef7de28cb0fdad2b16e3eb85a4f0f1 100755 (executable)
@@ -171,7 +171,7 @@ EOF
 
     evemu-device /run/lidswitch.evemu &
 
-    timeout 20 bash -c 'while ! grep "^Fake Lid Switch" /sys/class/input/*/device/name; do sleep .5; done'
+    timeout 20 bash -c 'until grep "^Fake Lid Switch" /sys/class/input/*/device/name; do sleep .5; done'
     input_name=$(grep -l '^Fake Lid Switch' /sys/class/input/*/device/name || :)
     if [[ -z "$input_name" ]]; then
         echo "cannot find fake lid switch." >&2
@@ -418,7 +418,7 @@ EOF
     # coldplug: logind started with existing device
     systemctl stop systemd-logind.service
     modprobe scsi_debug
-    timeout 30 bash -c 'while ! ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
+    timeout 30 bash -c 'until ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
     dev=/dev/$(ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null)
     if [[ ! -b "$dev" ]]; then
         echo "cannot find suitable scsi block device" >&2
@@ -437,7 +437,7 @@ EOF
     # hotplug: new device appears while logind is running
     rmmod scsi_debug
     modprobe scsi_debug
-    timeout 30 bash -c 'while ! ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
+    timeout 30 bash -c 'until ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
     dev=/dev/$(ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null)
     if [[ ! -b "$dev" ]]; then
         echo "cannot find suitable scsi block device" >&2
index 334afaabe7daf4f6c9ed666a833f1fbe8cd16649..8a53b984a652d586931a73f049c60ea742f1d93a 100755 (executable)
@@ -38,7 +38,7 @@ startStrace() {
     coproc strace -qq -p 1 -o "$straceLog" -e set_mempolicy -s 1024 ${1:+"$1"}
     # Wait for strace to properly "initialize", i.e. until PID 1 has the TracerPid
     # field set to the current strace's PID
-    while ! awk -v spid="$COPROC_PID" '/^TracerPid:/ {exit !($2 == spid);}' /proc/1/status; do sleep 0.1; done
+    until awk -v spid="$COPROC_PID" '/^TracerPid:/ {exit !($2 == spid);}' /proc/1/status; do sleep 0.1; done
 }
 
 stopStrace() {
index c02dfc862c70d7a637639abf9b49f982d847c899..44889779ccb2810bee4b125736884ec98c45d2f3 100755 (executable)
@@ -549,7 +549,7 @@ systemd-run --unit=test-root-ephemeral \
 test -n "$(ls -A /var/lib/systemd/ephemeral-trees)"
 systemctl stop test-root-ephemeral
 # shellcheck disable=SC2016
-timeout 10 bash -c 'while ! test -z "$(ls -A /var/lib/systemd/ephemeral-trees)"; do sleep .5; done'
+timeout 10 bash -c 'until test -z "$(ls -A /var/lib/systemd/ephemeral-trees)"; do sleep .5; done'
 test ! -f /tmp/img/abc
 
 systemd-dissect --mtree /tmp/img
index 875cdb8ff3d0be469e1c1c4d6ba8625e2f2ff7d0..e800a7a12c2695d1246f7850bb1521dcef9d6009 100755 (executable)
@@ -286,8 +286,8 @@ done
 
 # Figure out if we have entered the rate limit state.
 # If the infra is slow we might not enter the rate limit state; in that case skip the exit check.
-if timeout 2m bash -c "while ! journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do sleep 1; done"; then
-    timeout 2m bash -c "while ! journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do sleep 1; done"
+if timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do sleep 1; done"; then
+    timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do sleep 1; done"
 fi
 
 # Verify that the mount units are always cleaned up at the end.
index dd08f4e90eda7cebead5c2ad45204c47bf24b97d..9bbd700104562428e2b9ab2f57c74f5d49620dcc 100755 (executable)
@@ -16,7 +16,7 @@ touch /tmp/test63
 
 # Make sure systemd has sufficient time to hit the trigger limit for test63.path.
 # shellcheck disable=SC2016
-timeout 30 bash -c 'while ! test "$(systemctl show test63.path -P ActiveState)" = failed; do sleep .2; done'
+timeout 30 bash -c 'until test "$(systemctl show test63.path -P ActiveState)" = failed; do sleep .2; done'
 test "$(systemctl show test63.service -P ActiveState)" = inactive
 test "$(systemctl show test63.service -P Result)" = success
 test "$(systemctl show test63.path -P Result)" = trigger-limit-hit
@@ -34,7 +34,7 @@ test "$(systemctl show test63.path -P Result)" = success
 # Test that glob matching works too, with $TRIGGER_PATH
 systemctl start test63-glob.path
 touch /tmp/test63-glob-foo
-timeout 60 bash -c 'while ! systemctl -q is-active test63-glob.service; do sleep .2; done'
+timeout 60 bash -c 'until systemctl -q is-active test63-glob.service; do sleep .2; done'
 test "$(systemctl show test63-glob.service -P ActiveState)" = active
 test "$(systemctl show test63-glob.service -P Result)" = success
 
index 0100f58c440871e6d1e4e25500d3da6167cda293..d223f52b6a2c4eb17395df8c5dd1fbcda7af3263 100755 (executable)
@@ -546,7 +546,7 @@ testcase_lvm_basic() {
     # Mount mypart1 through by-label devlink
     mkdir -p /tmp/mypart1-mount-point
     mount /dev/disk/by-label/mylvpart1 /tmp/mypart1-mount-point
-    timeout 30 bash -c "while ! systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
+    timeout 30 bash -c "until systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
     # Extend the partition and check if the device and mount units are still active.
     # See https://bugzilla.redhat.com/show_bug.cgi?id=2158628
     # Note, the test below may be unstable with LVM2 without the following patch:
@@ -556,8 +556,8 @@ testcase_lvm_basic() {
     # is hopefully fast.
     lvm lvextend -y --size 8M "/dev/$vgroup/mypart1"
     udevadm wait --settle --timeout="$timeout" "/dev/disk/by-label/mylvpart1"
-    timeout 30 bash -c "while ! systemctl -q is-active '/dev/$vgroup/mypart1'; do sleep .2; done"
-    timeout 30 bash -c "while ! systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
+    timeout 30 bash -c "until systemctl -q is-active '/dev/$vgroup/mypart1'; do sleep .2; done"
+    timeout 30 bash -c "until systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
     # Umount the partition, otherwise the underlying device unit will stay in
     # the inactive state and not be collected, and helper_check_device_units() will fail.
     systemctl show /tmp/mypart1-mount-point
@@ -956,7 +956,7 @@ testcase_long_sysfs_path() {
     echo "UUID=deadbeef-dead-dead-beef-222222222222 $mpoint ext4 defaults 0 0" >>/etc/fstab
     systemctl daemon-reload
     mount "$mpoint"
-    timeout 30 bash -c "while ! systemctl -q is-active '$mpoint'; do sleep .2; done"
+    timeout 30 bash -c "until systemctl -q is-active '$mpoint'; do sleep .2; done"
     test -e "$mpoint/test"
     umount "$mpoint"