diff --git a/test/units/TEST-55-OOMD.sh b/test/units/TEST-55-OOMD.sh index 90d40069f7..6010d67225 100755 --- a/test/units/TEST-55-OOMD.sh +++ b/test/units/TEST-55-OOMD.sh @@ -301,6 +301,7 @@ testcase_reload() { testcase_kernel_oom() { cat >/tmp/script.sh <<"EOF" #!/usr/bin/env bash +set -x choom --adjust '+1000' -- bash -c 'echo f >/proc/sysrq-trigger && exec sleep infinity' choom --adjust '+1000' -p $$ echo f >/proc/sysrq-trigger @@ -324,12 +325,22 @@ EOF cat >/tmp/script.sh <<"EOF" #!/usr/bin/env bash +set -x echo '+memory' >/sys/fs/cgroup/system.slice/oom-kill.service/cgroup.subtree_control mkdir /sys/fs/cgroup/system.slice/oom-kill.service/sub echo 1 >/sys/fs/cgroup/system.slice/oom-kill.service/sub/memory.oom.group -echo $$ >/sys/fs/cgroup/system.slice/oom-kill.service/sub/cgroup.procs -choom --adjust '+1000' -p $$ -echo f >/proc/sysrq-trigger + +# Start a child process in the subcgroup that will trigger OOM and be killed but keep the main process +# outside the subcgroup to avoid a race condition where the kernel SIGKILLs the main process before systemd +# can process the OOM notification. With the main process still alive, systemd should have time to receive +# the OOM event and enter the 'oom-kill' state before the service exits. +( + echo $BASHPID >/sys/fs/cgroup/system.slice/oom-kill.service/sub/cgroup.procs + choom --adjust '+1000' -p $BASHPID + echo f >/proc/sysrq-trigger + exec sleep infinity +) & +wait $! || : exec sleep infinity EOF chmod +x /tmp/script.sh