teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0017-test-add-a-sanity-coverage-for-systemd-analyze-verbs.patch

2aacef
From d68d785ba0e3ecd59a2678fe00fbd7b1bde90622 Mon Sep 17 00:00:00 2001
2aacef
From: Frantisek Sumsal <frantisek@sumsal.cz>
2aacef
Date: Wed, 2 Nov 2022 17:51:51 +0100
2aacef
Subject: [PATCH] test: add a sanity coverage for systemd-analyze verbs
2aacef
2aacef
(cherry picked from commit 6c83054c0133eb53245e479d71589dceff76cf74)
2aacef
2aacef
Related #2138081
2aacef
---
2aacef
 test/units/testsuite-65.sh | 108 +++++++++++++++++++++++++++++++++++++
2aacef
 1 file changed, 108 insertions(+)
2aacef
2aacef
diff --git a/test/units/testsuite-65.sh b/test/units/testsuite-65.sh
2aacef
index 64ce629f3b..ece6b8734e 100755
2aacef
--- a/test/units/testsuite-65.sh
2aacef
+++ b/test/units/testsuite-65.sh
2aacef
@@ -9,6 +9,114 @@ set -eux
2aacef
 systemd-analyze log-level debug
2aacef
 export SYSTEMD_LOG_LEVEL=debug
2aacef
 
