]>
Commit | Line | Data |
---|---|---|
ff12a795 | 1 | #!/usr/bin/env bash |
36869f33 LP |
2 | set -ex |
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 | ||
c8937bed | 11 | if test -f /sys/fs/cgroup/system.slice/testsuite-32.service/memory.oom.group; then |
36869f33 LP |
12 | |
13 | systemd-analyze log-level debug | |
14 | systemd-analyze log-target console | |
15 | ||
16 | # Run a service that is guaranteed to be the first candidate for OOM killing | |
c8937bed ZJS |
17 | systemd-run --unit=oomtest.service \ |
18 | -p Type=exec -p OOMScoreAdjust=1000 -p OOMPolicy=stop -p MemoryAccounting=yes \ | |
19 | sleep infinity | |
36869f33 LP |
20 | |
21 | # Trigger an OOM killer run | |
c8937bed ZJS |
22 | echo 1 >/proc/sys/kernel/sysrq |
23 | echo f >/proc/sysrq-trigger | |
36869f33 LP |
24 | |
25 | while : ; do | |
5522e628 | 26 | STATE=`systemctl show -P ActiveState oomtest.service` |
36869f33 LP |
27 | [ "$STATE" = "failed" ] && break |
28 | sleep .5 | |
29 | done | |
30 | ||
5522e628 | 31 | RESULT=`systemctl show -P Result oomtest.service` |
36869f33 LP |
32 | test "$RESULT" = "oom-kill" |
33 | ||
34 | systemd-analyze log-level info | |
35 | fi | |
36 | ||
c8937bed | 37 | echo OK >/testok |
36869f33 LP |
38 | |
39 | exit 0 |