]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-55-OOMD: use 'stress' to create high pressure
authorLuca Boccassi <bluca@debian.org>
Fri, 16 Jun 2023 23:07:32 +0000 (00:07 +0100)
committerLuca Boccassi <bluca@debian.org>
Sat, 24 Jun 2023 10:48:51 +0000 (11:48 +0100)
The test fails on my machine, running Debian stable, because
testsuite-55-testbloat.service just swaps and never goes over the
limit, so it's not killed. Use 'stress' instead which seems to be
able to overwhelm the swap too.

test/TEST-55-OOMD/test.sh
test/units/testsuite-55-slowgrowth.sh [deleted file]
test/units/testsuite-55-testbloat.service
test/units/testsuite-55-testmunch.service
test/units/testsuite-55.sh

index c6dc92c050fd401d57a6ff592b76fe80165c7693..723e80d115850e0c84de40e0dffffc10ca54ad74 100755 (executable)
@@ -14,6 +14,8 @@ test_append_files() {
         mkswap "${LOOPDEV:?}p2"
         image_install swapon swapoff
 
+        inst_binary stress
+
         cat >>"${initdir:?}/etc/fstab" <<EOF
 UUID=$(blkid -o value -s UUID "${LOOPDEV}p2")    none    swap    defaults 0 0
 EOF
diff --git a/test/units/testsuite-55-slowgrowth.sh b/test/units/testsuite-55-slowgrowth.sh
deleted file mode 100755 (executable)
index df1ea48..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-# Don't use set -x here, since it generates a lot of output and slows
-# the script down, causing unexpected test fails.
-set -eu
-set -o pipefail
-
-PAGE_SIZE=$(getconf PAGE_SIZE)
-BLOAT_ITERATION_TARGET=$((100 << 20)) # 100 MB
-BLOAT_HOLDER=()
-PID="$$"
-
-function bloat {
-        local set_size mem_usage target_mem_size
-
-        set_size=$(cut -d " " -f2 "/proc/$PID/statm")
-        mem_usage=$((set_size * PAGE_SIZE))
-        target_mem_size=$((mem_usage + $1))
-
-        BLOAT_HOLDER=()
-        while [[ "$mem_usage" -lt "$target_mem_size" ]]; do
-                echo "target $target_mem_size"
-                echo "mem usage $mem_usage"
-                BLOAT_HOLDER+=("$(printf "=%0.s" {1..1000000})")
-                set_size=$(cut -d " " -f2 "/proc/$PID/statm")
-                mem_usage=$((set_size * PAGE_SIZE))
-        done
-}
-
-function run {
-        local arr=()
-
-        while :; do
-                bloat "$BLOAT_ITERATION_TARGET"
-                arr+=("${BLOAT_HOLDER[@]}")
-                sleep 1
-        done
-}
-
-run
index 8ec535979df75510ced12ba73a77060aa8b37664..6c8e3c93aca6bb34f8503172c028135cd7ce9afb 100644 (file)
@@ -3,8 +3,8 @@
 Description=Create a lot of memory pressure
 
 [Service]
-# A VERY small memory.high will cause the script (trying to use a lot of memory)
+# A VERY small memory.high will cause the 'stress' (trying to use a lot of memory)
 # to throttle and be put under heavy pressure.
-MemoryHigh=5M
+MemoryHigh=3M
 Slice=testsuite-55-workload.slice
-ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-55-slowgrowth.sh
+ExecStart=stress --timeout 3m --vm 10 --vm-bytes 200M --vm-keep --vm-stride 1
index 8820dc06782581f0325a4b57b196c49961426bde..373005979797412b2b163d8b39f2a068a1ccb9a4 100644 (file)
@@ -3,6 +3,6 @@
 Description=Create some memory pressure
 
 [Service]
-MemoryHigh=6M
+MemoryHigh=12M
 Slice=testsuite-55-workload.slice
-ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-55-slowgrowth.sh
+ExecStart=stress --timeout 3m --vm 10 --vm-bytes 200M --vm-keep --vm-stride 1
index 1433e79c5b9b0b9ce2ea7de1294ada5d2fa83e28..85ebb76732e61d0bdfbc5ab9406ac9668723f2bd 100755 (executable)
@@ -89,6 +89,7 @@ while [[ $(date -u +%s) -le $timeout ]]; do
     if ! systemctl status testsuite-55-testbloat.service; then
         break
     fi
+    oomctl
     sleep 2
 done
 
@@ -126,6 +127,7 @@ while [[ $(date -u +%s) -le $timeout ]]; do
     if ! systemctl --machine "testuser@.host" --user status testsuite-55-testbloat.service; then
         break
     fi
+    oomctl
     sleep 2
 done
 
@@ -153,6 +155,7 @@ EOF
         if ! systemctl status testsuite-55-testmunch.service; then
             break
         fi
+        oomctl
         sleep 2
     done