mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
test: add a couple of tests for busctl
This commit is contained in:
parent
e079120505
commit
16600a8661
102
test/units/testsuite-74.busctl.sh
Executable file
102
test/units/testsuite-74.busctl.sh
Executable file
@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
set -eux
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Unset $PAGER so we don't have to use --no-pager everywhere
|
||||||
|
export PAGER=
|
||||||
|
|
||||||
|
busctl --help
|
||||||
|
busctl help
|
||||||
|
busctl --version
|
||||||
|
busctl
|
||||||
|
busctl list --no-pager --allow-interactive-authorization=no
|
||||||
|
busctl list
|
||||||
|
busctl list --unique --show-machine --full
|
||||||
|
# Pass the JSON output (-j) through jq to check if it's valid
|
||||||
|
busctl list --acquired --activatable --no-legend -j | jq
|
||||||
|
busctl status
|
||||||
|
busctl status --machine=.host --augment-creds=no
|
||||||
|
busctl status --user --machine=testuser@.host
|
||||||
|
busctl status org.freedesktop.systemd1
|
||||||
|
busctl tree
|
||||||
|
busctl tree org.freedesktop.login1
|
||||||
|
busctl tree --list org.freedesktop.login1
|
||||||
|
busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd1
|
||||||
|
busctl introspect --watch-bind=yes --xml-interface org.freedesktop.systemd1 /org/freedesktop/LogControl1
|
||||||
|
busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager
|
||||||
|
|
||||||
|
busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
GetDefaultTarget
|
||||||
|
# Pass both JSON outputs through jq to check if the response JSON is valid
|
||||||
|
busctl call --json=pretty \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
ListUnitsByNames as 2 "systemd-journald.service" "systemd-logind.service" | jq
|
||||||
|
busctl call --json=short \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
ListUnitsByNames as 2 "systemd-journald.service" "systemd-logind.service" | jq
|
||||||
|
busctl call --verbose --timeout=60 --expect-reply=yes \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
ListUnitsByPatterns asas 1 "active" 2 "systemd-*.socket" "*.mount"
|
||||||
|
|
||||||
|
busctl emit /org/freedesktop/login1 org.freedesktop.login1.Manager \
|
||||||
|
PrepareForSleep b false
|
||||||
|
busctl emit --auto-start=no --destination=systemd-logind.service \
|
||||||
|
/org/freedesktop/login1 org.freedesktop.login1.Manager \
|
||||||
|
PrepareForShutdown b false
|
||||||
|
|
||||||
|
busctl get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
Version
|
||||||
|
busctl get-property --verbose \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
LogLevel LogTarget SystemState Version
|
||||||
|
# Pass both JSON outputs through jq to check if the response JSON is valid
|
||||||
|
busctl get-property --json=pretty \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
LogLevel LogTarget SystemState Version | jq
|
||||||
|
busctl get-property --json=short \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
LogLevel LogTarget SystemState Version | jq
|
||||||
|
|
||||||
|
# Set a property and check if it was indeed set
|
||||||
|
busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
KExecWatchdogUSec t 666
|
||||||
|
busctl get-property -j \
|
||||||
|
org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
KExecWatchdogUSec | jq -e '.data == 666'
|
||||||
|
|
||||||
|
(! busctl status org.freedesktop.systemd2)
|
||||||
|
(! busctl tree org.freedesktop.systemd2)
|
||||||
|
(! busctl introspect org.freedesktop.systemd1)
|
||||||
|
(! busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd2)
|
||||||
|
(! busctl introspect org.freedesktop.systemd2 /org/freedesktop/systemd1)
|
||||||
|
|
||||||
|
# Invalid method
|
||||||
|
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
ThisMethodDoesntExist)
|
||||||
|
# Invalid signature
|
||||||
|
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
ListUnitsByNames ab 1 false)
|
||||||
|
# Invalid arguments
|
||||||
|
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
GetUnitByPID u "hello")
|
||||||
|
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
-- ListUnitsByNames as -1 "systemd-journald.service")
|
||||||
|
# Not enough arguments
|
||||||
|
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
ListUnitsByNames as 99 "systemd-journald.service")
|
||||||
|
|
||||||
|
(! busctl get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
NonexistentProperty)
|
||||||
|
(! busctl get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
Version NonexistentProperty Version)
|
||||||
|
|
||||||
|
# Invalid property
|
||||||
|
(! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
NonexistentProperty t 666)
|
||||||
|
# Invalid signature
|
||||||
|
(! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
KExecWatchdogUSec s 666)
|
||||||
|
# Invalid argument
|
||||||
|
(! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
|
||||||
|
KExecWatchdogUSec t "foo")
|
Loading…
Reference in New Issue
Block a user