Skip to content

Commit

Permalink
tests/int/cgroups: add test for bfq per-device weight
Browse files Browse the repository at this point in the history
This works for both cgroup v1 and v2.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Jun 16, 2021
1 parent 1036f3f commit 2916817
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
37 changes: 37 additions & 0 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" ]
}
Expand Down

0 comments on commit 2916817

Please sign in to comment.