diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 40637bca648..a644bbadf63 100755 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -260,29 +260,30 @@ 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 or $3 (if specified). function check_cgroup_value() { - local current - current="$(get_cgroup_value "$1")" - local expected=$2 + local got + got="$(get_cgroup_value "$1")" + local want=$2 + local want2="${3:-}" - echo "current $current !? $expected" - [ "$current" = "$expected" ] + echo "$1: got $got, want $want $want2" + [ "$got" = "$want" ] || [[ -n "$want2" && "$got" = "$want2" ]] } -# 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() { @@ -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