dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
ac3a84
From cce2e337e37524df5ff81e758dbcfa91bf8b696a Mon Sep 17 00:00:00 2001
ac3a84
From: Frantisek Sumsal <frantisek@sumsal.cz>
ac3a84
Date: Wed, 2 Nov 2022 11:44:00 +0100
ac3a84
Subject: [PATCH] test: further extend systemctl's sanity coverage
ac3a84
ac3a84
Also, fix a race condition introduced by d16684fe13:
ac3a84
```
ac3a84
[   16.904218] H testsuite-26.sh[394]: + systemd-run --unit failed.service /bin/false
ac3a84
[   16.964783] H systemd[845]: failed.service: Executing: /bin/false
ac3a84
[   16.965062] H systemd[1]: Started failed.service.
ac3a84
[   16.965462] H testsuite-26.sh[844]: Running as unit: failed.service
ac3a84
[   16.966390] H testsuite-26.sh[394]: + systemctl is-failed failed.service
ac3a84
[   16.977970] H testsuite-26.sh[846]: active
ac3a84
[   16.978403] H systemd[1]: failed.service: Main process exited, code=exited, status=1/FAILURE
ac3a84
[   16.978478] H systemd[1]: failed.service: Failed with result 'exit-code'.
ac3a84
```
ac3a84
ac3a84
(cherry picked from commit 23f3a6f5ff864fd26063c6c35fdaa6d85de566c7)
ac3a84
ac3a84
Related #2138081
ac3a84
---
ac3a84
 test/units/testsuite-26.sh | 61 +++++++++++++++++++++++++++++++++++++-
ac3a84
 1 file changed, 60 insertions(+), 1 deletion(-)
ac3a84
ac3a84
diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh
ac3a84
index b83f85917b..7c7a12b1ae 100755
ac3a84
--- a/test/units/testsuite-26.sh
ac3a84
+++ b/test/units/testsuite-26.sh
ac3a84
@@ -58,6 +58,9 @@ systemctl list-units
ac3a84
 systemctl list-units --recursive
ac3a84
 systemctl list-units --type=socket
ac3a84
 systemctl list-units --type=service,timer
ac3a84
+# Compat: --type= allows load states for compatibility reasons
ac3a84
+systemctl list-units --type=loaded
ac3a84
+systemctl list-units --type=loaded,socket
ac3a84
 systemctl list-units --legend=yes -a "systemd-*"
ac3a84
 systemctl list-units --state=active
ac3a84
 systemctl list-units --with-dependencies systemd-journald.service
ac3a84
@@ -160,7 +163,7 @@ systemctl revert "$UNIT_NAME"
ac3a84
 (! grep -r "CPUQuota=" "/run/systemd/system.control/${UNIT_NAME}.d/")
ac3a84
 
ac3a84
 # Failed-unit related tests
ac3a84
-systemd-run --unit "failed.service" /bin/false
ac3a84
+(! systemd-run --wait --unit "failed.service" /bin/false)
ac3a84
 systemctl is-failed failed.service
ac3a84
 systemctl --state=failed | grep failed.service
ac3a84
 systemctl --failed | grep failed.service
ac3a84
@@ -189,11 +192,67 @@ for value in pretty us µs utc us+utc µs+utc; do
ac3a84
     systemctl show -P KernelTimestamp --timestamp="$value"
ac3a84
 done
ac3a84
 
ac3a84
+# set-default/get-default
ac3a84
+target="$(systemctl get-default)"
ac3a84
+systemctl set-default emergency.target
ac3a84
+[[ "$(systemctl get-default)" == emergency.target ]]
ac3a84
+systemctl set-default "$target"
ac3a84
+[[ "$(systemctl get-default)" == "$target" ]]
ac3a84
+
ac3a84
+# show/status
ac3a84
+systemctl show --property ""
ac3a84
+# Pick a heavily sandboxed unit for the best effect on coverage
ac3a84
+systemctl show systemd-logind.service
ac3a84
+systemctl status
ac3a84
+# Ignore the exit code in this case, as it might try to load non-existing units
ac3a84
+systemctl status -a >/dev/null || :
ac3a84
+systemctl status -a --state active,running,plugged >/dev/null
ac3a84
+systemctl status "systemd-*.timer"
ac3a84
+systemctl status "systemd-journald*.socket"
ac3a84
+systemctl status "sys-devices-*-ttyS0.device"
ac3a84
+systemctl status -- -.mount
ac3a84
+
ac3a84
+# --marked
ac3a84
+systemctl restart "$UNIT_NAME"
ac3a84
+systemctl set-property "$UNIT_NAME" Markers=needs-restart
ac3a84
+systemctl show -P Markers "$UNIT_NAME" | grep needs-restart
ac3a84
+systemctl reload-or-restart --marked
ac3a84
+(! systemctl show -P Markers "$UNIT_NAME" | grep needs-restart)
ac3a84
+
ac3a84
+# --dry-run with destructive verbs
ac3a84
+# kexec is skipped intentionally, as it requires a bit more involved setup
ac3a84
+VERBS=(
ac3a84
+    default
ac3a84
+    emergency
ac3a84
+    exit
ac3a84
+    halt
ac3a84
+    hibernate
ac3a84
+    hybrid-sleep
ac3a84
+    poweroff
ac3a84
+    reboot
ac3a84
+    rescue
ac3a84
+    suspend
ac3a84
+    suspend-then-hibernate
ac3a84
+)
ac3a84
+
ac3a84
+for verb in "${VERBS[@]}"; do
ac3a84
+    systemctl --dry-run "$verb"
ac3a84
+
ac3a84
+    if [[ "$verb" =~ (halt|poweroff|reboot) ]]; then
ac3a84
+        systemctl --dry-run --message "Hello world" "$verb"
ac3a84
+        systemctl --dry-run --no-wall "$verb"
ac3a84
+        systemctl --dry-run -f "$verb"
ac3a84
+        systemctl --dry-run -ff "$verb"
ac3a84
+    fi
ac3a84
+done
ac3a84
+
ac3a84
 # Aux verbs & assorted checks
ac3a84
 systemctl is-active "*-journald.service"
ac3a84
 systemctl cat "*journal*"
ac3a84
 systemctl cat "$UNIT_NAME"
ac3a84
 systemctl help "$UNIT_NAME"
ac3a84
+systemctl service-watchdogs
ac3a84
+systemctl service-watchdogs "$(systemctl service-watchdogs)"
ac3a84
 
ac3a84
 # show/set-environment
ac3a84
 # Make sure PATH is set