mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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). The second set of variables is mostly used by check_cgroup_value(), with only two exceptions: - CGROUP_CPU in @test "update rt period and runtime"; - few CGROUP_XXX in @test "runc delete --force in cgroupv1 with subcgroups". Remove these variables, as their values are not used much and are easy to get (as can be seen in modified test cases). While at it, mark some variables as local. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -85,8 +85,8 @@ EOF
|
||||
[[ "$output" =~ [0-9]+ ]]
|
||||
|
||||
for s in ${subsystems}; do
|
||||
name=CGROUP_${s^^}
|
||||
eval path=\$"${name}"/foo
|
||||
name=CGROUP_${s^^}_BASE_PATH
|
||||
eval path=\$"${name}${REL_CGROUPS_PATH}/foo"
|
||||
# shellcheck disable=SC2154
|
||||
[ -d "${path}" ] || fail "test failed to create memory sub-cgroup ($path not found)"
|
||||
done
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user