summaryrefslogtreecommitdiffstats
path: root/test/units/TEST-79-MEMPRESS.sh
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-05-11 19:17:13 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-05-14 12:43:28 +0200
commit7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5 (patch)
tree9464b421b4486e0af21b49706467a1f8053eda8f /test/units/TEST-79-MEMPRESS.sh
parenttest: Rework integration test definitions (diff)
downloadsystemd-7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5.tar.xz
systemd-7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5.zip
test: Rename testsuite-XX units to match test name
Having these named differently than the test itself mostly creates unecessary confusion and makes writing logic against the tests harder so let's rename the testsuite-xx units and scripts to just use the test name itself.
Diffstat (limited to 'test/units/TEST-79-MEMPRESS.sh')
-rwxr-xr-xtest/units/TEST-79-MEMPRESS.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/units/TEST-79-MEMPRESS.sh b/test/units/TEST-79-MEMPRESS.sh
new file mode 100755
index 0000000000..4ce73d4c29
--- /dev/null
+++ b/test/units/TEST-79-MEMPRESS.sh
@@ -0,0 +1,58 @@
+#!/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 TEST-79-MEMPRESS.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="/tmp/mempress-$RANDOM.sh"
+
+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 2000000\x00" | base64)"
+
+test "$EXPECTED" = "$MEMORY_PRESSURE_WRITE"
+
+EOF
+
+chmod +x "$SCRIPT"
+
+systemd-run -u "$UNIT" -p Type=exec -p ProtectControlGroups=1 -p DynamicUser=1 -p MemoryPressureWatch=on -p MemoryPressureThresholdSec=123ms -p BindPaths=$SCRIPT --wait "$SCRIPT"
+
+rm "$SCRIPT"
+
+systemd-analyze log-level info
+
+touch /testok