From: Yu Watanabe Date: Wed, 16 Oct 2024 06:04:07 +0000 (+0900) Subject: TEST-55-OOMD: split into small testcases X-Git-Tag: v257-rc1~207^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bba058076cf4ce91fd470841d5ced47c8d32d6a;p=thirdparty%2Fsystemd.git TEST-55-OOMD: split into small testcases Then, we can run each small test cases separately. --- diff --git a/test/units/TEST-55-OOMD.sh b/test/units/TEST-55-OOMD.sh index 2b003c9f73d..43a9919165a 100755 --- a/test/units/TEST-55-OOMD.sh +++ b/test/units/TEST-55-OOMD.sh @@ -3,8 +3,10 @@ set -eux set -o pipefail +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh # shellcheck source=test/units/util.sh - . "$(dirname "$0")"/util.sh +. "$(dirname "$0")"/util.sh systemd-analyze log-level debug @@ -93,62 +95,52 @@ else systemd-run -t -p MemoryMax=10M -p MemorySwapMax=0 -p MemoryZSwapMax=0 /bin/true fi -systemctl start TEST-55-OOMD-testchill.service -systemctl start TEST-55-OOMD-testbloat.service +test_basic() { + systemctl "$@" start TEST-55-OOMD-testchill.service + systemctl "$@" start TEST-55-OOMD-testbloat.service -# Verify systemd-oomd is monitoring the expected units -timeout 1m bash -xec 'until oomctl | grep "/TEST-55-OOMD-workload.slice"; do sleep 1; done' -oomctl | grep "/TEST-55-OOMD-workload.slice" -oomctl | grep "20.00%" + # Verify systemd-oomd is monitoring the expected units. + timeout 1m bash -xec 'until oomctl | grep "/TEST-55-OOMD-workload.slice"; do sleep 1; done' + oomctl | grep "/TEST-55-OOMD-workload.slice" + oomctl | grep "20.00%" -systemctl status TEST-55-OOMD-testchill.service + systemctl "$@" status TEST-55-OOMD-testchill.service -# systemd-oomd watches for elevated pressure for 2 seconds before acting. -# It can take time to build up pressure so either wait 2 minutes or for the service to fail. -for _ in {0..59}; do - if ! systemctl status TEST-55-OOMD-testbloat.service; then - break - fi - oomctl - sleep 2 -done + # systemd-oomd watches for elevated pressure for 2 seconds before acting. + # It can take time to build up pressure so either wait 2 minutes or for the service to fail. + for _ in {0..59}; do + if ! systemctl "$@" status TEST-55-OOMD-testbloat.service; then + break + fi + oomctl + sleep 2 + done -# testbloat should be killed and testchill should be fine -if systemctl status TEST-55-OOMD-testbloat.service; then exit 42; fi -if ! systemctl status TEST-55-OOMD-testchill.service; then exit 24; fi + # testbloat should be killed and testchill should be fine + if systemctl "$@" status TEST-55-OOMD-testbloat.service; then exit 42; fi + if ! systemctl "$@" status TEST-55-OOMD-testchill.service; then exit 24; fi +} -# Make sure we also work correctly on user units. -loginctl enable-linger testuser +testcase_basic_system() { + test_basic +} -systemctl start --machine "testuser@.host" --user TEST-55-OOMD-testchill.service -systemctl start --machine "testuser@.host" --user TEST-55-OOMD-testbloat.service +testcase_basic_user() { + # Make sure we also work correctly on user units. + loginctl enable-linger testuser -# Verify systemd-oomd is monitoring the expected units -# Try to avoid racing the oomctl output check by checking in a loop with a timeout -timeout 1m bash -xec 'until oomctl | grep "/TEST-55-OOMD-workload.slice"; do sleep 1; done' -oomctl | grep -E "/user.slice.*/TEST-55-OOMD-workload.slice" -oomctl | grep "20.00%" + test_basic --machine "testuser@.host" --user -systemctl --machine "testuser@.host" --user status TEST-55-OOMD-testchill.service + loginctl disable-linger testuser +} -# systemd-oomd watches for elevated pressure for 2 seconds before acting. -# It can take time to build up pressure so either wait 2 minutes or for the service to fail. -for _ in {0..59}; do - if ! systemctl --machine "testuser@.host" --user status TEST-55-OOMD-testbloat.service; then - break +testcase_preference_avoid() { + # only run this portion of the test if we can set xattrs + if ! cgroupfs_supports_user_xattrs; then + echo "cgroup does not support user xattrs, skipping test for ManagedOOMPreference=avoid" + return 0 fi - oomctl - sleep 2 -done - -# testbloat should be killed and testchill should be fine -if systemctl --machine "testuser@.host" --user status TEST-55-OOMD-testbloat.service; then exit 42; fi -if ! systemctl --machine "testuser@.host" --user status TEST-55-OOMD-testchill.service; then exit 24; fi - -loginctl disable-linger testuser -# only run this portion of the test if we can set xattrs -if cgroupfs_supports_user_xattrs; then sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down mkdir -p /run/systemd/system/TEST-55-OOMD-testbloat.service.d/ @@ -174,7 +166,9 @@ EOF if ! systemctl status TEST-55-OOMD-testbloat.service; then exit 25; fi if systemctl status TEST-55-OOMD-testmunch.service; then exit 43; fi if ! systemctl status TEST-55-OOMD-testchill.service; then exit 24; fi -fi +} + +run_testcases systemd-analyze log-level info