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).

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 <[email protected]>
  • Loading branch information
kolyshkin committed Apr 1, 2021
1 parent a1270a6 commit c34f9f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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 c34f9f3

Please sign in to comment.