dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
594167
From 2ac026ce61d73f76e33a31fdb29c73ec40a05dfc Mon Sep 17 00:00:00 2001
594167
From: Yu Watanabe <watanabe.yu+github@gmail.com>
594167
Date: Fri, 8 Jul 2022 20:22:40 +0900
594167
Subject: [PATCH] test: start test user session before idle action setting is
594167
 changed
594167
594167
Otherwise, idle action may be triggered before starting the test user
594167
session.
594167
594167
This also introduce create_session() and cleanup_session() helper
594167
functions.
594167
594167
Fixes #23952.
594167
594167
(cherry picked from commit 9d9fd4ad0a66eea9635081e8ef765e29865d22bf)
594167
594167
Related: #2100464
594167
---
594167
 test/units/testsuite-35.sh | 44 ++++++++++++++++++++++++--------------
594167
 1 file changed, 28 insertions(+), 16 deletions(-)
594167
594167
diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
594167
index 86787e7a02..9c37fc36d0 100755
594167
--- a/test/units/testsuite-35.sh
594167
+++ b/test/units/testsuite-35.sh
594167
@@ -214,7 +214,7 @@ test_shutdown() {
594167
     assert_eq "$(systemctl show systemd-logind.service -p ExecMainPID --value)" "$pid"
594167
 }
594167
 
594167
-teardown_session() (
594167
+cleanup_session() (
594167
     set +ex
594167
 
594167
     systemctl stop getty@tty2.service
594167
@@ -224,6 +224,12 @@ teardown_session() (
594167
     pkill -u "$(id -u logind-test-user)"
594167
     sleep 1
594167
     pkill -KILL -u "$(id -u logind-test-user)"
594167
+)
594167
+
594167
+teardown_session() (
594167
+    set +ex
594167
+
594167
+    cleanup_session
594167
 
594167
     rm -f /run/udev/rules.d/70-logindtest-scsi_debug-user.rules
594167
     udevadm control --reload
594167
@@ -271,21 +277,7 @@ check_session() (
594167
     fi
594167
 )
594167
 
594167
-test_session() {
594167
-    local dev
594167
-
594167
-    if systemd-detect-virt --quiet --container; then
594167
-        echo "Skipping ACL tests in container"
594167
-        return
594167
-    fi
594167
-
594167
-    if [[ ! -c /dev/tty2 ]]; then
594167
-        echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
594167
-        return
594167
-    fi
594167
-
594167
-    trap teardown_session RETURN
594167
-
594167
+create_session() {
594167
     # login with the test user to start a session
594167
     mkdir -p /run/systemd/system/getty@tty2.service.d
594167
     cat >/run/systemd/system/getty@tty2.service.d/override.conf <
594167
@@ -295,6 +287,7 @@ ExecStart=
594167
 ExecStart=-/sbin/agetty --autologin logind-test-user --noclear %I $TERM
594167
 EOF
594167
     systemctl daemon-reload
594167
+
594167
     systemctl restart getty@tty2.service
594167
 
594167
     # check session
594167
@@ -303,6 +296,25 @@ EOF
594167
         check_session && break
594167
     done
594167
     check_session
594167
+    assert_eq "$(loginctl --no-legend | awk '$3=="logind-test-user" { print $5 }')" "tty2"
594167
+}
594167
+
594167
+test_session() {
594167
+    local dev
594167
+
594167
+    if systemd-detect-virt --quiet --container; then
594167
+        echo "Skipping ACL tests in container"
594167
+        return
594167
+    fi
594167
+
594167
+    if [[ ! -c /dev/tty2 ]]; then
594167
+        echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
594167
+        return
594167
+    fi
594167
+
594167
+    trap teardown_session RETURN
594167
+
594167
+    create_session
594167
 
594167
     # scsi_debug should not be loaded yet
594167
     if [[ -d /sys/bus/pseudo/drivers/scsi_debug ]]; then