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