2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
7 # Let's run this test only if the "memory.oom.group" cgroupfs attribute
8 # exists. This test is a bit too strict, since the "memory.events"/"oom_kill"
9 # logic has been around since a longer time than "memory.oom.group", but it's
10 # an easier thing to test for, and also: let's not get confused by older
11 # kernels where the concept was still new.
13 if test -f /sys
/fs
/cgroup
/system.slice
/testsuite.service
/memory.oom.group
; then
15 systemd-analyze log-level debug
16 systemd-analyze log-target console
18 # Run a service that is guaranteed to be the first candidate for OOM killing
19 systemd-run
--unit=oomtest.service
-p Type
=exec -p OOMScoreAdjust
=1000 -p OOMPolicy
=stop
-p MemoryAccounting
=yes /bin
/sleep infinity
21 # Trigger an OOM killer run
22 echo 1 > /proc
/sys
/kernel
/sysrq
23 echo f
> /proc
/sysrq-trigger
26 STATE
=`systemctl show -p ActiveState --value oomtest.service`
27 [ "$STATE" = "failed" ] && break
31 RESULT
=`systemctl show -p Result --value oomtest.service`
32 test "$RESULT" = "oom-kill"
34 systemd-analyze log-level info