2aacef
From 07f188e9ca17345af904e6549c03b1c57d34405a Mon Sep 17 00:00:00 2001
2aacef
From: Frantisek Sumsal <frantisek@sumsal.cz>
2aacef
Date: Tue, 1 Nov 2022 09:17:58 +0100
2aacef
Subject: [PATCH] test: add a couple of sanity tests for loginctl
2aacef
2aacef
(cherry picked from commit 70e9066bc2eaf159e9cde7d95bbee99e44f3045a)
2aacef
2aacef
Related #2138081
2aacef
---
2aacef
 test/units/testsuite-35.sh | 45 ++++++++++++++++++++++++++++++++++++++
2aacef
 1 file changed, 45 insertions(+)
2aacef
2aacef
diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
2aacef
index 4ef0f0c11c..85925f2471 100755
2aacef
--- a/test/units/testsuite-35.sh
2aacef
+++ b/test/units/testsuite-35.sh
2aacef
@@ -338,6 +338,50 @@ EOF
2aacef
     assert_eq "$(loginctl --no-legend | awk '$3=="logind-test-user" { print $5 }')" "tty2"
2aacef
 }
2aacef
 
2aacef
+test_sanity_check() {
2aacef
+    # Exercise basic loginctl options
2aacef
+
2aacef
+    if [[ ! -c /dev/tty2 ]]; then
2aacef
+        echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
2aacef
+        return
2aacef
+    fi
2aacef
+
2aacef
+    trap cleanup_session RETURN
2aacef
+    create_session
2aacef
+
2aacef
+    # Run most of the loginctl commands from a user session to make
2aacef
+    # the seat/session autodetection work-ish
2aacef
+    systemd-run --user --pipe --wait -M "logind-test-user@.host" bash -eux <<\EOF
2aacef
+    loginctl list-sessions
2aacef
+    loginctl session-status
2aacef
+    loginctl show-session
2aacef
+    loginctl show-session -P DelayInhibited
2aacef
+
2aacef
+    # We're not in the same session scope, so in this case we need to specify
2aacef
+    # the session ID explicitly
2aacef
+    session=$(loginctl --no-legend | awk '$3 == "logind-test-user" { print $1; exit; }')
2aacef
+    loginctl kill-session --signal=SIGCONT "$session"
2aacef
+    # FIXME(?)
2aacef
+    #loginctl kill-session --signal=SIGCONT --kill-who=leader "$session"
2aacef
+
2aacef
+    loginctl list-users
2aacef
+    loginctl user-status
2aacef
+    loginctl show-user -a
2aacef
+    loginctl show-user -P IdleAction
2aacef
+    loginctl kill-user --signal=SIGCONT ""
2aacef
+
2aacef
+    loginctl list-seats
2aacef
+    loginctl seat-status
2aacef
+    loginctl show-seat
2aacef
+    loginctl show-seat -P IdleActionUSec
2aacef
+EOF
2aacef
+
2aacef
+    # Requires root privileges
2aacef
+    loginctl lock-sessions
2aacef
+    loginctl unlock-sessions
2aacef
+    loginctl flush-devices
2aacef
+}
2aacef
+
2aacef
 test_session() {
2aacef
     local dev
2aacef
 
2aacef
@@ -537,6 +581,7 @@ test_properties
2aacef
 test_started
2aacef
 test_suspend_on_lid
2aacef
 test_shutdown
2aacef
+test_sanity_check
2aacef
 test_session
2aacef
 test_lock_idle_action
2aacef
 test_session_properties