mirror of
https://github.com/systemd/systemd
synced 2024-10-04 15:21:01 +00:00
test: add test for the new memory pressure unit file settings, and that they work
This commit is contained in:
parent
9d03637404
commit
3b7101183c
1
test/TEST-79-MEMPRESS/Makefile
Symbolic link
1
test/TEST-79-MEMPRESS/Makefile
Symbolic link
|
@ -0,0 +1 @@
|
|||
../TEST-01-BASIC/Makefile
|
16
test/TEST-79-MEMPRESS/test.sh
Executable file
16
test/TEST-79-MEMPRESS/test.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
set -e
|
||||
|
||||
TEST_DESCRIPTION="Test Memory Pressure handling"
|
||||
# Ignore gcov complaints caused by DynamicUser=true
|
||||
IGNORE_MISSING_COVERAGE=yes
|
||||
|
||||
# shellcheck source=test/test-functions
|
||||
. "$TEST_BASE_DIR/test-functions"
|
||||
|
||||
test_append_files() {
|
||||
image_install base64
|
||||
}
|
||||
|
||||
do_test "$@"
|
8
test/units/testsuite-79.service
Normal file
8
test/units/testsuite-79.service
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
[Unit]
|
||||
Description=TEST-79-MEMPRESS
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
|
||||
MemoryAccounting=1
|
63
test/units/testsuite-79.sh
Executable file
63
test/units/testsuite-79.sh
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
set -ex
|
||||
set -o pipefail
|
||||
|
||||
# We not just test if the file exists, but try to read from it, since if
|
||||
# CONFIG_PSI_DEFAULT_DISABLED is set in the kernel the file will exist and can
|
||||
# be opened, but any read()s will fail with EOPNOTSUPP, which we want to
|
||||
# detect.
|
||||
if ! cat /proc/pressure/memory >/dev/null ; then
|
||||
echo "kernel too old, has no PSI." >&2
|
||||
echo OK >/testok
|
||||
exit 0
|
||||
fi
|
||||
|
||||
systemd-analyze log-level debug
|
||||
|
||||
CGROUP=/sys/fs/cgroup/"$(systemctl show testsuite-79.service -P ControlGroup)"
|
||||
test -d "$CGROUP"
|
||||
|
||||
if ! test -f "$CGROUP"/memory.pressure ; then
|
||||
echo "No memory accounting/PSI delegated via cgroup, can't test." >&2
|
||||
echo OK >/testok
|
||||
exit 0
|
||||
fi
|
||||
|
||||
UNIT="test-mempress-$RANDOM.service"
|
||||
SCRIPT="/run/bin/mempress-$RANDOM.sh"
|
||||
|
||||
mkdir -p "/run/bin"
|
||||
|
||||
cat >"$SCRIPT" <<'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
export
|
||||
id
|
||||
|
||||
test -n "$MEMORY_PRESSURE_WATCH"
|
||||
test "$MEMORY_PRESSURE_WATCH" != /dev/null
|
||||
test -w "$MEMORY_PRESSURE_WATCH"
|
||||
|
||||
ls -al "$MEMORY_PRESSURE_WATCH"
|
||||
|
||||
EXPECTED="$(echo -n -e "some 123000 1000000\x00" | base64)"
|
||||
|
||||
test "$EXPECTED" = "$MEMORY_PRESSURE_WRITE"
|
||||
|
||||
EOF
|
||||
|
||||
chmod +x "$SCRIPT"
|
||||
|
||||
systemd-run -u "$UNIT" -p Type=exec -p DynamicUser=1 -p MemoryPressureWatch=on -p MemoryPressureThresholdSec=123ms --wait "$SCRIPT"
|
||||
|
||||
rm "$SCRIPT"
|
||||
|
||||
rmdir /run/bin ||:
|
||||
|
||||
systemd-analyze log-level info
|
||||
echo OK >/testok
|
||||
|
||||
exit 0
|
Loading…
Reference in a new issue