]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-55.sh
resolved: reply using unicast mDNS when appropriate
[thirdparty/systemd.git] / test / units / testsuite-55.sh
1 #!/usr/bin/env bash
2 set -ex
3 set -o pipefail
4
5 systemd-analyze log-level debug
6 systemd-analyze log-target console
7
8 # Loose checks to ensure the environment has the necessary features for systemd-oomd
9 [[ -e /proc/pressure ]] || echo "no PSI" >> /skipped
10 cgroup_type=$(stat -fc %T /sys/fs/cgroup/)
11 if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]; then
12 echo "no cgroup2" >> /skipped
13 fi
14 if [ ! -f /usr/lib/systemd/systemd-oomd ] && [ ! -f /lib/systemd/systemd-oomd ]; then
15 echo "no oomd" >> /skipped
16 fi
17 [[ -e /skipped ]] && exit 0 || true
18
19 rm -rf /etc/systemd/system/testsuite-55-testbloat.service.d
20
21 echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf
22
23 systemctl start testsuite-55-testchill.service
24 systemctl start testsuite-55-testbloat.service
25
26 # Verify systemd-oomd is monitoring the expected units
27 oomctl | grep "/testsuite-55-workload.slice"
28 oomctl | grep "1.00%"
29 oomctl | grep "Default Memory Pressure Duration: 5s"
30
31 # systemd-oomd watches for elevated pressure for 5 seconds before acting.
32 # It can take time to build up pressure so either wait 2 minutes or for the service to fail.
33 timeout=$(date -ud "2 minutes" +%s)
34 while [[ $(date -u +%s) -le $timeout ]]; do
35 if ! systemctl status testsuite-55-testbloat.service; then
36 break
37 fi
38 sleep 5
39 done
40
41 # testbloat should be killed and testchill should be fine
42 if systemctl status testsuite-55-testbloat.service; then exit 42; fi
43 if ! systemctl status testsuite-55-testchill.service; then exit 24; fi
44
45 # only run this portion of the test if we can set xattrs
46 if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then
47 sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down
48
49 mkdir -p /etc/systemd/system/testsuite-55-testbloat.service.d/
50 echo "[Service]" > /etc/systemd/system/testsuite-55-testbloat.service.d/override.conf
51 echo "ManagedOOMPreference=avoid" >> /etc/systemd/system/testsuite-55-testbloat.service.d/override.conf
52
53 systemctl daemon-reload
54 systemctl start testsuite-55-testchill.service
55 systemctl start testsuite-55-testmunch.service
56 systemctl start testsuite-55-testbloat.service
57
58 timeout=$(date -ud "2 minutes" +%s)
59 while [[ $(date -u +%s) -le $timeout ]]; do
60 if ! systemctl status testsuite-55-testmunch.service; then
61 break
62 fi
63 sleep 5
64 done
65
66 # testmunch should be killed since testbloat had the avoid xattr on it
67 if ! systemctl status testsuite-55-testbloat.service; then exit 25; fi
68 if systemctl status testsuite-55-testmunch.service; then exit 43; fi
69 if ! systemctl status testsuite-55-testchill.service; then exit 24; fi
70 fi
71
72 systemd-analyze log-level info
73
74 echo OK > /testok
75
76 exit 0