]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-31-OOMPOLICY/testsuite.sh
travis: use variable to avoid one call
[thirdparty/systemd.git] / test / TEST-31-OOMPOLICY / testsuite.sh
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 set -ex
5 set -o pipefail
6
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.
12
13 if test -f /sys/fs/cgroup/system.slice/testsuite.service/memory.oom.group ; then
14
15 systemd-analyze log-level debug
16 systemd-analyze log-target console
17
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
20
21 # Trigger an OOM killer run
22 echo 1 > /proc/sys/kernel/sysrq
23 echo f > /proc/sysrq-trigger
24
25 while : ; do
26 STATE=`systemctl show -p ActiveState --value oomtest.service`
27 [ "$STATE" = "failed" ] && break
28 sleep .5
29 done
30
31 RESULT=`systemctl show -p Result --value oomtest.service`
32 test "$RESULT" = "oom-kill"
33
34 systemd-analyze log-level info
35 fi
36
37 echo OK > /testok
38
39 exit 0