2023-08-09 23:43:31 +03:00
#!/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]
2024-05-26 17:28:21 +03:00
MemoryMax = 400M
MemoryHigh = 400M
2023-08-09 23:43:31 +03:00
TasksMax = 400
EOF
cat >/run/systemd/system/" $pre " alpha-beta.slice <<EOF
[ Slice]
2024-05-26 17:28:21 +03:00
MemoryMax = 100M
MemoryHigh = 100M
2023-08-09 23:43:31 +03:00
TasksMax = 100
EOF
cat >/run/systemd/system/" $pre " alpha-beta-gamma.slice <<EOF
[ Slice]
2024-05-26 17:28:21 +03:00
MemoryMax = 200M
MemoryHigh = 200M
2023-08-09 23:43:31 +03:00
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 " \
2024-05-26 17:28:21 +03:00
-p MemoryMax = 50M \
-p MemoryHigh = 50M \
2023-08-09 23:43:31 +03:00
-p TasksMax = 50 \
sleep inf
# Compare with inequality because test can run in a constrained container
2024-05-26 17:28:21 +03:00
assert_le " $( systemctl show -P EffectiveMemoryMax " $srv " ) " "52428800"
assert_le " $( systemctl show -P EffectiveMemoryHigh " $srv " ) " "52428800"
2023-08-09 23:43:31 +03:00
assert_le " $( systemctl show -P EffectiveTasksMax " $srv " ) " "50"
systemctl stop " $srv "
systemd-run --unit " $srv " --slice " $slc " \
sleep inf
2024-05-26 17:28:21 +03:00
assert_le " $( systemctl show -P EffectiveMemoryMax " $srv " ) " "104857600"
assert_le " $( systemctl show -P EffectiveMemoryHigh " $srv " ) " "104857600"
2023-08-09 23:43:31 +03:00
assert_le " $( systemctl show -P EffectiveTasksMax " $srv " ) " "100"
systemctl set-property " $slc0 " \
2024-05-26 17:28:21 +03:00
MemoryMax = 50M \
MemoryHigh = 50M \
2023-08-09 23:43:31 +03:00
TasksMax = 50
2024-05-26 17:28:21 +03:00
assert_le " $( systemctl show -P EffectiveMemoryMax " $srv " ) " "52428800"
assert_le " $( systemctl show -P EffectiveMemoryHigh " $srv " ) " "52428800"
2023-08-09 23:43:31 +03:00
assert_le " $( systemctl show -P EffectiveTasksMax " $srv " ) " "50"
systemctl stop " $srv "
rm -f /run/systemd/system/" $pre " * || :