diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 5875469c6..1ea3e07a0 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -150,6 +150,43 @@ function setup() { fi } +@test "runc run (per-device io weight for bfq)" { + requires root # to create a loop device + + dd if=/dev/zero of=backing.img bs=4096 count=1 + dev=$(losetup --find --show backing.img) || skip "unable to create a loop device" + + # See if BFQ scheduler is available. + if ! { grep -qw bfq "/sys/block/${dev#/dev/}/queue/scheduler" && + echo bfq >"/sys/block/${dev#/dev/}/queue/scheduler"; }; then + losetup -d "$dev" + skip "BFQ scheduler not available" + fi + + set_cgroups_path + + IFS=$' \t:' read -r major minor <<<"$(lsblk -nd -o MAJ:MIN "$dev")" + update_config ' .linux.devices += [{path: "'"$dev"'", type: "b", major: '"$major"', minor: '"$minor"'}] + | .linux.resources.blockIO.weight |= 333 + | .linux.resources.blockIO.weightDevice |= [ + { major: '"$major"', minor: '"$minor"', weight: 444 } + ]' + runc run -d --console-socket "$CONSOLE_SOCKET" test_dev_weight + [ "$status" -eq 0 ] + + # The loop device itself is no longer needed. + losetup -d "$dev" + + if [ "$CGROUP_UNIFIED" = "yes" ]; then + file="io.bfq.weight" + else + file="blkio.bfq.weight_device" + fi + weights=$(get_cgroup_value $file) + [[ "$weights" == *"default 333"* ]] + [[ "$weights" == *"$major:$minor 444"* ]] +} + @test "runc run (cgroup v2 resources.unified only)" { requires root cgroups_v2 diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index b92c4169a..fe3a324b6 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -168,10 +168,9 @@ function set_cgroups_path() { update_config '.linux.cgroupsPath |= "'"${OCI_CGROUPS_PATH}"'"' "$bundle" } -# Helper to check a value in cgroups. -function check_cgroup_value() { +# Get a value from a cgroup file. +function get_cgroup_value() { local source=$1 - local expected=$2 local cgroup var current if [ "x$CGROUP_UNIFIED" = "xyes" ]; then @@ -181,9 +180,15 @@ function check_cgroup_value() { var=CGROUP_${var^^}_BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH) eval cgroup=\$${var}${REL_CGROUPS_PATH} fi + cat $cgroup/$source +} + +# Helper to check a if value in a cgroup file matches the expected one. +function check_cgroup_value() { + local current + current="$(get_cgroup_value $1)" + local expected=$2 - current=$(cat $cgroup/$source) - echo $cgroup/$source echo "current" $current "!?" "$expected" [ "$current" = "$expected" ] }