From c34f9f309ea63f1867eb61d41e6d393800e9bf04 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 31 Mar 2021 19:28:24 -0700 Subject: [PATCH] tests/int: don't set/use CGROUP_XXX variables Helper function init_cgroup_paths sets two sets of cgroup path variables for cgroup v1 case (below XXX is cgroup controller name, e.g. MEMORY): 1. CGROUP_XXX_BASE_PATH -- path to XXX controller mount point (e.g. CGROUP_MEMORY_BASE_PATH=/sys/fs/cgroup/memory); 2. CGROUP_XXX -- path to the particular container XXX controller cgroup (e.g. CGROUP_MEMORY=/sys/fs/cgroup/memory/runc-cgroups-integration-test/test-cgroup). Now, the second set of variables is only used by check_cgroup_value() (with the sole exception of CGROUP_CPU which is used by @test "update rt period and runtime"). Remove these variables, as their values are not used much and are easy to get (as can be seen in the rt test case). While at it, mark some variables as local. Signed-off-by: Kir Kolyshkin --- tests/integration/helpers.bash | 12 +++++++----- tests/integration/update.bats | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index a35ec62d71e..2cd48cce628 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -149,11 +149,11 @@ function init_cgroup_paths() { else CGROUP_UNIFIED=no CGROUP_SUBSYSTEMS=$(awk '!/^#/ {print $1}' /proc/cgroups) + local g base_path for g in ${CGROUP_SUBSYSTEMS}; do base_path=$(gawk '$(NF-2) == "cgroup" && $NF ~ /\<'${g}'\>/ { print $5; exit }' /proc/self/mountinfo) test -z "$base_path" && continue eval CGROUP_${g^^}_BASE_PATH="${base_path}" - eval CGROUP_${g^^}="${base_path}${REL_CGROUPS_PATH}" done fi } @@ -167,14 +167,16 @@ function set_cgroups_path() { # Helper to check a value in cgroups. function check_cgroup_value() { - source=$1 - expected=$2 + local source=$1 + local expected=$2 + local cgroup var current if [ "x$CGROUP_UNIFIED" = "xyes" ]; then cgroup=$CGROUP_PATH else - ctrl=${source%%.*} - eval cgroup=\$CGROUP_${ctrl^^} + var=${source%%.*} # controller name (e.g. memory) + var=CGROUP_${var^^}_BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH) + eval cgroup=\$var${REL_CGROUPS_PATH} fi current=$(cat $cgroup/$source) diff --git a/tests/integration/update.bats b/tests/integration/update.bats index bea67312d2c..149da63cff9 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -532,10 +532,12 @@ EOF [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup requires cgroups_v1 cgroups_rt no_systemd - # By default, "${CGROUP_CPU}/cpu.rt_runtime_us" is set to 0, which inhibits + local cgroup_cpu="${CGROUP_CPU_BASE_PATH}/${REL_CGROUPS_PATH}" + + # By default, "${cgroup_cpu}/cpu.rt_runtime_us" is set to 0, which inhibits # setting the container's realtimeRuntime. (#2046) # - # When $CGROUP_CPU is "/sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/test-cgroup", + # When ${cgroup_cpu} is "/sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/test-cgroup", # we write the values of /sys/fs/cgroup/cpu,cpuacct/cpu.rt_{period,runtime}_us to: # - sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/cpu.rt_{period,runtime}_us # - sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/test-cgroup/cpu.rt_{period,runtime}_us @@ -543,12 +545,12 @@ EOF # Typically period=1000000 runtime=950000 . # # TODO: support systemd - mkdir -p "$CGROUP_CPU" + mkdir -p "$cgroup_cpu" local root_period root_runtime root_period=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us") root_runtime=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_runtime_us") # the following IFS magic sets dirs=("runc-cgroups-integration-test" "test-cgroup") - IFS='/' read -r -a dirs <<<"${CGROUP_CPU//${CGROUP_CPU_BASE_PATH}/}" + IFS='/' read -r -a dirs <<<"$REL_CGROUPS_PATH" for ((i = 0; i < ${#dirs[@]}; i++)); do local target="$CGROUP_CPU_BASE_PATH" for ((j = 0; j <= i; j++)); do