From b4be36563a4e8f2f24e37485289a0d190a67a294 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Thu, 13 Nov 2025 08:44:11 +0100 Subject: [PATCH] cgroup-limit: support running test where DOTNET_PROCESSOR_COUNT is set. --- cgroup-limit/test.sh | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/cgroup-limit/test.sh b/cgroup-limit/test.sh index fe90660..c269ba3 100755 --- a/cgroup-limit/test.sh +++ b/cgroup-limit/test.sh @@ -14,21 +14,6 @@ if [[ "$(stat -f -c "%T" /sys/fs/cgroup)" == "cgroup2fs" ]] ; then CGROUPV2=true fi -if [[ $CGROUPV2 == true ]] && [[ $(dotnet --version) == "3."* ]]; then - echo "cgroup v2 is not fully supported on .NET Core 3.x. Skipping." - exit 0 -fi - -# For mono-based runtimes (ppc64le, s390x), cgroup support is only functional -# on .NET 7.0 and later. -if [[ "$(uname -m)" == "s390x" ]] || [[ "$(uname -m)" == "ppc64le" ]] ; then - IFS='.-' read -ra VERSION <<< "${1:-$(dotnet --version)}" - if [[ "${VERSION[0]}" -lt "7" ]]; then - echo "cgroup support is not available on Mono-based runtimes before .NET 7. Skipping." - exit 0 - fi -fi - if [ -z "$(command -v systemctl)" ]; then echo "Environment does not use systemd" exit 0 @@ -41,18 +26,17 @@ if [ "$UID" != "0" ]; then if ! grep -q "cpu" "/sys/fs/cgroup/user.slice/user-$UID.slice/user@$UID.service/cgroup.controllers" ; then # user can't set cpu limits, use sudo. SYSTEMD_RUN="sudo -n $SYSTEMD_RUN" - - # Pass DOTNET_ROOT to support testing against a dotnet tarball. - # On RHEL 7 we don't pass the envvar because systemd-run doesn't support '-E' yet and the envvar is passed by default. - if [[ "$runtime_id" != "rhel.7"* ]]; then - SYSTEMD_RUN="$SYSTEMD_RUN -E DOTNET_ROOT=$DOTNET_ROOT" - fi else # run on behalf of user. SYSTEMD_RUN="$SYSTEMD_RUN --user" fi fi +# Pass DOTNET_ROOT to support testing against a dotnet tarball. +SYSTEMD_RUN="$SYSTEMD_RUN -E DOTNET_ROOT=$DOTNET_ROOT" +# Unset DOTNET_PROCESSOR_COUNT so .NET won't return its value instead of the cgroup CPU limit. +SYSTEMD_RUN="$SYSTEMD_RUN -E DOTNET_PROCESSOR_COUNT=" + memory_args="-p MemoryLimit=100M" if [[ $CGROUPV2 == true ]]; then memory_args="-p MemoryMax=100M"