summaryrefslogtreecommitdiffstats
path: root/test/units/testsuite-35.sh
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-07-08 13:22:40 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2022-07-08 18:14:38 +0200
commit9d9fd4ad0a66eea9635081e8ef765e29865d22bf (patch)
tree148cca3c1328a1ad65a30cf605546afddbd4851a /test/units/testsuite-35.sh
parentmac: rework labelling code to be simpler, and less racy (diff)
downloadsystemd-9d9fd4ad0a66eea9635081e8ef765e29865d22bf.tar.xz
systemd-9d9fd4ad0a66eea9635081e8ef765e29865d22bf.zip
test: start test user session before idle action setting is changed
Otherwise, idle action may be triggered before starting the test user session. This also introduce create_session() and cleanup_session() helper functions. Fixes #23952.
Diffstat (limited to 'test/units/testsuite-35.sh')
-rwxr-xr-xtest/units/testsuite-35.sh87
1 files changed, 38 insertions, 49 deletions
diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
index 147604e293..612f92ac19 100755
--- a/test/units/testsuite-35.sh
+++ b/test/units/testsuite-35.sh
@@ -214,7 +214,7 @@ test_shutdown() {
assert_eq "$(systemctl show systemd-logind.service -p ExecMainPID --value)" "$pid"
}
-teardown_session() (
+cleanup_session() (
set +ex
systemctl stop getty@tty2.service
@@ -224,6 +224,12 @@ teardown_session() (
pkill -u "$(id -u logind-test-user)"
sleep 1
pkill -KILL -u "$(id -u logind-test-user)"
+)
+
+teardown_session() (
+ set +ex
+
+ cleanup_session
rm -f /run/udev/rules.d/70-logindtest-scsi_debug-user.rules
udevadm control --reload
@@ -271,21 +277,7 @@ check_session() (
fi
)
-test_session() {
- local dev
-
- if systemd-detect-virt --quiet --container; then
- echo "Skipping ACL tests in container"
- return
- fi
-
- if [[ ! -c /dev/tty2 ]]; then
- echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
- return
- fi
-
- trap teardown_session RETURN
-
+create_session() {
# login with the test user to start a session
mkdir -p /run/systemd/system/getty@tty2.service.d
cat >/run/systemd/system/getty@tty2.service.d/override.conf <<EOF
@@ -295,6 +287,7 @@ ExecStart=
ExecStart=-/sbin/agetty --autologin logind-test-user --noclear %I $TERM
EOF
systemctl daemon-reload
+
systemctl restart getty@tty2.service
# check session
@@ -303,6 +296,25 @@ EOF
check_session && break
done
check_session
+ assert_eq "$(loginctl --no-legend | awk '$3=="logind-test-user" { print $5 }')" "tty2"
+}
+
+test_session() {
+ local dev
+
+ if systemd-detect-virt --quiet --container; then
+ echo "Skipping ACL tests in container"
+ return
+ fi
+
+ if [[ ! -c /dev/tty2 ]]; then
+ echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
+ return
+ fi
+
+ trap teardown_session RETURN
+
+ create_session
# scsi_debug should not be loaded yet
if [[ -d /sys/bus/pseudo/drivers/scsi_debug ]]; then
@@ -356,13 +368,7 @@ EOF
teardown_lock_idle_action() (
set +eux
- systemctl stop getty@tty2.service
- rm -rf /run/systemd/system/getty@tty2.service.d
- systemctl daemon-reload
-
- pkill -u "$(id -u logind-test-user)"
- sleep 1
- pkill -KILL -u "$(id -u logind-test-user)"
+ cleanup_session
rm -f /run/systemd/logind.conf.d/idle-action-lock.conf
systemctl restart systemd-logind.service
@@ -376,8 +382,17 @@ test_lock_idle_action() {
return
fi
+ if loginctl --no-legend | grep -q logind-test-user; then
+ echo >&2 "Session of the \'logind-test-user\' is already present."
+ exit 1
+ fi
+
trap teardown_lock_idle_action RETURN
+ create_session
+
+ ts="$(date '+%H:%M:%S')"
+
mkdir -p /run/systemd/logind.conf.d
cat >/run/systemd/logind.conf.d/idle-action-lock.conf <<EOF
[Login]
@@ -386,32 +401,6 @@ IdleActionSec=1s
EOF
systemctl restart systemd-logind.service
- if loginctl --no-legend | grep -q logind-test-user; then
- echo >&2 "Session of the \'logind-test-user\' is already present."
- exit 1
- fi
-
- # login with the test user to start a session
- mkdir -p /run/systemd/system/getty@tty2.service.d
- cat >/run/systemd/system/getty@tty2.service.d/override.conf <<EOF
-[Service]
-Type=simple
-ExecStart=
-ExecStart=-/sbin/agetty --autologin logind-test-user --noclear %I $TERM
-EOF
- systemctl daemon-reload
-
- ts="$(date '+%H:%M:%S')"
- systemctl restart getty@tty2.service
-
- # check session
- for ((i = 0; i < 30; i++)); do
- (( i != 0 )) && sleep 1
- check_session && break
- done
- check_session
- assert_eq "$(loginctl --no-legend | awk '$3=="logind-test-user" { print $5 }')" "tty2"
-
# Wait for 35s, in that interval all sessions should have become idle
# and "Lock" signal should have been sent out. Then we wrote to tty to make
# session active again and next we slept for another 35s so sessions have