Skip to content

Commit

Permalink
tests/int: move check_cpu* to helpers
Browse files Browse the repository at this point in the history
To be used by the following commit.
  • Loading branch information
kolyshkin committed Nov 4, 2020
1 parent a141d2f commit 1c4690d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
41 changes: 41 additions & 0 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,47 @@ function check_systemd_value() {
[ "$current" = "$expected" ] || [ -n "$expected2" -a "$current" = "$expected2" ]
}

function check_cpu_quota() {
local quota=$1
local period=$2
local sd_quota=$3

if [ "$CGROUP_UNIFIED" = "yes" ]; then
if [ "$quota" = "-1" ]; then
quota="max"
fi
check_cgroup_value "cpu.max" "$quota $period"
else
check_cgroup_value "cpu.cfs_quota_us" $quota
check_cgroup_value "cpu.cfs_period_us" "$period"
fi
# systemd values are the same for v1 and v2
check_systemd_value "CPUQuotaPerSecUSec" "$sd_quota"

# CPUQuotaPeriodUSec requires systemd >= v242
[ "$(systemd_version)" -lt 242 ] && return

local sd_period=$((period / 1000))ms
[ "$sd_period" = "1000ms" ] && sd_period="1s"
local sd_infinity=""
# 100ms is the default value, and if not set, shown as infinity
[ "$sd_period" = "100ms" ] && sd_infinity="infinity"
check_systemd_value "CPUQuotaPeriodUSec" $sd_period $sd_infinity
}

function check_cpu_shares() {
local shares=$1

if [ "$CGROUP_UNIFIED" = "yes" ]; then
local weight=$((1 + ((shares - 2) * 9999) / 262142))
check_cgroup_value "cpu.weight" $weight
check_systemd_value "CPUWeight" $weight
else
check_cgroup_value "cpu.shares" "$shares"
check_systemd_value "CPUShares" "$shares"
fi
}

# Helper function to set a resources limit
function set_resources_limit() {
bundle="${1:-.}"
Expand Down
41 changes: 0 additions & 41 deletions tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -240,47 +240,6 @@ EOF
check_systemd_value "TasksMax" 20
}

function check_cpu_quota() {
local quota=$1
local period=$2
local sd_quota=$3

if [ "$CGROUP_UNIFIED" = "yes" ]; then
if [ "$quota" = "-1" ]; then
quota="max"
fi
check_cgroup_value "cpu.max" "$quota $period"
else
check_cgroup_value "cpu.cfs_quota_us" $quota
check_cgroup_value "cpu.cfs_period_us" "$period"
fi
# systemd values are the same for v1 and v2
check_systemd_value "CPUQuotaPerSecUSec" "$sd_quota"

# CPUQuotaPeriodUSec requires systemd >= v242
[ "$(systemd_version)" -lt 242 ] && return

local sd_period=$((period / 1000))ms
[ "$sd_period" = "1000ms" ] && sd_period="1s"
local sd_infinity=""
# 100ms is the default value, and if not set, shown as infinity
[ "$sd_period" = "100ms" ] && sd_infinity="infinity"
check_systemd_value "CPUQuotaPeriodUSec" $sd_period $sd_infinity
}

function check_cpu_shares() {
local shares=$1

if [ "$CGROUP_UNIFIED" = "yes" ]; then
local weight=$((1 + ((shares - 2) * 9999) / 262142))
check_cgroup_value "cpu.weight" $weight
check_systemd_value "CPUWeight" $weight
else
check_cgroup_value "cpu.shares" "$shares"
check_systemd_value "CPUShares" "$shares"
fi
}

@test "update cgroup cpu limits" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup

Expand Down

0 comments on commit 1c4690d

Please sign in to comment.