]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-32.sh
2393601a007ff8932895d83351aa21b6a652483e
[thirdparty/systemd.git] / test / units / testsuite-32.sh
1 #!/usr/bin/env bash
2 set -eux
3 set -o pipefail
4
5 # Let's run this test only if the "memory.oom.group" cgroupfs attribute
6 # exists. This test is a bit too strict, since the "memory.events"/"oom_kill"
7 # logic has been around since a longer time than "memory.oom.group", but it's
8 # an easier thing to test for, and also: let's not get confused by older
9 # kernels where the concept was still new.
10
11 if test -f /sys/fs/cgroup/system.slice/testsuite-32.service/memory.oom.group; then
12 systemd-analyze log-level debug
13 systemd-analyze log-target console
14
15 # Run a service that is guaranteed to be the first candidate for OOM killing
16 systemd-run --unit=oomtest.service \
17 -p Type=exec -p OOMScoreAdjust=1000 -p OOMPolicy=stop -p MemoryAccounting=yes \
18 sleep infinity
19
20 # Trigger an OOM killer run
21 echo 1 >/proc/sys/kernel/sysrq
22 echo f >/proc/sysrq-trigger
23
24 while : ; do
25 STATE="$(systemctl show -P ActiveState oomtest.service)"
26 [ "$STATE" = "failed" ] && break
27 sleep .5
28 done
29
30 RESULT="$(systemctl show -P Result oomtest.service)"
31 test "$RESULT" = "oom-kill"
32
33 systemd-analyze log-level info
34 fi
35
36 echo OK >/testok
37
38 exit 0