@@ -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