diff --git a/test/test-functions b/test/test-functions index 19559fc071f..974fa4384be 100644 --- a/test/test-functions +++ b/test/test-functions @@ -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 diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh index aa1a6af2fb7..98283cad25b 100755 --- a/test/units/testsuite-35.sh +++ b/test/units/testsuite-35.sh @@ -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 - <&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