Skip to content

Commit

Permalink
tests/int: don't set/use CGROUP_XXX variables
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kolyshkin committed Apr 1, 2021
1 parent a1270a6 commit f09a3e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -532,23 +532,25 @@ 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
#
# 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
Expand Down

0 comments on commit f09a3e1

Please sign in to comment.