From b437ed3063150c721eb1d3c5e4d8d46b083c7ed7 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 13 Aug 2024 17:33:14 -0700 Subject: [PATCH 1/2] tests/int: check_{systemd,cgroup}_value: better log 1. Rename current -> got, expected -> want. 2. check_cgroup_value: add file name to output. 3. Improve functions description. This is mostly to simplify debugging test failures. Example output before: current 500000 !? 500 After: cpu.max.burst: got 500000, want 500 Signed-off-by: Kir Kolyshkin --- tests/integration/helpers.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 40637bca648..b32652dc25e 100755 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -260,29 +260,29 @@ function get_cgroup_value() { cat "$cgroup/$1" } -# Helper to check a if value in a cgroup file matches the expected one. +# Check if a value in a cgroup file $1 matches $2. function check_cgroup_value() { - local current - current="$(get_cgroup_value "$1")" - local expected=$2 + local got + got="$(get_cgroup_value "$1")" + local want=$2 - echo "current $current !? $expected" - [ "$current" = "$expected" ] + echo "$1: got $got, want $want" + [ "$got" = "$want" ] } -# Helper to check a value in systemd. +# Check if a value of systemd unit property $1 matches $2 or $3 (if specified). function check_systemd_value() { [ ! -v RUNC_USE_SYSTEMD ] && return local source="$1" [ "$source" = "unsupported" ] && return - local expected="$2" - local expected2="${3:-}" + local want="$2" + local want2="${3:-}" local user="" [ $EUID -ne 0 ] && user="--user" - current=$(systemctl show $user --property "$source" "$SD_UNIT_NAME" | awk -F= '{print $2}') - echo "systemd $source: current $current !? $expected $expected2" - [ "$current" = "$expected" ] || [[ -n "$expected2" && "$current" = "$expected2" ]] + got=$(systemctl show $user --property "$source" "$SD_UNIT_NAME" | awk -F= '{print $2}') + echo "systemd $source: got $got, want $want $want2" + [ "$got" = "$want" ] || [[ -n "$want2" && "$got" = "$want2" ]] } function check_cpu_quota() { From a7c8d86fc14da6c80d834e15b234c6012d5e2bf0 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 13 Aug 2024 17:53:46 -0700 Subject: [PATCH 2/2] tests/int: fix "cpu burst" failure on new kernels A kernel bug which resulted in cpu.max.burst value read which is 1000 times smaller than it should be has recently been fixed (see [1]). Adapt the test so it works with either broken or fixed kernel. [1]: https://lore.kernel.org/all/20240424132438.514720-1-serein.chengyu@huawei.com/ Signed-off-by: Kir Kolyshkin --- tests/integration/helpers.bash | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index b32652dc25e..a644bbadf63 100755 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -260,14 +260,15 @@ function get_cgroup_value() { cat "$cgroup/$1" } -# Check if a value in a cgroup file $1 matches $2. +# Check if a value in a cgroup file $1 matches $2 or $3 (if specified). function check_cgroup_value() { local got got="$(get_cgroup_value "$1")" local want=$2 + local want2="${3:-}" - echo "$1: got $got, want $want" - [ "$got" = "$want" ] + echo "$1: got $got, want $want $want2" + [ "$got" = "$want" ] || [[ -n "$want2" && "$got" = "$want2" ]] } # Check if a value of systemd unit property $1 matches $2 or $3 (if specified). @@ -316,8 +317,10 @@ function check_cpu_quota() { function check_cpu_burst() { local burst=$1 if [ -v CGROUP_V2 ]; then - burst=$((burst / 1000)) - check_cgroup_value "cpu.max.burst" "$burst" + # Due to a kernel bug (fixed by commit 49217ea147df, see + # https://lore.kernel.org/all/20240424132438.514720-1-serein.chengyu@huawei.com/), + # older kernels printed value divided by 1000. Check for both. + check_cgroup_value "cpu.max.burst" "$burst" "$((burst / 1000))" else check_cgroup_value "cpu.cfs_burst_us" "$burst" fi