test: configure swap for TEST-55-OOMD

oomd works way better with swap, so let's make the test less flaky by
configuring a swap device for it. This also allows us to drop the ugly
`cat`s from the load-generating script.
This commit is contained in:
Frantisek Sumsal 2021-04-22 16:26:25 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent 3a1e9d8083
commit 6f47e45c67
2 changed files with 15 additions and 4 deletions

View file

@ -2,10 +2,23 @@
set -e
TEST_DESCRIPTION="systemd-oomd Memory Pressure Test"
IMAGE_NAME="oomd"
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
test_append_files() {
# Create a swap device
(
mkswap "${LOOPDEV:?}p2"
dracut_install swapon swapoff
cat >>"${initdir:?}/etc/fstab" <<EOF
UUID=$(blkid -o value -s UUID "${LOOPDEV}p2") none swap defaults 0 0
EOF
)
}
check_result_nspawn() {
local workspace="${1:?}"
local ret=1

View file

@ -12,9 +12,7 @@ PID="$$"
function bloat {
local set_size mem_usage target_mem_size
# Following `| cat` weirdness is intentional to generate some reclaim
# activity in case there's no swap available.
set_size=$(cut -d " " -f2 "/proc/$PID/statm" | cat)
set_size=$(cut -d " " -f2 "/proc/$PID/statm")
mem_usage=$((set_size * PAGE_SIZE))
target_mem_size=$((mem_usage + $1))
@ -23,7 +21,7 @@ function bloat {
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" | cat)
set_size=$(cut -d " " -f2 "/proc/$PID/statm")
mem_usage=$((set_size * PAGE_SIZE))
done
}