From 7c597660495bafbc7b4e0e1a0c698675d71ea928 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 5 Aug 2016 13:17:06 +0200 Subject: [PATCH] tests: add requires cgroups_kmem On older kernels or kernels were CONFIG_MEMCG_KMEM is not set some cgroup tests cannot be run. We simply test for the existence of the file "${CGROUP_BASE_PATH}/memory/memory.kmem.limit_in_bytes" which should be sufficient to conclude that CONFIG_MEMCG_KMEM is not set. Signed-off-by: Christian Brauner --- tests/integration/cgroups.bats | 10 +++------- tests/integration/helpers.bash | 11 +++++++++++ tests/integration/update.bats | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index c415d5da6..f7796a886 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -2,13 +2,8 @@ load helpers -CGROUP_MEMORY="" TEST_CGROUP_NAME="runc-cgroups-integration-test" - -function init_cgroup_path() { - base_path=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\/ { print $5; exit }') - CGROUP_MEMORY="${base_path}/${TEST_CGROUP_NAME}" -} +CGROUP_MEMORY="${CGROUP_BASE_PATH}/${TEST_CGROUP_NAME}" function teardown() { rm -f $BATS_TMPDIR/runc-update-integration-test.json @@ -19,7 +14,6 @@ function teardown() { function setup() { teardown setup_busybox - init_cgroup_path } function check_cgroup_value() { @@ -34,6 +28,7 @@ function check_cgroup_value() { } @test "runc update --kernel-memory (initialized)" { + requires cgroups_kmem # Add cgroup path sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json @@ -61,6 +56,7 @@ EOF } @test "runc update --kernel-memory (uninitialized)" { + requires cgroups_kmem # Add cgroup path sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 236e5d26c..bf3b36b12 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -28,6 +28,12 @@ KERNEL_MINOR="${KERNEL_MINOR%%.*}" # Root state path. ROOT="$BATS_TMPDIR/runc" +# Cgroup mount +CGROUP_BASE_PATH=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\/ { print $5; exit }') + +# CONFIG_MEMCG_KMEM support +KMEM="${CGROUP_BASE_PATH}/memory.kmem.limit_in_bytes" + # Wrapper for runc. function runc() { run __runc "$@" @@ -59,6 +65,11 @@ function requires() { skip "Test requires ${var}." fi ;; + cgroups_kmem) + if [ ! -e "$KMEM" ]; then + skip "Test requires ${var}." + fi + ;; *) fail "BUG: Invalid requires ${var}." ;; diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 2020127d7..8ba95d1d9 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -48,6 +48,7 @@ function check_cgroup_value() { } @test "update" { + requires cgroups_kmem # run a few busyboxes detached runc run -d --console /dev/pts/ptmx test_update [ "$status" -eq 0 ]