mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
tests: add test for handling of background sessions
This commit is contained in:
committed by
Yu Watanabe
parent
e73bf3425c
commit
bf40417c7c
@@ -1736,6 +1736,7 @@ install_basic_tools() {
|
||||
# in Debian ldconfig is just a shell script wrapper around ldconfig.real
|
||||
image_install -o ldconfig.real
|
||||
# for TEST-35-LOGIN
|
||||
image_install -o evemu-device evemu-event crond crontab
|
||||
image_install -o evemu-device evemu-event
|
||||
if command -v expect >/dev/null && command -v tclsh >/dev/null ; then
|
||||
# shellcheck disable=SC2016
|
||||
|
||||
@@ -443,6 +443,69 @@ EOF
|
||||
rm -f dbus.log logind.log
|
||||
}
|
||||
|
||||
setup_cron() {
|
||||
# Setup test user and cron
|
||||
useradd test || :
|
||||
crond -s -n &
|
||||
# Install crontab for the test user that runs sleep every minute. But let's sleep for
|
||||
# 65 seconds to make sure there is overlap between two consecutive runs, i.e. we have
|
||||
# always a cron session running.
|
||||
crontab -u test - <<EOF
|
||||
RANDOM_DELAY=0
|
||||
* * * * * /bin/sleep 65
|
||||
EOF
|
||||
# Let's wait (at most one interval plus 10s to accomodate for slow machines) for at least one session of test user
|
||||
timeout 70s bash -c "while true; do loginctl --no-legend list-sessions | awk '{ print \$3 }' | grep -q test && break || sleep 1 ; done"
|
||||
}
|
||||
|
||||
teardown_cron() (
|
||||
set +ex
|
||||
pkill -9 -u "$(id -u test)"
|
||||
pkill crond
|
||||
crontab -r -u test
|
||||
userdel -r test
|
||||
)
|
||||
|
||||
test_no_user_instance_for_cron() {
|
||||
if ! command -v crond || ! command -v crontab ; then
|
||||
echo >&2 "Skipping test for background cron sessions because cron is missing."
|
||||
return
|
||||
fi
|
||||
|
||||
trap teardown_cron EXIT
|
||||
setup_cron
|
||||
|
||||
if [[ $(loginctl --no-legend list-sessions | grep -c test) -lt 1 ]]; then
|
||||
echo >&2 '"test" user should have at least one session'
|
||||
loginctl list-sessions
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check that all sessions of test user have class=background and no user instance was started
|
||||
# for the test user.
|
||||
while read -r s _; do
|
||||
local class
|
||||
|
||||
class=$(loginctl --property Class --value show-session "$s")
|
||||
if [[ "$class" != "background" ]]; then
|
||||
echo >&2 "Session has incorrect class, expected \"background\", got \"$class\"."
|
||||
return 1
|
||||
fi
|
||||
done < <(loginctl --no-legend list-sessions | grep test)
|
||||
|
||||
state=$(systemctl --property ActiveState --value show user@"$(id -u test)".service)
|
||||
if [[ "$state" != "inactive" ]]; then
|
||||
echo >&2 "User instance state is unexpected, expected \"inactive\", got \"$state\""
|
||||
return 1
|
||||
fi
|
||||
|
||||
state=$(systemctl --property SubState --value show user@"$(id -u test)".service)
|
||||
if [[ "$state" != "dead" ]]; then
|
||||
echo >&2 "User instance state is unexpected, expected \"dead\", got \"$state\""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
: >/failed
|
||||
|
||||
test_enable_debug
|
||||
@@ -452,6 +515,7 @@ test_suspend_on_lid
|
||||
test_shutdown
|
||||
test_session
|
||||
test_lock_idle_action
|
||||
test_no_user_instance_for_cron
|
||||
|
||||
touch /testok
|
||||
rm /failed
|
||||
|
||||
Reference in New Issue
Block a user