#!/usr/bin/env bats load helpers function teardown() { rm -f $BATS_TMPDIR/runc-cgroups-integration-test.json teardown_running_container test_update teardown_running_container test_update_rt teardown_busybox } function setup() { teardown setup_busybox set_cgroups_path "$BUSYBOX_BUNDLE" # Set some initial known values DATA=$(cat < $BATS_TMPDIR/runc-cgroups-integration-test.json { "memory": { "limit": 33554432, "reservation": 25165824 }, "cpu": { "shares": 100, "quota": 500000, "period": 1000000, "cpus": "0" }, "pids": { "limit": 20 } } EOF runc update -r $BATS_TMPDIR/runc-cgroups-integration-test.json test_update [ "$status" -eq 0 ] check_cgroup_value "cpuset.cpus" 0 check_cgroup_value $MEM_LIMIT 33554432 check_cgroup_value $MEM_RESERVE 25165824 check_cgroup_value "pids.max" 20 } @test "update cgroup v1 cpu limits" { [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup requires cgroups_v1 # run a few busyboxes detached runc run -d --console-socket $CONSOLE_SOCKET test_update [ "$status" -eq 0 ] # check that initial values were properly set check_cgroup_value "cpu.cfs_period_us" 1000000 check_cgroup_value "cpu.cfs_quota_us" 500000 check_cgroup_value "cpu.shares" 100 # update cpu-period runc update test_update --cpu-period 900000 [ "$status" -eq 0 ] check_cgroup_value "cpu.cfs_period_us" 900000 # update cpu-quota runc update test_update --cpu-quota 600000 [ "$status" -eq 0 ] check_cgroup_value "cpu.cfs_quota_us" 600000 # update cpu-shares runc update test_update --cpu-share 200 [ "$status" -eq 0 ] check_cgroup_value "cpu.shares" 200 # Revert to the test initial value via json on stding runc update -r - test_update < $BATS_TMPDIR/runc-cgroups-integration-test.json { "cpu": { "shares": 100, "quota": 500000, "period": 1000000 } } EOF runc update -r $BATS_TMPDIR/runc-cgroups-integration-test.json test_update [ "$status" -eq 0 ] check_cgroup_value "cpu.cfs_period_us" 1000000 check_cgroup_value "cpu.cfs_quota_us" 500000 check_cgroup_value "cpu.shares" 100 } @test "update rt period and runtime" { [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup requires cgroups_rt # run a detached busybox runc run -d --console-socket $CONSOLE_SOCKET test_update_rt [ "$status" -eq 0 ] runc update -r - test_update_rt <