Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cpu burst test failure on newer kernels #4374

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Loading