merge branch 'pr-1203'

Closes #1203
LGTMs: @cyphar @hqhq
This commit is contained in:
Aleksa Sarai 2016-12-31 04:15:12 +11:00
commit db25629d46
No known key found for this signature in database
GPG Key ID: 9E18AA267DDB8DB4
3 changed files with 47 additions and 5 deletions

View File

@ -3,7 +3,7 @@
load helpers
TEST_CGROUP_NAME="runc-cgroups-integration-test"
CGROUP_MEMORY="${CGROUP_BASE_PATH}/${TEST_CGROUP_NAME}"
CGROUP_MEMORY="${CGROUP_MEMORY_BASE_PATH}/${TEST_CGROUP_NAME}"
function teardown() {
rm -f $BATS_TMPDIR/runc-update-integration-test.json

View File

@ -33,10 +33,12 @@ ROOT="$BATS_TMPDIR/runc"
CONSOLE_SOCKET="$BATS_TMPDIR/console.sock"
# Cgroup mount
CGROUP_BASE_PATH=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<MEMORY\>/ { print $5; exit }')
CGROUP_MEMORY_BASE_PATH=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<MEMORY\>/ { print $5; exit }')
CGROUP_CPU_BASE_PATH=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<CPU\>/ { print $5; exit }')
# CONFIG_MEMCG_KMEM support
KMEM="${CGROUP_BASE_PATH}/memory.kmem.limit_in_bytes"
KMEM="${CGROUP_MEMORY_BASE_PATH}/memory.kmem.limit_in_bytes"
RT_PERIOD="${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us"
# Wrapper for runc.
function runc() {
@ -74,6 +76,11 @@ function requires() {
skip "Test requires ${var}."
fi
;;
cgroups_rt)
if [ ! -e "$RT_PERIOD" ]; then
skip "Test requires ${var}."
fi
;;
*)
fail "BUG: Invalid requires ${var}."
;;
@ -189,7 +196,10 @@ function setup_hello() {
function teardown_running_container() {
runc list
if [[ "${output}" == *"$1"* ]]; then
# $1 should be a container name such as "test_busybox"
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
# e.g. "test_busybox" and "test_busybox_update"
if [[ "${output}" == *"$1 "* ]]; then
runc kill $1 KILL
retry 10 1 eval "__runc state '$1' | grep -q 'stopped'"
runc delete $1
@ -198,7 +208,10 @@ function teardown_running_container() {
function teardown_running_container_inroot() {
ROOT=$2 runc list
if [[ "${output}" == *"$1"* ]]; then
# $1 should be a container name such as "test_busybox"
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
# e.g. "test_busybox" and "test_busybox_update"
if [[ "${output}" == *"$1 "* ]]; then
ROOT=$2 runc kill $1 KILL
retry 10 1 eval "ROOT='$2' __runc state '$1' | grep -q 'stopped'"
ROOT=$2 runc delete $1

View File

@ -5,6 +5,7 @@ load helpers
function teardown() {
rm -f $BATS_TMPDIR/runc-update-integration-test.json
teardown_running_container test_update
teardown_running_container test_update_rt
teardown_busybox
}
@ -212,3 +213,31 @@ EOF
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824
}
@test "update rt period and runtime" {
requires cgroups_rt
# run a detached busybox
runc run -d --console-socket $CONSOLE_SOCKET test_update_rt
[ "$status" -eq 0 ]
wait_for_container 15 1 test_update_rt
# get the cgroup paths
eval CGROUP_CPU="${CGROUP_CPU_BASE_PATH}/runc-update-integration-test"
runc update -r - test_update_rt <<EOF
{
"cpu": {
"realtimePeriod": 800001,
"realtimeRuntime": 500001
}
}
EOF
check_cgroup_value $CGROUP_CPU "cpu.rt_period_us" 800001
check_cgroup_value $CGROUP_CPU "cpu.rt_runtime_us" 500001
runc update test_update_rt --cpu-rt-period 900001 --cpu-rt-runtime 600001
check_cgroup_value $CGROUP_CPU "cpu.rt_period_us" 900001
check_cgroup_value $CGROUP_CPU "cpu.rt_runtime_us" 600001
}