tests/int/cgroups: add test for bfq per-device weight

This works for both cgroup v1 and v2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-06-13 17:44:25 -07:00
parent 1036f3f995
commit 2916817278
2 changed files with 47 additions and 5 deletions
+37
View File
@@ -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
+10 -5
View File
@@ -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" ]
}