mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Merge pull request #2881 from kolyshkin/test-rand-cg
tests/int: some refactoring, fix a flake
This commit is contained in:
@@ -717,7 +717,6 @@ func (c *linuxContainer) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc.
|
||||
return errors.New("CRIU feature check failed")
|
||||
}
|
||||
|
||||
logrus.Debugf("Feature check says: %s", criuFeatures)
|
||||
missingFeatures := false
|
||||
|
||||
// The outer if checks if the fields actually exist
|
||||
@@ -1518,7 +1517,6 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *
|
||||
// the initial CRIU run to detect the version. Skip it.
|
||||
logrus.Debugf("Using CRIU %d at: %s", c.criuVersion, c.criuPath)
|
||||
}
|
||||
logrus.Debugf("Using CRIU with following args: %s", args)
|
||||
cmd := exec.Command(c.criuPath, args...)
|
||||
if process != nil {
|
||||
cmd.Stdin = process.Stdin
|
||||
|
||||
@@ -189,8 +189,8 @@ function setup() {
|
||||
@test "runc run (blkio weight)" {
|
||||
requires root cgroups_v2
|
||||
|
||||
set_cgroups_path "$BUSYBOX_BUNDLE"
|
||||
update_config '.linux.resources.blockIO |= {"weight": 750}' "${BUSYBOX_BUNDLE}"
|
||||
set_cgroups_path
|
||||
update_config '.linux.resources.blockIO |= {"weight": 750}'
|
||||
|
||||
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
@@ -38,11 +38,23 @@ function setup_pipes() {
|
||||
}
|
||||
|
||||
function check_pipes() {
|
||||
local output stderr
|
||||
|
||||
echo Ping >&${in_w}
|
||||
exec {in_w}>&-
|
||||
exec {out_w}>&-
|
||||
exec {err_w}>&-
|
||||
|
||||
exec {in_r}>&-
|
||||
output=$(cat <&${out_r})
|
||||
exec {out_r}>&-
|
||||
stderr=$(cat <&${err_r})
|
||||
exec {err_r}>&-
|
||||
|
||||
[[ "${output}" == *"ponG Ping"* ]]
|
||||
if [ -n "$stderr" ]; then
|
||||
fail "runc stderr: $stderr"
|
||||
fi
|
||||
}
|
||||
|
||||
# Usage: runc_run_with_pipes container-name
|
||||
@@ -186,6 +198,7 @@ function simple_cr() {
|
||||
|
||||
# wait for lazy page server to be ready
|
||||
out=$(timeout 2 dd if=/proc/self/fd/${lazy_r} bs=1 count=1 2>/dev/null | od)
|
||||
exec {lazy_r}>&-
|
||||
exec {lazy_w}>&-
|
||||
# shellcheck disable=SC2116,SC2086
|
||||
out=$(echo $out) # rm newlines
|
||||
@@ -202,11 +215,13 @@ function simple_cr() {
|
||||
lp_pid=$!
|
||||
|
||||
# Restore lazily from checkpoint.
|
||||
# The restored container needs a different name as the checkpointed
|
||||
# The restored container needs a different name (as well as systemd
|
||||
# unit name, in case systemd cgroup driver is used) as the checkpointed
|
||||
# container is not yet destroyed. It is only destroyed at that point
|
||||
# in time when the last page is lazily transferred to the destination.
|
||||
# Killing the CRIU on the checkpoint side will let the container
|
||||
# continue to run if the migration failed at some point.
|
||||
[ -n "$RUNC_USE_SYSTEMD" ] && set_cgroups_path
|
||||
runc_restore_with_pipes ./image-dir test_busybox_restore --lazy-pages
|
||||
|
||||
wait $cpt_pid
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -112,22 +112,6 @@ function init_cgroup_paths() {
|
||||
# init once
|
||||
test -n "$CGROUP_UNIFIED" && return
|
||||
|
||||
local rnd="$RANDOM"
|
||||
if [ -n "${RUNC_USE_SYSTEMD}" ]; then
|
||||
SD_UNIT_NAME="runc-cgroups-integration-test-${rnd}.scope"
|
||||
if [ $(id -u) = "0" ]; then
|
||||
REL_CGROUPS_PATH="/machine.slice/$SD_UNIT_NAME"
|
||||
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test-${rnd}"
|
||||
else
|
||||
REL_CGROUPS_PATH="/user.slice/user-$(id -u).slice/user@$(id -u).service/machine.slice/$SD_UNIT_NAME"
|
||||
# OCI path doesn't contain "/user.slice/user-$(id -u).slice/user@$(id -u).service/" prefix
|
||||
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test-${rnd}"
|
||||
fi
|
||||
else
|
||||
REL_CGROUPS_PATH="/runc-cgroups-integration-test/test-cgroup-${rnd}"
|
||||
OCI_CGROUPS_PATH=$REL_CGROUPS_PATH
|
||||
fi
|
||||
|
||||
if stat -f -c %t /sys/fs/cgroup | grep -qFw 63677270; then
|
||||
CGROUP_UNIFIED=yes
|
||||
# "pseudo" controllers do not appear in /sys/fs/cgroup/cgroup.controllers.
|
||||
@@ -140,7 +124,6 @@ function init_cgroup_paths() {
|
||||
echo devices
|
||||
)
|
||||
CGROUP_BASE_PATH=/sys/fs/cgroup
|
||||
CGROUP_PATH=${CGROUP_BASE_PATH}${REL_CGROUPS_PATH}
|
||||
|
||||
# Find any cgroup.freeze files...
|
||||
if [ -n "$(find "$CGROUP_BASE_PATH" -type f -name "cgroup.freeze" -print -quit)" ]; then
|
||||
@@ -149,32 +132,57 @@ 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
|
||||
}
|
||||
|
||||
# Helper function to set cgroupsPath to the value of $OCI_CGROUPS_PATH
|
||||
# Randomize cgroup path(s), and update cgroupsPath in config.json.
|
||||
# This function sets a few cgroup-related variables.
|
||||
function set_cgroups_path() {
|
||||
bundle="${1:-.}"
|
||||
init_cgroup_paths
|
||||
update_config '.linux.cgroupsPath |= "'"${OCI_CGROUPS_PATH}"'"' $bundle
|
||||
|
||||
local rnd="$RANDOM"
|
||||
if [ -n "${RUNC_USE_SYSTEMD}" ]; then
|
||||
SD_UNIT_NAME="runc-cgroups-integration-test-${rnd}.scope"
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
REL_CGROUPS_PATH="/machine.slice/$SD_UNIT_NAME"
|
||||
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test-${rnd}"
|
||||
else
|
||||
REL_CGROUPS_PATH="/user.slice/user-$(id -u).slice/user@$(id -u).service/machine.slice/$SD_UNIT_NAME"
|
||||
# OCI path doesn't contain "/user.slice/user-$(id -u).slice/user@$(id -u).service/" prefix
|
||||
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test-${rnd}"
|
||||
fi
|
||||
else
|
||||
REL_CGROUPS_PATH="/runc-cgroups-integration-test/test-cgroup-${rnd}"
|
||||
OCI_CGROUPS_PATH=$REL_CGROUPS_PATH
|
||||
fi
|
||||
|
||||
# Absolute path to container's cgroup v2.
|
||||
if [ "$CGROUP_UNIFIED" == "yes" ]; then
|
||||
CGROUP_PATH=${CGROUP_BASE_PATH}${REL_CGROUPS_PATH}
|
||||
fi
|
||||
|
||||
update_config '.linux.cgroupsPath |= "'"${OCI_CGROUPS_PATH}"'"' "$bundle"
|
||||
}
|
||||
|
||||
# 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