2024-02-23 17:24:26 +01:00
|
|
|
From 10d8f042c0bf685d41b95d7151214999a8ff68c2 Mon Sep 17 00:00:00 2001
|
2024-01-23 14:52:53 +01:00
|
|
|
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
|
2024-02-23 17:24:26 +01:00
|
|
|
Date: Wed, 9 Aug 2023 22:43:31 +0200
|
|
|
|
Subject: [PATCH 5008/5010] test: Add effective cgroup limits testing
|
2024-01-23 14:52:53 +01:00
|
|
|
|
|
|
|
(cherry picked from commit ce35bb95c7b6fe9a48d2b8628bd690279b17fffa)
|
|
|
|
|
|
|
|
[mkoutny: fixes jsc#PED-5659]
|
|
|
|
---
|
|
|
|
test/units/testsuite-05.effective-limit.sh | 68 ++++++++++++++++++++++
|
|
|
|
test/units/util.sh | 9 +++
|
|
|
|
2 files changed, 77 insertions(+)
|
|
|
|
create mode 100755 test/units/testsuite-05.effective-limit.sh
|
|
|
|
|
|
|
|
diff --git a/test/units/testsuite-05.effective-limit.sh b/test/units/testsuite-05.effective-limit.sh
|
|
|
|
new file mode 100755
|
|
|
|
index 0000000000..3ff8e83140
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/test/units/testsuite-05.effective-limit.sh
|
|
|
|
@@ -0,0 +1,68 @@
|
|
|
|
+#!/usr/bin/env bash
|
|
|
|
+# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
+set -eux
|
|
|
|
+set -o pipefail
|
|
|
|
+
|
|
|
|
+# shellcheck source=test/units/util.sh
|
|
|
|
+. "$(dirname "$0")"/util.sh
|
|
|
|
+
|
|
|
|
+pre=test05
|
|
|
|
+cat >/run/systemd/system/"$pre"alpha.slice <<EOF
|
|
|
|
+[Slice]
|
|
|
|
+MemoryMax=40M
|
|
|
|
+MemoryHigh=40M
|
|
|
|
+TasksMax=400
|
|
|
|
+EOF
|
|
|
|
+
|
|
|
|
+cat >/run/systemd/system/"$pre"alpha-beta.slice <<EOF
|
|
|
|
+[Slice]
|
|
|
|
+MemoryMax=10M
|
|
|
|
+MemoryHigh=10M
|
|
|
|
+TasksMax=100
|
|
|
|
+EOF
|
|
|
|
+
|
|
|
|
+cat >/run/systemd/system/"$pre"alpha-beta-gamma.slice <<EOF
|
|
|
|
+[Slice]
|
|
|
|
+MemoryMax=20M
|
|
|
|
+MemoryHigh=20M
|
|
|
|
+TasksMax=200
|
|
|
|
+EOF
|
|
|
|
+
|
|
|
|
+systemctl daemon-reload
|
|
|
|
+
|
|
|
|
+srv=probe.service
|
|
|
|
+slc0="$pre"alpha.slice
|
|
|
|
+slc="$pre"alpha-beta-gamma.slice
|
|
|
|
+
|
|
|
|
+systemd-run --unit "$srv" --slice "$slc" \
|
|
|
|
+ -p MemoryMax=5M \
|
|
|
|
+ -p MemoryHigh=5M \
|
|
|
|
+ -p TasksMax=50 \
|
|
|
|
+ sleep inf
|
|
|
|
+
|
|
|
|
+# Compare with inequality because test can run in a constrained container
|
|
|
|
+assert_le "$(systemctl show -P EffectiveMemoryMax "$srv")" "5242880"
|
|
|
|
+assert_le "$(systemctl show -P EffectiveMemoryHigh "$srv")" "5242880"
|
|
|
|
+assert_le "$(systemctl show -P EffectiveTasksMax "$srv")" "50"
|
|
|
|
+
|
|
|
|
+systemctl stop "$srv"
|
|
|
|
+
|
|
|
|
+systemd-run --unit "$srv" --slice "$slc" \
|
|
|
|
+ sleep inf
|
|
|
|
+
|
|
|
|
+assert_le "$(systemctl show -P EffectiveMemoryMax "$srv")" "10485760"
|
|
|
|
+assert_le "$(systemctl show -P EffectiveMemoryHigh "$srv")" "10485760"
|
|
|
|
+assert_le "$(systemctl show -P EffectiveTasksMax "$srv")" "100"
|
|
|
|
+
|
|
|
|
+systemctl set-property "$slc0" \
|
|
|
|
+ MemoryMax=5M \
|
|
|
|
+ MemoryHigh=5M \
|
|
|
|
+ TasksMax=50
|
|
|
|
+
|
|
|
|
+assert_le "$(systemctl show -P EffectiveMemoryMax "$srv")" "5242880"
|
|
|
|
+assert_le "$(systemctl show -P EffectiveMemoryHigh "$srv")" "5242880"
|
|
|
|
+assert_le "$(systemctl show -P EffectiveTasksMax "$srv")" "50"
|
|
|
|
+
|
|
|
|
+systemctl stop "$srv"
|
|
|
|
+
|
|
|
|
+rm -f /run/systemd/system/"$pre"* || :
|
|
|
|
diff --git a/test/units/util.sh b/test/units/util.sh
|
2024-02-23 17:24:26 +01:00
|
|
|
index b5ed73237c..567cda2845 100755
|
2024-01-23 14:52:53 +01:00
|
|
|
--- a/test/units/util.sh
|
|
|
|
+++ b/test/units/util.sh
|
2024-02-23 17:24:26 +01:00
|
|
|
@@ -28,6 +28,15 @@ assert_eq() {(
|
2024-01-23 14:52:53 +01:00
|
|
|
fi
|
|
|
|
)}
|
|
|
|
|
|
|
|
+assert_le() {(
|
|
|
|
+ set +ex
|
|
|
|
+
|
|
|
|
+ if [[ "${1:?}" -gt "${2:?}" ]]; then
|
|
|
|
+ echo "FAIL: '$1' > '$2'" >&2
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
|
|
+)}
|
|
|
|
+
|
|
|
|
assert_in() {(
|
|
|
|
set +ex
|
|
|
|
|
|
|
|
--
|
|
|
|
2.35.3
|
|
|
|
|