2aacef
+# Sanity checks
2aacef
+#
2aacef
+# We can't really test time, blame, critical-chain and plot verbs here, as
2aacef
+# the testsuite service is a part of the boot transaction, so let's assume
2aacef
+# they fail
2aacef
+systemd-analyze || :
2aacef
+systemd-analyze time || :
2aacef
+systemd-analyze blame || :
2aacef
+systemd-analyze critical-chain || :
2aacef
+systemd-analyze plot >/dev/null || :
2aacef
+# dot
2aacef
+systemd-analyze dot >/dev/null
2aacef
+systemd-analyze dot systemd-journald.service >/dev/null
2aacef
+systemd-analyze dot systemd-journald.service systemd-logind.service >/dev/null
2aacef
+systemd-analyze dot --from-pattern="*" --from-pattern="*.service" systemd-journald.service >/dev/null
2aacef
+systemd-analyze dot --to-pattern="*" --to-pattern="*.service" systemd-journald.service >/dev/null
2aacef
+systemd-analyze dot --from-pattern="*.service" --to-pattern="*.service" systemd-journald.service >/dev/null
2aacef
+systemd-analyze dot --order systemd-journald.service systemd-logind.service >/dev/null
2aacef
+systemd-analyze dot --require systemd-journald.service systemd-logind.service >/dev/null
2aacef
+systemd-analyze dot "systemd-*.service" >/dev/null
2aacef
+(! systemd-analyze dot systemd-journald.service systemd-logind.service "*" bbb ccc)
2aacef
+# dump
2aacef
+systemd-analyze dump >/dev/null
2aacef
+systemd-analyze dump "*" >/dev/null
2aacef
+systemd-analyze dump "*.socket" >/dev/null
2aacef
+systemd-analyze dump systemd-journald.service >/dev/null
2aacef
+(! systemd-analyze dump "")
2aacef
+# unit-paths
2aacef
+systemd-analyze unit-paths
2aacef
+systemd-analyze unit-paths --user
2aacef
+systemd-analyze unit-paths --global
2aacef
+# exist-status
2aacef
+systemd-analyze exit-status
2aacef
+systemd-analyze exit-status STDOUT BPF
2aacef
+systemd-analyze exit-status 0 1 {63..65}
2aacef
+(! systemd-analyze exit-status STDOUT BPF "hello*")
2aacef
+# capability
2aacef
+systemd-analyze capability
2aacef
+systemd-analyze capability cap_chown CAP_KILL
2aacef
+systemd-analyze capability 0 1 {30..32}
2aacef
+(! systemd-analyze capability cap_chown CAP_KILL "hello*")
2aacef
+# condition
2aacef
+mkdir -p /run/systemd/system
2aacef
+UNIT_NAME="analyze-condition-$RANDOM.service"
2aacef
+cat >"/run/systemd/system/$UNIT_NAME" <
2aacef
+[Unit]
2aacef
+AssertPathExists=/etc/os-release
2aacef
+AssertEnvironment=!FOOBAR
2aacef
+ConditionKernelVersion=>1.0
2aacef
+ConditionPathExists=/etc/os-release
2aacef
+
2aacef
+[Service]
2aacef
+ExecStart=/bin/true
2aacef
+EOF
2aacef
+systemctl daemon-reload
2aacef
+systemd-analyze condition --unit="$UNIT_NAME"
2aacef
+systemd-analyze condition 'ConditionKernelVersion = ! <4.0' \
2aacef
+                          'ConditionKernelVersion = >=3.1' \
2aacef
+                          'ConditionACPower=|false' \
2aacef
+                          'ConditionArchitecture=|!arm' \
2aacef
+                          'AssertPathExists=/etc/os-release'
2aacef
+(! systemd-analyze condition 'ConditionArchitecture=|!arm' 'AssertXYZ=foo')
2aacef
+(! systemd-analyze condition 'ConditionKernelVersion=<1.0')
2aacef
+(! systemd-analyze condition 'AssertKernelVersion=<1.0')
2aacef
+# syscall-filter
2aacef
+systemd-analyze syscall-filter >/dev/null
2aacef
+systemd-analyze syscall-filter @chown @sync
2aacef
+systemd-analyze syscall-filter @sync @sync @sync
2aacef
+(! systemd-analyze syscall-filter @chown @sync @foobar)
2aacef
+# filesystems (requires libbpf support)
2aacef
+if systemctl --version | grep "+BPF_FRAMEWORK"; then
2aacef
+    systemd-analyze filesystems >/dev/null
2aacef
+    systemd-analyze filesystems @basic-api
2aacef
+    systemd-analyze filesystems @basic-api @basic-api @basic-api
2aacef
+    (! systemd-analyze filesystems @basic-api @basic-api @foobar @basic-api)
2aacef
+fi
2aacef
+# calendar
2aacef
+systemd-analyze calendar '*-2-29 0:0:0'
2aacef
+systemd-analyze calendar --iterations=5 '*-2-29 0:0:0'
2aacef
+systemd-analyze calendar '*-* *:*:*'
2aacef
+systemd-analyze calendar --iterations=5 '*-* *:*:*'
2aacef
+systemd-analyze calendar --iterations=50 '*-* *:*:*'
2aacef
+systemd-analyze calendar --iterations=0 '*-* *:*:*'
2aacef
+systemd-analyze calendar --base-time=yesterday --iterations=5 '*-* *:*:*'
2aacef
+(! systemd-analyze calendar --iterations=0 '*-* 99:*:*')
2aacef
+(! systemd-analyze calendar --base-time=never '*-* *:*:*')
2aacef
+(! systemd-analyze calendar 1)
2aacef
+(! systemd-analyze calendar "")
2aacef
+# timestamp
2aacef
+systemd-analyze timestamp now
2aacef
+systemd-analyze timestamp -- -1
2aacef
+systemd-analyze timestamp yesterday now tomorrow
2aacef
+(! systemd-analyze timestamp yesterday never tomorrow)
2aacef
+(! systemd-analyze timestamp 1)
2aacef
+(! systemd-analyze timestamp "")
2aacef
+# timespan
2aacef
+systemd-analyze timespan 1
2aacef
+systemd-analyze timespan 1s 300s '1year 0.000001s'
2aacef
+(! systemd-analyze timespan 1s 300s aaaaaa '1year 0.000001s')
2aacef
+(! systemd-analyze timespan -- -1)
2aacef
+(! systemd-analyze timespan "")
2aacef
+# cat-config
2aacef
+systemd-analyze cat-config systemd/system.conf >/dev/null
2aacef
+systemd-analyze cat-config /etc/systemd/system.conf >/dev/null
2aacef
+systemd-analyze cat-config systemd/system.conf systemd/journald.conf >/dev/null
2aacef
+systemd-analyze cat-config systemd/system.conf foo/bar systemd/journald.conf >/dev/null
2aacef
+systemd-analyze cat-config foo/bar
2aacef
+
2aacef
 mkdir -p /tmp/img/usr/lib/systemd/system/
2aacef
 mkdir -p /tmp/img/opt/
2aacef