Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 20874ee

Browse files
committed
tests: backport fixes from opencontainers#4785
Signed-off-by: Jared Ledvina <[email protected]>
1 parent 5b137f6 commit 20874ee

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

tests/integration/helpers.bash

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,17 @@ function check_cpu_shares() {
344344
local shares=$1
345345

346346
if [ -v CGROUP_V2 ]; then
347-
local weight=$((1 + ((shares - 2) * 9999) / 262142))
348-
check_cpu_weight "$weight"
347+
# Same formula as ConvertCPUSharesToCgroupV2Value.
348+
local weight
349+
weight=$(awk -v shares="$shares" '
350+
BEGIN {
351+
if (shares == 0) { print 0; exit }
352+
if (shares <= 2) { print 1; exit }
353+
if (shares >= 262144) { print 10000; exit }
354+
l = log(shares) / log(2)
355+
exponent = (l*l + 125*l) / 612.0 - 7.0/34.0
356+
print int(exp(exponent * log(10)) + 0.99)
357+
}')
349358
else
350359
check_cgroup_value "cpu.shares" "$shares"
351360
check_systemd_value "CPUShares" "$shares"

tests/integration/update.bats

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,9 @@ EOF
545545
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
546546
[ "$status" -eq 0 ]
547547

548-
# check that initial values were properly set
549-
check_cpu_quota 500000 1000000 "500ms"
550-
# initial cpu shares of 100 corresponds to weight of 4
551-
check_cpu_weight 4
548+
# Check that initial values (from setup) were properly set.
549+
check_cpu_quota 500000 1000000
550+
check_cpu_shares 100
552551
check_systemd_value "TasksMax" 20
553552

554553
runc update -r - test_update <<EOF

0 commit comments

Comments
 (0)