2020-08-14 11:20:43 +03:00
#!/usr/bin/env bash
set -ex
set -o pipefail
systemd-analyze log-level debug
systemd-analyze log-target console
# Loose checks to ensure the environment has the necessary features for systemd-oomd
[ [ -e /proc/pressure ] ] || echo "no PSI" >> /skipped
cgroup_type = $( stat -fc %T /sys/fs/cgroup/)
if [ [ " $cgroup_type " != *"cgroup2" * ] ] && [ [ " $cgroup_type " != *"0x63677270" * ] ] ; then
echo "no cgroup2" >> /skipped
fi
[ [ -e /skipped ] ] && exit 0 || true
2021-01-28 13:31:44 +03:00
rm -rf /etc/systemd/system/testsuite-56-testbloat.service.d
2021-01-24 11:16:19 +03:00
echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf
2020-10-24 01:47:07 +03:00
systemctl start testsuite-56-testchill.service
2021-01-24 12:34:23 +03:00
systemctl start testsuite-56-testbloat.service
2020-08-14 11:20:43 +03:00
# Verify systemd-oomd is monitoring the expected units
2020-10-24 01:47:07 +03:00
oomctl | grep "/testsuite-56-workload.slice"
2021-02-03 01:16:03 +03:00
oomctl | grep "1.00%"
2021-01-24 11:16:19 +03:00
oomctl | grep "Default Memory Pressure Duration: 5s"
2020-08-14 11:20:43 +03:00
2021-02-09 12:47:34 +03:00
# systemd-oomd watches for elevated pressure for 5 seconds before acting.
# It can take time to build up pressure so either wait 2 minutes or for the service to fail.
timeout = $( date -ud "2 minutes" +%s)
2020-08-14 11:20:43 +03:00
while [ [ $( date -u +%s) -le $timeout ] ] ; do
2020-10-24 01:47:07 +03:00
if ! systemctl status testsuite-56-testbloat.service; then
2020-08-14 11:20:43 +03:00
break
fi
2021-02-09 12:47:34 +03:00
sleep 5
2020-08-14 11:20:43 +03:00
done
# testbloat should be killed and testchill should be fine
2020-10-24 01:47:07 +03:00
if systemctl status testsuite-56-testbloat.service; then exit 42; fi
if ! systemctl status testsuite-56-testchill.service; then exit 24; fi
2020-08-14 11:20:43 +03:00
2021-02-09 12:47:34 +03:00
# only run this portion of the test if we can set xattrs
if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then
sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down
2021-01-28 13:31:44 +03:00
mkdir -p /etc/systemd/system/testsuite-56-testbloat.service.d/
echo "[Service]" > /etc/systemd/system/testsuite-56-testbloat.service.d/override.conf
echo "ManagedOOMPreference=avoid" >> /etc/systemd/system/testsuite-56-testbloat.service.d/override.conf
systemctl daemon-reload
2021-02-09 12:47:34 +03:00
systemctl start testsuite-56-testchill.service
systemctl start testsuite-56-testmunch.service
systemctl start testsuite-56-testbloat.service
timeout = $( date -ud "2 minutes" +%s)
while [ [ $( date -u +%s) -le $timeout ] ] ; do
if ! systemctl status testsuite-56-testmunch.service; then
break
fi
sleep 5
done
# testmunch should be killed since testbloat had the avoid xattr on it
if ! systemctl status testsuite-56-testbloat.service; then exit 25; fi
if systemctl status testsuite-56-testmunch.service; then exit 43; fi
if ! systemctl status testsuite-56-testchill.service; then exit 24; fi
fi
2020-08-14 11:20:43 +03:00
systemd-analyze log-level info
echo OK > /testok
exit 0