Skip to content

Commit 16c0bda

Browse files
committed
Update "bud with --cpu-shares" test, and rename it
Update "the bud with --cpu-shares" test to expect the a cgroupsv2 value computed using either the older formula or the newer one introduced in github.com/opencontainers/cgroups v0.0.3, and give it a unique name so that it can be selected more easily with bats's "--filter" flag. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent 5408a8b commit 16c0bda

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tests/bud.bats

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6422,7 +6422,7 @@ _EOF
64226422
expect_output --substring "memory"
64236423
}
64246424

6425-
@test "bud with --cpu-shares" {
6425+
@test "bud with --cpu-shares, checked" {
64266426
skip_if_chroot
64276427
skip_if_rootless_environment
64286428
skip_if_rootless_and_cgroupv1
@@ -6438,21 +6438,26 @@ _EOF
64386438

64396439
if is_cgroupsv2; then
64406440
cat > $mytmpdir/Containerfile << _EOF
6441-
from alpine
6442-
run printf "weight " && cat /sys/fs/cgroup/\$(awk -F : '{print \$NF}' /proc/self/cgroup)/cpu.weight
6443-
_EOF
6444-
expect="weight $((1 + ((${shares} - 2) * 9999) / 262142))"
6441+
FROM alpine
6442+
RUN printf "weight " && cat /sys/fs/cgroup/\$(awk -F : '{print \$NF}' /proc/self/cgroup)/cpu.weight
6443+
_EOF
6444+
# there's an old way to convert the value, and a new way to convert the value, and we don't know
6445+
# which one our runtime is using, so accept the values that either would compute for ${shares}
6446+
local oldexpect="weight $((1 + ((${shares} - 2) * 9999) / 262142))"
6447+
local newconverted=$(awk '{if ($1 <= 2) { print "1"} else if ($1 >= 262144) {print "10000"} else {l=log($1)/log(2); e=((((l+125)*l)/612.0) - 7.0/34.0); p = exp(e*log(10)); print int(p+1)}}' <<< "${shares}")
6448+
local newexpect="weight ${newconverted}"
6449+
expect="($oldexpect|$newexpect)"
64456450
else
64466451
cat > $mytmpdir/Containerfile << _EOF
6447-
from alpine
6448-
run printf "weight " && cat /sys/fs/cgroup/cpu/cpu.shares
6452+
FROM alpine
6453+
RUN printf "weight " && cat /sys/fs/cgroup/cpu/cpu.shares
64496454
_EOF
64506455
expect="weight ${shares}"
64516456
fi
64526457

64536458
run_buildah build --cpu-shares=${shares} -t testcpu \
64546459
$WITH_POLICY_JSON --file ${mytmpdir}/Containerfile .
6455-
expect_output --from="${lines[2]}" "${expect}"
6460+
expect_output --from="${lines[2]}" --substring "${expect}"
64566461
}
64576462

64586463
@test "bud with --cpuset-cpus" {

0 commit comments

Comments
 (0)