tests/integration/*.bats: reformat with shfmt

Various bats tests use various types of indentation (about half
is tabs, the rest is 2 spaces, 4 spaces, etc.).

Let's bring it to one style (tabs) using recently added
shfmt support for bats files (see [1]).

This commit is brought to you by

	shfmt -ln bats -w tests/integration/*.bats

[1] https://github.com/mvdan/sh/issues/600

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2020-10-11 19:12:51 -07:00
parent 44f221e2fc
commit fc8c779704
24 changed files with 1448 additions and 1449 deletions
+151 -151
View File
@@ -3,198 +3,198 @@
load helpers load helpers
function teardown() { function teardown() {
teardown_running_container test_cgroups_kmem teardown_running_container test_cgroups_kmem
teardown_running_container test_cgroups_permissions teardown_running_container test_cgroups_permissions
teardown_running_container test_cgroups_group teardown_running_container test_cgroups_group
teardown_running_container test_cgroups_unified teardown_running_container test_cgroups_unified
teardown_busybox teardown_busybox
} }
function setup() { function setup() {
teardown teardown
setup_busybox setup_busybox
} }
@test "runc update --kernel-memory{,-tcp} (initialized)" { @test "runc update --kernel-memory{,-tcp} (initialized)" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_kmem requires cgroups_kmem
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
# Set some initial known values # Set some initial known values
update_config '.linux.resources.memory |= {"kernel": 16777216, "kernelTCP": 11534336}' "${BUSYBOX_BUNDLE}" update_config '.linux.resources.memory |= {"kernel": 16777216, "kernelTCP": 11534336}' "${BUSYBOX_BUNDLE}"
# run a detached busybox to work with # run a detached busybox to work with
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "memory.kmem.limit_in_bytes" 16777216 check_cgroup_value "memory.kmem.limit_in_bytes" 16777216
check_cgroup_value "memory.kmem.tcp.limit_in_bytes" 11534336 check_cgroup_value "memory.kmem.tcp.limit_in_bytes" 11534336
# update kernel memory limit # update kernel memory limit
runc update test_cgroups_kmem --kernel-memory 50331648 runc update test_cgroups_kmem --kernel-memory 50331648
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "memory.kmem.limit_in_bytes" 50331648 check_cgroup_value "memory.kmem.limit_in_bytes" 50331648
# update kernel memory tcp limit # update kernel memory tcp limit
runc update test_cgroups_kmem --kernel-memory-tcp 41943040 runc update test_cgroups_kmem --kernel-memory-tcp 41943040
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "memory.kmem.tcp.limit_in_bytes" 41943040 check_cgroup_value "memory.kmem.tcp.limit_in_bytes" 41943040
} }
@test "runc update --kernel-memory (uninitialized)" { @test "runc update --kernel-memory (uninitialized)" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_kmem requires cgroups_kmem
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
# run a detached busybox to work with # run a detached busybox to work with
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# update kernel memory limit # update kernel memory limit
runc update test_cgroups_kmem --kernel-memory 50331648 runc update test_cgroups_kmem --kernel-memory 50331648
# Since kernel 4.6, we can update kernel memory without initialization # Since kernel 4.6, we can update kernel memory without initialization
# because it's accounted by default. # because it's accounted by default.
if [[ "$KERNEL_MAJOR" -lt 4 || ( "$KERNEL_MAJOR" -eq 4 && "$KERNEL_MINOR" -le 5 ) ]]; then if [[ "$KERNEL_MAJOR" -lt 4 || ("$KERNEL_MAJOR" -eq 4 && "$KERNEL_MINOR" -le 5) ]]; then
[ ! "$status" -eq 0 ] [ ! "$status" -eq 0 ]
else else
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "memory.kmem.limit_in_bytes" 50331648 check_cgroup_value "memory.kmem.limit_in_bytes" 50331648
fi fi
} }
@test "runc create (no limits + no cgrouppath + no permission) succeeds" { @test "runc create (no limits + no cgrouppath + no permission) succeeds" {
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "runc create (rootless + no limits + cgrouppath + no permission) fails with permission error" { @test "runc create (rootless + no limits + cgrouppath + no permission) fails with permission error" {
requires rootless requires rootless
requires rootless_no_cgroup requires rootless_no_cgroup
# systemd controls the permission, so error does not happen # systemd controls the permission, so error does not happen
requires no_systemd requires no_systemd
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ ${lines[0]} == *"permission denied"* ]] [[ ${lines[0]} == *"permission denied"* ]]
} }
@test "runc create (rootless + limits + no cgrouppath + no permission) fails with informative error" { @test "runc create (rootless + limits + no cgrouppath + no permission) fails with informative error" {
requires rootless requires rootless
requires rootless_no_cgroup requires rootless_no_cgroup
# systemd controls the permission, so error does not happen # systemd controls the permission, so error does not happen
requires no_systemd requires no_systemd
set_resources_limit "$BUSYBOX_BUNDLE" set_resources_limit "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ ${lines[0]} == *"rootless needs no limits + no cgrouppath when no permission is granted for cgroups"* ]] || [[ ${lines[0]} == *"cannot set pids limit: container could not join or create cgroup"* ]] [[ ${lines[0]} == *"rootless needs no limits + no cgrouppath when no permission is granted for cgroups"* ]] || [[ ${lines[0]} == *"cannot set pids limit: container could not join or create cgroup"* ]]
} }
@test "runc create (limits + cgrouppath + permission on the cgroup dir) succeeds" { @test "runc create (limits + cgrouppath + permission on the cgroup dir) succeeds" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE" set_resources_limit "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
if [ "$CGROUP_UNIFIED" != "no" ]; then if [ "$CGROUP_UNIFIED" != "no" ]; then
if [ -n "${RUNC_USE_SYSTEMD}" ] ; then if [ -n "${RUNC_USE_SYSTEMD}" ]; then
if [ "$(id -u)" = "0" ]; then if [ "$(id -u)" = "0" ]; then
check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/machine.slice/cgroup.controllers)" check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/machine.slice/cgroup.controllers)"
else else
# shellcheck disable=SC2046 # shellcheck disable=SC2046
check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/cgroup.controllers)" check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/cgroup.controllers)"
fi fi
else else
check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/cgroup.controllers)" check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/cgroup.controllers)"
fi fi
fi fi
} }
@test "runc exec (limits + cgrouppath + permission on the cgroup dir) succeeds" { @test "runc exec (limits + cgrouppath + permission on the cgroup dir) succeeds" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE" set_resources_limit "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_cgroups_permissions echo "cgroups_exec" runc exec test_cgroups_permissions echo "cgroups_exec"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == *"cgroups_exec"* ]] [[ ${lines[0]} == *"cgroups_exec"* ]]
} }
@test "runc exec (cgroup v2 + init process in non-root cgroup) succeeds" { @test "runc exec (cgroup v2 + init process in non-root cgroup) succeeds" {
requires root cgroups_v2 requires root cgroups_v2
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE" set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_group runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_group
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_cgroups_group cat /sys/fs/cgroup/cgroup.controllers runc exec test_cgroups_group cat /sys/fs/cgroup/cgroup.controllers
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == *"memory"* ]] [[ ${lines[0]} == *"memory"* ]]
runc exec test_cgroups_group cat /proc/self/cgroup runc exec test_cgroups_group cat /proc/self/cgroup
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == "0::/" ]] [[ ${lines[0]} == "0::/" ]]
runc exec test_cgroups_group mkdir /sys/fs/cgroup/foo runc exec test_cgroups_group mkdir /sys/fs/cgroup/foo
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_cgroups_group sh -c "echo 1 > /sys/fs/cgroup/foo/cgroup.procs" runc exec test_cgroups_group sh -c "echo 1 > /sys/fs/cgroup/foo/cgroup.procs"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# the init process is now in "/foo", but an exec process can still join "/" # the init process is now in "/foo", but an exec process can still join "/"
# because we haven't enabled any domain controller. # because we haven't enabled any domain controller.
runc exec test_cgroups_group cat /proc/self/cgroup runc exec test_cgroups_group cat /proc/self/cgroup
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == "0::/" ]] [[ ${lines[0]} == "0::/" ]]
# turn on a domain controller (memory) # turn on a domain controller (memory)
runc exec test_cgroups_group sh -euxc 'echo $$ > /sys/fs/cgroup/foo/cgroup.procs; echo +memory > /sys/fs/cgroup/cgroup.subtree_control' runc exec test_cgroups_group sh -euxc 'echo $$ > /sys/fs/cgroup/foo/cgroup.procs; echo +memory > /sys/fs/cgroup/cgroup.subtree_control'
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# an exec process can no longer join "/" after turning on a domain controller. # an exec process can no longer join "/" after turning on a domain controller.
# falls back to "/foo". # falls back to "/foo".
runc exec test_cgroups_group cat /proc/self/cgroup runc exec test_cgroups_group cat /proc/self/cgroup
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == "0::/foo" ]] [[ ${lines[0]} == "0::/foo" ]]
# teardown: remove "/foo" # teardown: remove "/foo"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
runc exec test_cgroups_group sh -uxc 'echo -memory > /sys/fs/cgroup/cgroup.subtree_control; for f in $(cat /sys/fs/cgroup/foo/cgroup.procs); do echo $f > /sys/fs/cgroup/cgroup.procs; done; rmdir /sys/fs/cgroup/foo' runc exec test_cgroups_group sh -uxc 'echo -memory > /sys/fs/cgroup/cgroup.subtree_control; for f in $(cat /sys/fs/cgroup/foo/cgroup.procs); do echo $f > /sys/fs/cgroup/cgroup.procs; done; rmdir /sys/fs/cgroup/foo'
runc exec test_cgroups_group test ! -d /sys/fs/cgroup/foo runc exec test_cgroups_group test ! -d /sys/fs/cgroup/foo
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# #
} }
@test "runc run (cgroup v1 + unified resources should fail)" { @test "runc run (cgroup v1 + unified resources should fail)" {
requires root cgroups_v1 requires root cgroups_v1
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE" set_resources_limit "$BUSYBOX_BUNDLE"
update_config '.linux.resources.unified |= {"memory.min": "131072"}' "$BUSYBOX_BUNDLE" update_config '.linux.resources.unified |= {"memory.min": "131072"}' "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
[[ "$output" == *'invalid configuration'* ]] [[ "$output" == *'invalid configuration'* ]]
} }
@test "runc run (cgroup v2 resources.unified only)" { @test "runc run (cgroup v2 resources.unified only)" {
requires root cgroups_v2 requires root cgroups_v2
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
update_config ' .linux.resources.unified |= { update_config ' .linux.resources.unified |= {
"memory.min": "131072", "memory.min": "131072",
"memory.low": "524288", "memory.low": "524288",
"memory.high": "5242880", "memory.high": "5242880",
@@ -203,38 +203,38 @@ function setup() {
"cpu.max": "10000 100000" "cpu.max": "10000 100000"
}' "$BUSYBOX_BUNDLE" }' "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_cgroups_unified sh -c 'cd /sys/fs/cgroup && grep . *.min *.max *.low *.high' runc exec test_cgroups_unified sh -c 'cd /sys/fs/cgroup && grep . *.min *.max *.low *.high'
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
echo "$output" echo "$output"
echo "$output" | grep -q '^memory.min:131072$' echo "$output" | grep -q '^memory.min:131072$'
echo "$output" | grep -q '^memory.low:524288$' echo "$output" | grep -q '^memory.low:524288$'
echo "$output" | grep -q '^memory.high:5242880$' echo "$output" | grep -q '^memory.high:5242880$'
echo "$output" | grep -q '^memory.max:10485760$' echo "$output" | grep -q '^memory.max:10485760$'
echo "$output" | grep -q '^pids.max:99$' echo "$output" | grep -q '^pids.max:99$'
echo "$output" | grep -q '^cpu.max:10000 100000$' echo "$output" | grep -q '^cpu.max:10000 100000$'
} }
@test "runc run (cgroup v2 resources.unified override)" { @test "runc run (cgroup v2 resources.unified override)" {
requires root cgroups_v2 requires root cgroups_v2
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
update_config ' .linux.resources.memory |= {"limit": 33554432} update_config ' .linux.resources.memory |= {"limit": 33554432}
| .linux.resources.memorySwap |= {"limit": 33554432} | .linux.resources.memorySwap |= {"limit": 33554432}
| .linux.resources.unified |= | .linux.resources.unified |=
{"memory.min": "131072", "memory.max": "10485760" }' \ {"memory.min": "131072", "memory.max": "10485760" }' \
"$BUSYBOX_BUNDLE" "$BUSYBOX_BUNDLE"
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_cgroups_unified cat /sys/fs/cgroup/memory.min runc exec test_cgroups_unified cat /sys/fs/cgroup/memory.min
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = '131072' ] [ "$output" = '131072' ]
runc exec test_cgroups_unified cat /sys/fs/cgroup/memory.max runc exec test_cgroups_unified cat /sys/fs/cgroup/memory.max
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = '10485760' ] [ "$output" = '10485760' ]
} }
+172 -172
View File
@@ -3,22 +3,22 @@
load helpers load helpers
function setup() { function setup() {
# XXX: currently criu require root containers. # XXX: currently criu require root containers.
requires criu root requires criu root
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
teardown_running_container test_busybox_restore teardown_running_container test_busybox_restore
} }
function setup_pipes() { function setup_pipes() {
# The changes to 'terminal' are needed for running in detached mode # The changes to 'terminal' are needed for running in detached mode
# shellcheck disable=SC2016 # shellcheck disable=SC2016
update_config ' (.. | select(.terminal? != null)) .terminal |= false update_config ' (.. | select(.terminal? != null)) .terminal |= false
| (.. | select(.[]? == "sh")) += ["-c", "for i in `seq 10`; do read xxx || continue; echo ponG $xxx; done"]' | (.. | select(.[]? == "sh")) += ["-c", "for i in `seq 10`; do read xxx || continue; echo ponG $xxx; done"]'
# Create three sets of pipes for __runc run. # Create three sets of pipes for __runc run.
@@ -93,28 +93,28 @@ function runc_restore_with_pipes() {
} }
function simple_cr() { function simple_cr() {
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
for _ in $(seq 2); do for _ in $(seq 2); do
# checkpoint the running container # checkpoint the running container
runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox
grep -B 5 Error ./work-dir/dump.log || true grep -B 5 Error ./work-dir/dump.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# after checkpoint busybox is no longer running # after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed testcontainer test_busybox checkpointed
# restore from checkpoint # restore from checkpoint
runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
grep -B 5 Error ./work-dir/restore.log || true grep -B 5 Error ./work-dir/restore.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# busybox should be back up and running # busybox should be back up and running
testcontainer test_busybox running testcontainer test_busybox running
done done
} }
@test "checkpoint and restore " { @test "checkpoint and restore " {
@@ -122,199 +122,199 @@ function simple_cr() {
} }
@test "checkpoint and restore (cgroupns)" { @test "checkpoint and restore (cgroupns)" {
# cgroupv2 already enables cgroupns so this case was tested above already # cgroupv2 already enables cgroupns so this case was tested above already
requires cgroups_v1 cgroupns requires cgroups_v1 cgroupns
# enable CGROUPNS # enable CGROUPNS
update_config '.linux.namespaces += [{"type": "cgroup"}]' update_config '.linux.namespaces += [{"type": "cgroup"}]'
simple_cr simple_cr
} }
@test "checkpoint --pre-dump and restore" { @test "checkpoint --pre-dump and restore" {
setup_pipes setup_pipes
runc_run_with_pipes test_busybox runc_run_with_pipes test_busybox
#test checkpoint pre-dump #test checkpoint pre-dump
mkdir parent-dir mkdir parent-dir
runc --criu "$CRIU" checkpoint --pre-dump --image-path ./parent-dir test_busybox runc --criu "$CRIU" checkpoint --pre-dump --image-path ./parent-dir test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# busybox should still be running # busybox should still be running
testcontainer test_busybox running testcontainer test_busybox running
# checkpoint the running container # checkpoint the running container
mkdir image-dir mkdir image-dir
mkdir work-dir mkdir work-dir
runc --criu "$CRIU" checkpoint --parent-path ./parent-dir --work-path ./work-dir --image-path ./image-dir test_busybox runc --criu "$CRIU" checkpoint --parent-path ./parent-dir --work-path ./work-dir --image-path ./image-dir test_busybox
grep -B 5 Error ./work-dir/dump.log || true grep -B 5 Error ./work-dir/dump.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# after checkpoint busybox is no longer running # after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed testcontainer test_busybox checkpointed
runc_restore_with_pipes ./work-dir test_busybox runc_restore_with_pipes ./work-dir test_busybox
check_pipes check_pipes
} }
@test "checkpoint --lazy-pages and restore" { @test "checkpoint --lazy-pages and restore" {
# check if lazy-pages is supported # check if lazy-pages is supported
run "${CRIU}" check --feature uffd-noncoop run "${CRIU}" check --feature uffd-noncoop
if [ "$status" -eq 1 ]; then if [ "$status" -eq 1 ]; then
skip "this criu does not support lazy migration" skip "this criu does not support lazy migration"
fi fi
setup_pipes setup_pipes
runc_run_with_pipes test_busybox runc_run_with_pipes test_busybox
# checkpoint the running container # checkpoint the running container
mkdir image-dir mkdir image-dir
mkdir work-dir mkdir work-dir
# For lazy migration we need to know when CRIU is ready to serve # For lazy migration we need to know when CRIU is ready to serve
# the memory pages via TCP. # the memory pages via TCP.
exec {pipe}<> <(:) exec {pipe}<> <(:)
# shellcheck disable=SC2094 # shellcheck disable=SC2094
exec {lazy_r}</proc/self/fd/$pipe {lazy_w}>/proc/self/fd/$pipe exec {lazy_r}</proc/self/fd/$pipe {lazy_w}>/proc/self/fd/$pipe
exec {pipe}>&- exec {pipe}>&-
# TCP port for lazy migration # TCP port for lazy migration
port=27277 port=27277
__runc --criu "$CRIU" checkpoint --lazy-pages --page-server 0.0.0.0:${port} --status-fd ${lazy_w} --work-path ./work-dir --image-path ./image-dir test_busybox & __runc --criu "$CRIU" checkpoint --lazy-pages --page-server 0.0.0.0:${port} --status-fd ${lazy_w} --work-path ./work-dir --image-path ./image-dir test_busybox &
cpt_pid=$! cpt_pid=$!
# wait for lazy page server to be ready # 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) out=$(timeout 2 dd if=/proc/self/fd/${lazy_r} bs=1 count=1 2>/dev/null | od)
exec {lazy_w}>&- exec {lazy_w}>&-
# shellcheck disable=SC2116,SC2086 # shellcheck disable=SC2116,SC2086
out=$(echo $out) # rm newlines out=$(echo $out) # rm newlines
# show errors if there are any before we fail # show errors if there are any before we fail
grep -B5 Error ./work-dir/dump.log || true grep -B5 Error ./work-dir/dump.log || true
# expecting \0 which od prints as # expecting \0 which od prints as
[ "$out" = "0000000 000000 0000001" ] [ "$out" = "0000000 000000 0000001" ]
# Check if inventory.img was written # Check if inventory.img was written
[ -e image-dir/inventory.img ] [ -e image-dir/inventory.img ]
# Start CRIU in lazy-daemon mode # Start CRIU in lazy-daemon mode
${CRIU} lazy-pages --page-server --address 127.0.0.1 --port ${port} -D image-dir & ${CRIU} lazy-pages --page-server --address 127.0.0.1 --port ${port} -D image-dir &
lp_pid=$! lp_pid=$!
# Restore lazily from checkpoint. # Restore lazily from checkpoint.
# The restored container needs a different name as the checkpointed # The restored container needs a different name as the checkpointed
# container is not yet destroyed. It is only destroyed at that point # container is not yet destroyed. It is only destroyed at that point
# in time when the last page is lazily transferred to the destination. # in time when the last page is lazily transferred to the destination.
# Killing the CRIU on the checkpoint side will let the container # Killing the CRIU on the checkpoint side will let the container
# continue to run if the migration failed at some point. # continue to run if the migration failed at some point.
runc_restore_with_pipes ./image-dir test_busybox_restore --lazy-pages runc_restore_with_pipes ./image-dir test_busybox_restore --lazy-pages
wait $cpt_pid wait $cpt_pid
wait $lp_pid wait $lp_pid
check_pipes check_pipes
} }
@test "checkpoint and restore in external network namespace" { @test "checkpoint and restore in external network namespace" {
# check if external_net_ns is supported; only with criu 3.10++ # check if external_net_ns is supported; only with criu 3.10++
run "${CRIU}" check --feature external_net_ns run "${CRIU}" check --feature external_net_ns
if [ "$status" -eq 1 ]; then if [ "$status" -eq 1 ]; then
# this criu does not support external_net_ns; skip the test # this criu does not support external_net_ns; skip the test
skip "this criu does not support external network namespaces" skip "this criu does not support external network namespaces"
fi fi
# create a temporary name for the test network namespace # create a temporary name for the test network namespace
tmp=$(mktemp) tmp=$(mktemp)
rm -f "$tmp" rm -f "$tmp"
ns_name=$(basename "$tmp") ns_name=$(basename "$tmp")
# create network namespace # create network namespace
ip netns add "$ns_name" ip netns add "$ns_name"
ns_path=$(ip netns add "$ns_name" 2>&1 | sed -e 's/.*"\(.*\)".*/\1/') ns_path=$(ip netns add "$ns_name" 2>&1 | sed -e 's/.*"\(.*\)".*/\1/')
# shellcheck disable=SC2012 # shellcheck disable=SC2012
ns_inode=$(ls -iL "$ns_path" | awk '{ print $1 }') ns_inode=$(ls -iL "$ns_path" | awk '{ print $1 }')
# tell runc which network namespace to use # tell runc which network namespace to use
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
for _ in $(seq 2); do for _ in $(seq 2); do
# checkpoint the running container; this automatically tells CRIU to # checkpoint the running container; this automatically tells CRIU to
# handle the network namespace defined in config.json as an external # handle the network namespace defined in config.json as an external
runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox
grep -B 5 Error ./work-dir/dump.log || true grep -B 5 Error ./work-dir/dump.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# after checkpoint busybox is no longer running # after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed testcontainer test_busybox checkpointed
# restore from checkpoint; this should restore the container into the existing network namespace # restore from checkpoint; this should restore the container into the existing network namespace
runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
grep -B 5 Error ./work-dir/restore.log || true grep -B 5 Error ./work-dir/restore.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# busybox should be back up and running # busybox should be back up and running
testcontainer test_busybox running testcontainer test_busybox running
# container should be running in same network namespace as before # container should be running in same network namespace as before
pid=$(__runc state test_busybox | jq '.pid') pid=$(__runc state test_busybox | jq '.pid')
ns_inode_new=$(readlink /proc/"$pid"/ns/net | sed -e 's/.*\[\(.*\)\]/\1/') ns_inode_new=$(readlink /proc/"$pid"/ns/net | sed -e 's/.*\[\(.*\)\]/\1/')
echo "old network namespace inode $ns_inode" echo "old network namespace inode $ns_inode"
echo "new network namespace inode $ns_inode_new" echo "new network namespace inode $ns_inode_new"
[ "$ns_inode" -eq "$ns_inode_new" ] [ "$ns_inode" -eq "$ns_inode_new" ]
done done
ip netns del "$ns_name" ip netns del "$ns_name"
} }
@test "checkpoint and restore with container specific CRIU config" { @test "checkpoint and restore with container specific CRIU config" {
tmp=$(mktemp /tmp/runc-criu-XXXXXX.conf) tmp=$(mktemp /tmp/runc-criu-XXXXXX.conf)
# This is the file we write to /etc/criu/default.conf # This is the file we write to /etc/criu/default.conf
tmplog1=$(mktemp /tmp/runc-criu-log-XXXXXX.log) tmplog1=$(mktemp /tmp/runc-criu-log-XXXXXX.log)
unlink "$tmplog1" unlink "$tmplog1"
tmplog1=$(basename "$tmplog1") tmplog1=$(basename "$tmplog1")
# That is the actual configuration file to be used # That is the actual configuration file to be used
tmplog2=$(mktemp /tmp/runc-criu-log-XXXXXX.log) tmplog2=$(mktemp /tmp/runc-criu-log-XXXXXX.log)
unlink "$tmplog2" unlink "$tmplog2"
tmplog2=$(basename "$tmplog2") tmplog2=$(basename "$tmplog2")
# This adds the annotation 'org.criu.config' to set a container # This adds the annotation 'org.criu.config' to set a container
# specific CRIU config file. # specific CRIU config file.
update_config '.annotations += {"org.criu.config": "'"$tmp"'"}' update_config '.annotations += {"org.criu.config": "'"$tmp"'"}'
# Tell CRIU to use another configuration file # Tell CRIU to use another configuration file
mkdir -p /etc/criu mkdir -p /etc/criu
echo "log-file=$tmplog1" > /etc/criu/default.conf echo "log-file=$tmplog1" >/etc/criu/default.conf
# Make sure the RPC defined configuration file overwrites the previous # Make sure the RPC defined configuration file overwrites the previous
echo "log-file=$tmplog2" > "$tmp" echo "log-file=$tmplog2" >"$tmp"
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
# checkpoint the running container # checkpoint the running container
runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox
grep -B 5 Error ./work-dir/dump.log || true grep -B 5 Error ./work-dir/dump.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
! test -f ./work-dir/"$tmplog1" ! test -f ./work-dir/"$tmplog1"
test -f ./work-dir/"$tmplog2" test -f ./work-dir/"$tmplog2"
# after checkpoint busybox is no longer running # after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed testcontainer test_busybox checkpointed
test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2" test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2"
# restore from checkpoint # restore from checkpoint
runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
grep -B 5 Error ./work-dir/restore.log || true grep -B 5 Error ./work-dir/restore.log || true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
! test -f ./work-dir/"$tmplog1" ! test -f ./work-dir/"$tmplog1"
test -f ./work-dir/"$tmplog2" test -f ./work-dir/"$tmplog2"
# busybox should be back up and running # busybox should be back up and running
testcontainer test_busybox running testcontainer test_busybox running
unlink "$tmp" unlink "$tmp"
test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2" test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2"
} }
+49 -49
View File
@@ -3,87 +3,87 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "runc create" { @test "runc create" {
runc create --console-socket "$CONSOLE_SOCKET" test_busybox runc create --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox created testcontainer test_busybox created
# start the command # start the command
runc start test_busybox runc start test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc create exec" { @test "runc create exec" {
runc create --console-socket "$CONSOLE_SOCKET" test_busybox runc create --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox created testcontainer test_busybox created
runc exec test_busybox true runc exec test_busybox true
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox created testcontainer test_busybox created
# start the command # start the command
runc start test_busybox runc start test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc create --pid-file" { @test "runc create --pid-file" {
runc create --pid-file pid.txt --console-socket "$CONSOLE_SOCKET" test_busybox runc create --pid-file pid.txt --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox created testcontainer test_busybox created
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]] [[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
# start the command # start the command
runc start test_busybox runc start test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc create --pid-file with new CWD" { @test "runc create --pid-file with new CWD" {
# create pid_file directory as the CWD # create pid_file directory as the CWD
run mkdir pid_file run mkdir pid_file
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run cd pid_file run cd pid_file
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox created testcontainer test_busybox created
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]] [[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
# start the command # start the command
runc start test_busybox runc start test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
} }
+50 -50
View File
@@ -3,79 +3,79 @@
load helpers load helpers
function setup() { function setup() {
teardown_hello teardown_hello
setup_hello setup_hello
} }
function teardown() { function teardown() {
teardown_hello teardown_hello
} }
@test "global --debug" { @test "global --debug" {
# run hello-world # run hello-world
runc --debug run test_hello runc --debug run test_hello
echo "${output}" echo "${output}"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check expected debug output was sent to stderr # check expected debug output was sent to stderr
[[ "${output}" == *"level=debug"* ]] [[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]] [[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]] [[ "${output}" == *"child process in init()"* ]]
} }
@test "global --debug to --log" { @test "global --debug to --log" {
# run hello-world # run hello-world
runc --log log.out --debug run test_hello runc --log log.out --debug run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check output does not include debug info # check output does not include debug info
[[ "${output}" != *"level=debug"* ]] [[ "${output}" != *"level=debug"* ]]
# check log.out was generated # check log.out was generated
[ -e log.out ] [ -e log.out ]
# check expected debug output was sent to log.out # check expected debug output was sent to log.out
run cat log.out run cat log.out
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"level=debug"* ]] [[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]] [[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]] [[ "${output}" == *"child process in init()"* ]]
} }
@test "global --debug to --log --log-format 'text'" { @test "global --debug to --log --log-format 'text'" {
# run hello-world # run hello-world
runc --log log.out --log-format "text" --debug run test_hello runc --log log.out --log-format "text" --debug run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check output does not include debug info # check output does not include debug info
[[ "${output}" != *"level=debug"* ]] [[ "${output}" != *"level=debug"* ]]
# check log.out was generated # check log.out was generated
[ -e log.out ] [ -e log.out ]
# check expected debug output was sent to log.out # check expected debug output was sent to log.out
run cat log.out run cat log.out
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"level=debug"* ]] [[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]] [[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]] [[ "${output}" == *"child process in init()"* ]]
} }
@test "global --debug to --log --log-format 'json'" { @test "global --debug to --log --log-format 'json'" {
# run hello-world # run hello-world
runc --log log.out --log-format "json" --debug run test_hello runc --log log.out --log-format "json" --debug run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check output does not include debug info # check output does not include debug info
[[ "${output}" != *"level=debug"* ]] [[ "${output}" != *"level=debug"* ]]
# check log.out was generated # check log.out was generated
[ -e log.out ] [ -e log.out ]
# check expected debug output was sent to log.out # check expected debug output was sent to log.out
run cat log.out run cat log.out
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *'"level":"debug"'* ]] [[ "${output}" == *'"level":"debug"'* ]]
[[ "${output}" == *"nsexec started"* ]] [[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]] [[ "${output}" == *"child process in init()"* ]]
} }
+83 -83
View File
@@ -3,78 +3,78 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
teardown_running_container testbusyboxdelete teardown_running_container testbusyboxdelete
} }
@test "runc delete" { @test "runc delete" {
runc run -d --console-socket "$CONSOLE_SOCKET" testbusyboxdelete runc run -d --console-socket "$CONSOLE_SOCKET" testbusyboxdelete
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer testbusyboxdelete running testcontainer testbusyboxdelete running
runc kill testbusyboxdelete KILL runc kill testbusyboxdelete KILL
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
retry 10 1 eval "__runc state testbusyboxdelete | grep -q 'stopped'" retry 10 1 eval "__runc state testbusyboxdelete | grep -q 'stopped'"
runc delete testbusyboxdelete runc delete testbusyboxdelete
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc state testbusyboxdelete runc state testbusyboxdelete
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output" [ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
} }
@test "runc delete --force" { @test "runc delete --force" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
# force delete test_busybox # force delete test_busybox
runc delete --force test_busybox runc delete --force test_busybox
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@test "runc delete --force ignore not exist" { @test "runc delete --force ignore not exist" {
runc delete --force notexists runc delete --force notexists
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "runc delete --force in cgroupv1 with subcgroups" { @test "runc delete --force in cgroupv1 with subcgroups" {
requires cgroups_v1 root cgroupns requires cgroups_v1 root cgroupns
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE" set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
# enable cgroupns # enable cgroupns
update_config '.linux.namespaces += [{"type": "cgroup"}]' update_config '.linux.namespaces += [{"type": "cgroup"}]'
local subsystems="memory freezer" local subsystems="memory freezer"
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
__runc exec -d test_busybox sleep 1d __runc exec -d test_busybox sleep 1d
# find the pid of sleep # find the pid of sleep
pid=$(__runc exec test_busybox ps -a | grep 1d | awk '{print $1}') pid=$(__runc exec test_busybox ps -a | grep 1d | awk '{print $1}')
[[ ${pid} =~ [0-9]+ ]] [[ ${pid} =~ [0-9]+ ]]
# create a sub-cgroup # create a sub-cgroup
cat <<EOF | runc exec test_busybox sh cat <<EOF | runc exec test_busybox sh
set -e -u -x set -e -u -x
for s in ${subsystems}; do for s in ${subsystems}; do
cd /sys/fs/cgroup/\$s cd /sys/fs/cgroup/\$s
@@ -84,47 +84,47 @@ for s in ${subsystems}; do
cat tasks cat tasks
done done
EOF EOF
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" =~ [0-9]+ ]] [[ "$output" =~ [0-9]+ ]]
for s in ${subsystems}; do for s in ${subsystems}; do
name=CGROUP_${s^^} name=CGROUP_${s^^}
eval path=\$"${name}"/foo eval path=\$"${name}"/foo
# shellcheck disable=SC2154 # shellcheck disable=SC2154
[ -d "${path}" ] || fail "test failed to create memory sub-cgroup ($path not found)" [ -d "${path}" ] || fail "test failed to create memory sub-cgroup ($path not found)"
done done
runc delete --force test_busybox runc delete --force test_busybox
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output" [ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
} }
@test "runc delete --force in cgroupv2 with subcgroups" { @test "runc delete --force in cgroupv2 with subcgroups" {
requires cgroups_v2 root requires cgroups_v2 root
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE" set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
# create a sub process # create a sub process
__runc exec -d test_busybox sleep 1d __runc exec -d test_busybox sleep 1d
# find the pid of sleep # find the pid of sleep
pid=$(__runc exec test_busybox ps -a | grep 1d | awk '{print $1}') pid=$(__runc exec test_busybox ps -a | grep 1d | awk '{print $1}')
[[ ${pid} =~ [0-9]+ ]] [[ ${pid} =~ [0-9]+ ]]
# create subcgroups # create subcgroups
cat <<EOF > nest.sh cat <<EOF >nest.sh
set -e -u -x set -e -u -x
cd /sys/fs/cgroup cd /sys/fs/cgroup
echo +pids > cgroup.subtree_control echo +pids > cgroup.subtree_control
@@ -134,19 +134,19 @@ EOF
echo ${pid} > cgroup.threads echo ${pid} > cgroup.threads
cat cgroup.threads cat cgroup.threads
EOF EOF
runc exec test_busybox sh < nest.sh runc exec test_busybox sh <nest.sh
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" =~ [0-9]+ ]] [[ "$output" =~ [0-9]+ ]]
# check create subcgroups success # check create subcgroups success
[ -d "$CGROUP_PATH"/foo ] [ -d "$CGROUP_PATH"/foo ]
# force delete test_busybox # force delete test_busybox
runc delete --force test_busybox runc delete --force test_busybox
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
# check delete subcgroups success # check delete subcgroups success
[ ! -d "$CGROUP_PATH"/foo ] [ ! -d "$CGROUP_PATH"/foo ]
} }
+99 -99
View File
@@ -3,140 +3,140 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "events --stats" { @test "events --stats" {
# XXX: currently cgroups require root containers. # XXX: currently cgroups require root containers.
requires root requires root
init_cgroup_paths init_cgroup_paths
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# generate stats # generate stats
runc events --stats test_busybox runc events --stats test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]] [[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
[[ "${lines[0]}" == *"data"* ]] [[ "${lines[0]}" == *"data"* ]]
} }
@test "events --interval default" { @test "events --interval default" {
# XXX: currently cgroups require root containers. # XXX: currently cgroups require root containers.
requires root requires root
init_cgroup_paths init_cgroup_paths
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# spawn two sub processes (shells) # spawn two sub processes (shells)
# the first sub process is an event logger that sends stats events to events.log # the first sub process is an event logger that sends stats events to events.log
# the second sub process waits for an event that includes test_busybox then # the second sub process waits for an event that includes test_busybox then
# kills the test_busybox container which causes the event logger to exit # kills the test_busybox container which causes the event logger to exit
(__runc events test_busybox > events.log) & (__runc events test_busybox >events.log) &
( (
retry 10 1 eval "grep -q 'test_busybox' events.log" retry 10 1 eval "grep -q 'test_busybox' events.log"
teardown_running_container test_busybox teardown_running_container test_busybox
) & ) &
wait # wait for the above sub shells to finish wait # wait for the above sub shells to finish
[ -e events.log ] [ -e events.log ]
run cat events.log run cat events.log
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]] [[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
[[ "${lines[0]}" == *"data"* ]] [[ "${lines[0]}" == *"data"* ]]
} }
@test "events --interval 1s" { @test "events --interval 1s" {
# XXX: currently cgroups require root containers. # XXX: currently cgroups require root containers.
requires root requires root
init_cgroup_paths init_cgroup_paths
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# spawn two sub processes (shells) # spawn two sub processes (shells)
# the first sub process is an event logger that sends stats events to events.log once a second # the first sub process is an event logger that sends stats events to events.log once a second
# the second sub process tries 3 times for an event that incudes test_busybox # the second sub process tries 3 times for an event that incudes test_busybox
# pausing 1s between each attempt then kills the test_busybox container which # pausing 1s between each attempt then kills the test_busybox container which
# causes the event logger to exit # causes the event logger to exit
(__runc events --interval 1s test_busybox > events.log) & (__runc events --interval 1s test_busybox >events.log) &
( (
retry 3 1 eval "grep -q 'test_busybox' events.log" retry 3 1 eval "grep -q 'test_busybox' events.log"
teardown_running_container test_busybox teardown_running_container test_busybox
) & ) &
wait # wait for the above sub shells to finish wait # wait for the above sub shells to finish
[ -e events.log ] [ -e events.log ]
run eval "grep -q 'test_busybox' events.log" run eval "grep -q 'test_busybox' events.log"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "events --interval 100ms" { @test "events --interval 100ms" {
# XXX: currently cgroups require root containers. # XXX: currently cgroups require root containers.
requires root requires root
init_cgroup_paths init_cgroup_paths
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
#prove there is no carry over of events.log from a prior test #prove there is no carry over of events.log from a prior test
[ ! -e events.log ] [ ! -e events.log ]
# spawn two sub processes (shells) # spawn two sub processes (shells)
# the first sub process is an event logger that sends stats events to events.log once every 100ms # the first sub process is an event logger that sends stats events to events.log once every 100ms
# the second sub process tries 3 times for an event that incudes test_busybox # the second sub process tries 3 times for an event that incudes test_busybox
# pausing 100s between each attempt then kills the test_busybox container which # pausing 100s between each attempt then kills the test_busybox container which
# causes the event logger to exit # causes the event logger to exit
(__runc events --interval 100ms test_busybox > events.log) & (__runc events --interval 100ms test_busybox >events.log) &
( (
retry 3 0.100 eval "grep -q 'test_busybox' events.log" retry 3 0.100 eval "grep -q 'test_busybox' events.log"
teardown_running_container test_busybox teardown_running_container test_busybox
) & ) &
wait # wait for the above sub shells to finish wait # wait for the above sub shells to finish
[ -e events.log ] [ -e events.log ]
run eval "grep -q 'test_busybox' events.log" run eval "grep -q 'test_busybox' events.log"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "events oom" { @test "events oom" {
# XXX: currently cgroups require root containers. # XXX: currently cgroups require root containers.
requires root cgroups_swap requires root cgroups_swap
init_cgroup_paths init_cgroup_paths
# we need the container to hit OOM, so disable swap # we need the container to hit OOM, so disable swap
update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}' "${BUSYBOX_BUNDLE}" update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}' "${BUSYBOX_BUNDLE}"
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# spawn two sub processes (shells) # spawn two sub processes (shells)
# the first sub process is an event logger that sends stats events to events.log # the first sub process is an event logger that sends stats events to events.log
# the second sub process exec a memory hog process to cause a oom condition # the second sub process exec a memory hog process to cause a oom condition
# and waits for an oom event # and waits for an oom event
(__runc events test_busybox > events.log) & (__runc events test_busybox >events.log) &
( (
retry 10 1 eval "grep -q 'test_busybox' events.log" retry 10 1 eval "grep -q 'test_busybox' events.log"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
__runc exec -d test_busybox sh -c 'test=$(dd if=/dev/urandom ibs=5120k)' __runc exec -d test_busybox sh -c 'test=$(dd if=/dev/urandom ibs=5120k)'
retry 10 1 eval "grep -q 'oom' events.log" retry 10 1 eval "grep -q 'oom' events.log"
__runc delete -f test_busybox __runc delete -f test_busybox
) & ) &
wait # wait for the above sub shells to finish wait # wait for the above sub shells to finish
grep -q '{"type":"oom","id":"test_busybox"}' events.log grep -q '{"type":"oom","id":"test_busybox"}' events.log
} }
+83 -83
View File
@@ -3,138 +3,138 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "runc exec" { @test "runc exec" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_busybox echo Hello from exec runc exec test_busybox echo Hello from exec
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
echo text echoed = "'""${output}""'" echo text echoed = "'""${output}""'"
[[ "${output}" == *"Hello from exec"* ]] [[ "${output}" == *"Hello from exec"* ]]
} }
@test "runc exec --pid-file" { @test "runc exec --pid-file" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec --pid-file pid.txt test_busybox echo Hello from exec runc exec --pid-file pid.txt test_busybox echo Hello from exec
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
echo text echoed = "'""${output}""'" echo text echoed = "'""${output}""'"
[[ "${output}" == *"Hello from exec"* ]] [[ "${output}" == *"Hello from exec"* ]]
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]] [[ ${lines[0]} =~ [0-9]+ ]]
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]] [[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
} }
@test "runc exec --pid-file with new CWD" { @test "runc exec --pid-file with new CWD" {
# create pid_file directory as the CWD # create pid_file directory as the CWD
run mkdir pid_file run mkdir pid_file
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run cd pid_file run cd pid_file
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# run busybox detached # run busybox detached
runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec --pid-file pid.txt test_busybox echo Hello from exec runc exec --pid-file pid.txt test_busybox echo Hello from exec
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
echo text echoed = "'""${output}""'" echo text echoed = "'""${output}""'"
[[ "${output}" == *"Hello from exec"* ]] [[ "${output}" == *"Hello from exec"* ]]
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]] [[ ${lines[0]} =~ [0-9]+ ]]
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]] [[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
} }
@test "runc exec ls -la" { @test "runc exec ls -la" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec test_busybox ls -la runc exec test_busybox ls -la
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == *"total"* ]] [[ ${lines[0]} == *"total"* ]]
[[ ${lines[1]} == *"."* ]] [[ ${lines[1]} == *"."* ]]
[[ ${lines[2]} == *".."* ]] [[ ${lines[2]} == *".."* ]]
} }
@test "runc exec ls -la with --cwd" { @test "runc exec ls -la with --cwd" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec --cwd /bin test_busybox pwd runc exec --cwd /bin test_busybox pwd
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${output} == "/bin"* ]] [[ ${output} == "/bin"* ]]
} }
@test "runc exec --env" { @test "runc exec --env" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec --env RUNC_EXEC_TEST=true test_busybox env runc exec --env RUNC_EXEC_TEST=true test_busybox env
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${output} == *"RUNC_EXEC_TEST=true"* ]] [[ ${output} == *"RUNC_EXEC_TEST=true"* ]]
} }
@test "runc exec --user" { @test "runc exec --user" {
# --user can't work in rootless containers that don't have idmap. # --user can't work in rootless containers that don't have idmap.
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc exec --user 1000:1000 test_busybox id runc exec --user 1000:1000 test_busybox id
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == "uid=1000 gid=1000"* ]] [[ "${output}" == "uid=1000 gid=1000"* ]]
} }
@test "runc exec --additional-gids" { @test "runc exec --additional-gids" {
requires root requires root
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox wait_for_container 15 1 test_busybox
runc exec --user 1000:1000 --additional-gids 100 --additional-gids 65534 test_busybox id -G runc exec --user 1000:1000 --additional-gids 100 --additional-gids 65534 test_busybox id -G
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${output} == "1000 100 65534" ]] [[ ${output} == "1000 100 65534" ]]
} }
@test "runc exec --preserve-fds" { @test "runc exec --preserve-fds" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run bash -c "cat hello > preserve-fds.test; exec 3<preserve-fds.test; $RUNC ${RUNC_USE_SYSTEMD:+--systemd-cgroup} --log /proc/self/fd/2 --root $ROOT exec --preserve-fds=1 test_busybox cat /proc/self/fd/3" run bash -c "cat hello > preserve-fds.test; exec 3<preserve-fds.test; $RUNC ${RUNC_USE_SYSTEMD:+--systemd-cgroup} --log /proc/self/fd/2 --root $ROOT exec --preserve-fds=1 test_busybox cat /proc/self/fd/3"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"hello"* ]] [[ "${output}" == *"hello"* ]]
} }
+59 -59
View File
@@ -3,85 +3,85 @@
load helpers load helpers
@test "runc -h" { @test "runc -h" {
runc -h runc -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ NAME:+ ]] [[ ${lines[0]} =~ NAME:+ ]]
[[ ${lines[1]} =~ runc\ '-'\ Open\ Container\ Initiative\ runtime+ ]] [[ ${lines[1]} =~ runc\ '-'\ Open\ Container\ Initiative\ runtime+ ]]
runc --help runc --help
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ NAME:+ ]] [[ ${lines[0]} =~ NAME:+ ]]
[[ ${lines[1]} =~ runc\ '-'\ Open\ Container\ Initiative\ runtime+ ]] [[ ${lines[1]} =~ runc\ '-'\ Open\ Container\ Initiative\ runtime+ ]]
} }
@test "runc command -h" { @test "runc command -h" {
runc checkpoint -h runc checkpoint -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ checkpoint+ ]] [[ ${lines[1]} =~ runc\ checkpoint+ ]]
runc delete -h runc delete -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ delete+ ]] [[ ${lines[1]} =~ runc\ delete+ ]]
runc events -h runc events -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ events+ ]] [[ ${lines[1]} =~ runc\ events+ ]]
runc exec -h runc exec -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ exec+ ]] [[ ${lines[1]} =~ runc\ exec+ ]]
runc kill -h runc kill -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ kill+ ]] [[ ${lines[1]} =~ runc\ kill+ ]]
runc list -h runc list -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ NAME:+ ]] [[ ${lines[0]} =~ NAME:+ ]]
[[ ${lines[1]} =~ runc\ list+ ]] [[ ${lines[1]} =~ runc\ list+ ]]
runc list --help runc list --help
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ NAME:+ ]] [[ ${lines[0]} =~ NAME:+ ]]
[[ ${lines[1]} =~ runc\ list+ ]] [[ ${lines[1]} =~ runc\ list+ ]]
runc pause -h runc pause -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ pause+ ]] [[ ${lines[1]} =~ runc\ pause+ ]]
runc restore -h runc restore -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ restore+ ]] [[ ${lines[1]} =~ runc\ restore+ ]]
runc resume -h runc resume -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ resume+ ]] [[ ${lines[1]} =~ runc\ resume+ ]]
# We don't use runc_spec here, because we're just testing the help page. # We don't use runc_spec here, because we're just testing the help page.
runc spec -h runc spec -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ spec+ ]] [[ ${lines[1]} =~ runc\ spec+ ]]
runc start -h runc start -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ start+ ]] [[ ${lines[1]} =~ runc\ start+ ]]
runc run -h runc run -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ run+ ]] [[ ${lines[1]} =~ runc\ run+ ]]
runc state -h runc state -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ state+ ]] [[ ${lines[1]} =~ runc\ state+ ]]
runc update -h runc update -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ update+ ]] [[ ${lines[1]} =~ runc\ update+ ]]
} }
@test "runc foo -h" { @test "runc foo -h" {
runc foo -h runc foo -h
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
[[ "${output}" == *"No help topic for 'foo'"* ]] [[ "${output}" == *"No help topic for 'foo'"* ]]
} }
+12 -11
View File
@@ -9,16 +9,16 @@ HOOKLIBCC=librunc-hooks-create-container.so
LIBPATH="$DEBIAN_BUNDLE/rootfs/lib/" LIBPATH="$DEBIAN_BUNDLE/rootfs/lib/"
function setup() { function setup() {
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &> /dev/null || true umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &> /dev/null || true umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
teardown_debian teardown_debian
setup_debian setup_debian
} }
function teardown() { function teardown() {
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &> /dev/null || true umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &> /dev/null || true umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
rm -f $HOOKLIBCR.1.0.0 $HOOKLIBCC.1.0.0 rm -f $HOOKLIBCR.1.0.0 $HOOKLIBCC.1.0.0
teardown_debian teardown_debian
@@ -35,12 +35,13 @@ function teardown() {
current_pwd="$(pwd)" current_pwd="$(pwd)"
# To mount $HOOKLIBCR we need to do that in the container namespace # To mount $HOOKLIBCR we need to do that in the container namespace
create_runtime_hook=$(cat <<-EOF create_runtime_hook=$(
pid=\$(cat - | jq -r '.pid') cat <<-EOF
touch "$LIBPATH/$HOOKLIBCR.1.0.0" pid=\$(cat - | jq -r '.pid')
nsenter -m \$ns -t \$pid mount --bind "$current_pwd/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0" touch "$LIBPATH/$HOOKLIBCR.1.0.0"
EOF nsenter -m \$ns -t \$pid mount --bind "$current_pwd/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0"
) EOF
)
create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $current_pwd/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0" create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $current_pwd/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0"
@@ -49,7 +50,7 @@ EOF
.hooks |= . + {"createContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_container_hook]}]} | .hooks |= . + {"createContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_container_hook]}]} |
.hooks |= . + {"startContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "ldconfig"]}]} | .hooks |= . + {"startContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "ldconfig"]}]} |
.process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' "$DEBIAN_BUNDLE"/config.json) .process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' "$DEBIAN_BUNDLE"/config.json)
echo "${CONFIG}" > config.json echo "${CONFIG}" >config.json
runc run test_debian runc run test_debian
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
+16 -17
View File
@@ -3,32 +3,31 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "kill detached busybox" { @test "kill detached busybox" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
runc kill test_busybox KILL runc kill test_busybox KILL
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'" retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
# we should ensure kill work after the container stopped # we should ensure kill work after the container stopped
runc kill -a test_busybox 0 runc kill -a test_busybox 0
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc delete test_busybox runc delete test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
+38 -38
View File
@@ -3,54 +3,54 @@
load helpers load helpers
function setup() { function setup() {
teardown_running_container_inroot test_box1 "$HELLO_BUNDLE" teardown_running_container_inroot test_box1 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box2 "$HELLO_BUNDLE" teardown_running_container_inroot test_box2 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box3 "$HELLO_BUNDLE" teardown_running_container_inroot test_box3 "$HELLO_BUNDLE"
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_running_container_inroot test_box1 "$HELLO_BUNDLE" teardown_running_container_inroot test_box1 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box2 "$HELLO_BUNDLE" teardown_running_container_inroot test_box2 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box3 "$HELLO_BUNDLE" teardown_running_container_inroot test_box3 "$HELLO_BUNDLE"
teardown_busybox teardown_busybox
} }
@test "list" { @test "list" {
# run a few busyboxes detached # run a few busyboxes detached
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box1 ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box2 ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box3 ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc list ROOT=$HELLO_BUNDLE runc list
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]] [[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]] [[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]] [[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]] [[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
ROOT=$HELLO_BUNDLE runc list -q ROOT=$HELLO_BUNDLE runc list -q
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${lines[0]}" == "test_box1" ]] [[ "${lines[0]}" == "test_box1" ]]
[[ "${lines[1]}" == "test_box2" ]] [[ "${lines[1]}" == "test_box2" ]]
[[ "${lines[2]}" == "test_box3" ]] [[ "${lines[2]}" == "test_box3" ]]
ROOT=$HELLO_BUNDLE runc list --format table ROOT=$HELLO_BUNDLE runc list --format table
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]] [[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]] [[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]] [[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]] [[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
ROOT=$HELLO_BUNDLE runc list --format json ROOT=$HELLO_BUNDLE runc list --format json
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]] [[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]] [[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]] [[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
} }
+1 -1
View File
@@ -8,7 +8,7 @@ function setup() {
# Create fake rootfs. # Create fake rootfs.
mkdir rootfs/testdir mkdir rootfs/testdir
echo "Forbidden information!" > rootfs/testfile echo "Forbidden information!" >rootfs/testfile
# add extra masked paths # add extra masked paths
update_config '(.. | select(.maskedPaths? != null)) .maskedPaths += ["/testdir", "/testfile"]' update_config '(.. | select(.maskedPaths? != null)) .maskedPaths += ["/testdir", "/testfile"]'
+1 -1
View File
@@ -13,7 +13,7 @@ function teardown() {
} }
@test "runc run [bind mount]" { @test "runc run [bind mount]" {
update_config ' .mounts += [{"source": ".", "destination": "/tmp/bind", "options": ["bind"]}] update_config ' .mounts += [{"source": ".", "destination": "/tmp/bind", "options": ["bind"]}]
| .process.args |= ["ls", "/tmp/bind/config.json"]' | .process.args |= ["ls", "/tmp/bind/config.json"]'
runc run test_bind_mount runc run test_bind_mount
+49 -51
View File
@@ -3,78 +3,76 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "runc pause and resume" { @test "runc pause and resume" {
if [[ "$ROOTLESS" -ne 0 ]] if [[ "$ROOTLESS" -ne 0 ]]; then
then requires rootless_cgroup
requires rootless_cgroup set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path "$BUSYBOX_BUNDLE" fi
fi requires cgroups_freezer
requires cgroups_freezer
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
# pause busybox # pause busybox
runc pause test_busybox runc pause test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# test state of busybox is paused # test state of busybox is paused
testcontainer test_busybox paused testcontainer test_busybox paused
# resume busybox # resume busybox
runc resume test_busybox runc resume test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# test state of busybox is back to running # test state of busybox is back to running
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc pause and resume with nonexist container" { @test "runc pause and resume with nonexist container" {
if [[ "$ROOTLESS" -ne 0 ]] if [[ "$ROOTLESS" -ne 0 ]]; then
then requires rootless_cgroup
requires rootless_cgroup set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path "$BUSYBOX_BUNDLE" fi
fi requires cgroups_freezer
requires cgroups_freezer
# run test_busybox detached # run test_busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
# pause test_busybox and nonexistent container # pause test_busybox and nonexistent container
runc pause test_busybox runc pause test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc pause nonexistent runc pause nonexistent
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
# test state of test_busybox is paused # test state of test_busybox is paused
testcontainer test_busybox paused testcontainer test_busybox paused
# resume test_busybox and nonexistent container # resume test_busybox and nonexistent container
runc resume test_busybox runc resume test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc resume nonexistent runc resume nonexistent
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
# test state of test_busybox is back to running # test state of test_busybox is back to running
testcontainer test_busybox running testcontainer test_busybox running
# delete test_busybox # delete test_busybox
runc delete --force test_busybox runc delete --force test_busybox
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
+50 -50
View File
@@ -3,84 +3,84 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "ps" { @test "ps" {
# ps is not supported, it requires cgroups # ps is not supported, it requires cgroups
requires root requires root
# start busybox detached # start busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
runc ps test_busybox runc ps test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]] [[ ${lines[0]} =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]]
[[ "${lines[1]}" == *"$(id -un 2>/dev/null)"*[0-9]* ]] [[ "${lines[1]}" == *"$(id -un 2>/dev/null)"*[0-9]* ]]
} }
@test "ps -f json" { @test "ps -f json" {
# ps is not supported, it requires cgroups # ps is not supported, it requires cgroups
requires root requires root
# start busybox detached # start busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
runc ps -f json test_busybox runc ps -f json test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]] [[ ${lines[0]} =~ [0-9]+ ]]
} }
@test "ps -e -x" { @test "ps -e -x" {
# ps is not supported, it requires cgroups # ps is not supported, it requires cgroups
requires root requires root
# start busybox detached # start busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
runc ps test_busybox -e -x runc ps test_busybox -e -x
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ \ +PID\ +TTY\ +STAT\ +TIME\ +COMMAND+ ]] [[ ${lines[0]} =~ \ +PID\ +TTY\ +STAT\ +TIME\ +COMMAND+ ]]
[[ "${lines[1]}" =~ [0-9]+ ]] [[ "${lines[1]}" =~ [0-9]+ ]]
} }
@test "ps after the container stopped" { @test "ps after the container stopped" {
# ps requires cgroups # ps requires cgroups
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
# start busybox detached # start busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
runc ps test_busybox runc ps test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc kill test_busybox KILL runc kill test_busybox KILL
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'" retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
runc ps test_busybox runc ps test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
+31 -31
View File
@@ -3,48 +3,48 @@
load helpers load helpers
function setup() { function setup() {
teardown_running_container_inroot test_dotbox "$HELLO_BUNDLE" teardown_running_container_inroot test_dotbox "$HELLO_BUNDLE"
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_running_container_inroot test_dotbox "$HELLO_BUNDLE" teardown_running_container_inroot test_dotbox "$HELLO_BUNDLE"
teardown_busybox teardown_busybox
} }
@test "global --root" { @test "global --root" {
# run busybox detached using $HELLO_BUNDLE for state # run busybox detached using $HELLO_BUNDLE for state
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_dotbox ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_dotbox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# run busybox detached in default root # run busybox detached in default root
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc state test_busybox runc state test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]] [[ "${output}" == *"running"* ]]
ROOT=$HELLO_BUNDLE runc state test_dotbox ROOT=$HELLO_BUNDLE runc state test_dotbox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]] [[ "${output}" == *"running"* ]]
ROOT=$HELLO_BUNDLE runc state test_busybox ROOT=$HELLO_BUNDLE runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
runc state test_dotbox runc state test_dotbox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
runc kill test_busybox KILL runc kill test_busybox KILL
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'" retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
runc delete test_busybox runc delete test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc kill test_dotbox KILL ROOT=$HELLO_BUNDLE runc kill test_dotbox KILL
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
retry 10 1 eval "ROOT='$HELLO_BUNDLE' __runc state test_dotbox | grep -q 'stopped'" retry 10 1 eval "ROOT='$HELLO_BUNDLE' __runc state test_dotbox | grep -q 'stopped'"
ROOT=$HELLO_BUNDLE runc delete test_dotbox ROOT=$HELLO_BUNDLE runc delete test_dotbox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
+2 -2
View File
@@ -25,11 +25,11 @@ function teardown() {
SPEC_VERSION=$(awk '$1 == "github.com/opencontainers/runtime-spec" {print $2}' "$BATS_TEST_DIRNAME"/../../go.mod) SPEC_VERSION=$(awk '$1 == "github.com/opencontainers/runtime-spec" {print $2}' "$BATS_TEST_DIRNAME"/../../go.mod)
# Will look like this when not pinned to specific tag: "v0.0.0-20190207185410-29686dbc5559", otherwise "v1.0.0" # Will look like this when not pinned to specific tag: "v0.0.0-20190207185410-29686dbc5559", otherwise "v1.0.0"
SPEC_COMMIT=$(cut -d "-" -f 3 <<< "$SPEC_VERSION") SPEC_COMMIT=$(cut -d "-" -f 3 <<<"$SPEC_VERSION")
SPEC_REF=$([[ -z "$SPEC_COMMIT" ]] && echo "$SPEC_VERSION" || echo "$SPEC_COMMIT") SPEC_REF=$([[ -z "$SPEC_COMMIT" ]] && echo "$SPEC_VERSION" || echo "$SPEC_COMMIT")
git clone https://github.com/opencontainers/runtime-spec.git git clone https://github.com/opencontainers/runtime-spec.git
( cd runtime-spec && git reset --hard "$SPEC_REF" ) (cd runtime-spec && git reset --hard "$SPEC_REF")
SCHEMA='runtime-spec/schema/config-schema.json' SCHEMA='runtime-spec/schema/config-schema.json'
[ -e "$SCHEMA" ] [ -e "$SCHEMA" ]
+14 -14
View File
@@ -3,29 +3,29 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "runc start" { @test "runc start" {
runc create --console-socket "$CONSOLE_SOCKET" test_busybox runc create --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox created testcontainer test_busybox created
# start container test_busybox # start container test_busybox
runc start test_busybox runc start test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
testcontainer test_busybox running testcontainer test_busybox running
# delete test_busybox # delete test_busybox
runc delete --force test_busybox runc delete --force test_busybox
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
+43 -43
View File
@@ -3,74 +3,74 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "runc run detached" { @test "runc run detached" {
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc run detached ({u,g}id != 0)" { @test "runc run detached ({u,g}id != 0)" {
# cannot start containers as another user in rootless setup without idmap # cannot start containers as another user in rootless setup without idmap
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap
# replace "uid": 0 with "uid": 1000 # replace "uid": 0 with "uid": 1000
# and do a similar thing for gid. # and do a similar thing for gid.
update_config ' (.. | select(.uid? == 0)) .uid |= 1000 update_config ' (.. | select(.uid? == 0)) .uid |= 1000
| (.. | select(.gid? == 0)) .gid |= 100' | (.. | select(.gid? == 0)) .gid |= 100'
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc run detached --pid-file" { @test "runc run detached --pid-file" {
# run busybox detached # run busybox detached
runc run --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]] [[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
} }
@test "runc run detached --pid-file with new CWD" { @test "runc run detached --pid-file with new CWD" {
# create pid_file directory as the CWD # create pid_file directory as the CWD
run mkdir pid_file run mkdir pid_file
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run cd pid_file run cd pid_file
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# run busybox detached # run busybox detached
runc run --pid-file pid.txt -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox runc run --pid-file pid.txt -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]] [[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
} }
+35 -35
View File
@@ -3,62 +3,62 @@
load helpers load helpers
function setup() { function setup() {
teardown_hello teardown_hello
setup_hello setup_hello
} }
function teardown() { function teardown() {
teardown_hello teardown_hello
} }
@test "runc run" { @test "runc run" {
# run hello-world # run hello-world
runc run test_hello runc run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check expected output # check expected output
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]
} }
@test "runc run ({u,g}id != 0)" { @test "runc run ({u,g}id != 0)" {
# cannot start containers as another user in rootless setup without idmap # cannot start containers as another user in rootless setup without idmap
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap
# replace "uid": 0 with "uid": 1000 # replace "uid": 0 with "uid": 1000
# and do a similar thing for gid. # and do a similar thing for gid.
update_config ' (.. | select(.uid? == 0)) .uid |= 1000 update_config ' (.. | select(.uid? == 0)) .uid |= 1000
| (.. | select(.gid? == 0)) .gid |= 100' | (.. | select(.gid? == 0)) .gid |= 100'
# run hello-world # run hello-world
runc run test_hello runc run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check expected output # check expected output
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]
} }
@test "runc run with rootfs set to ." { @test "runc run with rootfs set to ." {
cp config.json rootfs/. cp config.json rootfs/.
rm config.json rm config.json
cd rootfs cd rootfs
update_config '(.. | select(. == "rootfs")) |= "."' update_config '(.. | select(. == "rootfs")) |= "."'
# run hello-world # run hello-world
runc run test_hello runc run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]
} }
@test "runc run --pid-file" { @test "runc run --pid-file" {
# run hello-world # run hello-world
runc run --pid-file pid.txt test_hello runc run --pid-file pid.txt test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]
# check pid.txt was generated # check pid.txt was generated
[ -e pid.txt ] [ -e pid.txt ]
run cat pid.txt run cat pid.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]] [[ ${lines[0]} =~ [0-9]+ ]]
} }
+38 -38
View File
@@ -3,64 +3,64 @@
load helpers load helpers
function setup() { function setup() {
teardown_busybox teardown_busybox
setup_busybox setup_busybox
} }
function teardown() { function teardown() {
teardown_busybox teardown_busybox
} }
@test "state (kill + delete)" { @test "state (kill + delete)" {
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
runc kill test_busybox KILL runc kill test_busybox KILL
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# wait for busybox to be in the destroyed state # wait for busybox to be in the destroyed state
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'" retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
# delete test_busybox # delete test_busybox
runc delete test_busybox runc delete test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@test "state (pause + resume)" { @test "state (pause + resume)" {
# XXX: pause and resume require cgroups. # XXX: pause and resume require cgroups.
requires root requires root
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
# run busybox detached # run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
testcontainer test_busybox running testcontainer test_busybox running
# pause busybox # pause busybox
runc pause test_busybox runc pause test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# test state of busybox is paused # test state of busybox is paused
testcontainer test_busybox paused testcontainer test_busybox paused
# resume busybox # resume busybox
runc resume test_busybox runc resume test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# test state of busybox is back to running # test state of busybox is back to running
testcontainer test_busybox running testcontainer test_busybox running
} }
+13 -11
View File
@@ -15,7 +15,7 @@ function teardown() {
# stty size fails without a tty # stty size fails without a tty
update_config '(.. | select(.[]? == "sh")) += ["-c", "stty size"]' update_config '(.. | select(.[]? == "sh")) += ["-c", "stty size"]'
# note that stdout/stderr are already redirected by bats' run # note that stdout/stderr are already redirected by bats' run
runc run test_busybox < /dev/null runc run test_busybox </dev/null
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@@ -57,7 +57,7 @@ function teardown() {
# and do a similar thing for gid. # and do a similar thing for gid.
# Replace sh script with stat. # Replace sh script with stat.
# shellcheck disable=SC2016 # shellcheck disable=SC2016
update_config ' (.. | select(.uid? == 0)) .uid |= 1000 update_config ' (.. | select(.uid? == 0)) .uid |= 1000
| (.. | select(.gid? == 0)) .gid |= 100 | (.. | select(.gid? == 0)) .gid |= 100
| (.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]' | (.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]'
@@ -77,7 +77,7 @@ function teardown() {
testcontainer test_busybox running testcontainer test_busybox running
# note that stdout/stderr are already redirected by bats' run # note that stdout/stderr are already redirected by bats' run
runc exec -t test_busybox sh -c "stty size" < /dev/null runc exec -t test_busybox sh -c "stty size" </dev/null
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@@ -125,7 +125,7 @@ function teardown() {
# replace "uid": 0 with "uid": 1000 # replace "uid": 0 with "uid": 1000
# and do a similar thing for gid. # and do a similar thing for gid.
# shellcheck disable=SC2016 # shellcheck disable=SC2016
update_config ' (.. | select(.uid? == 0)) .uid |= 1000 update_config ' (.. | select(.uid? == 0)) .uid |= 1000
| (.. | select(.gid? == 0)) .gid |= 100' | (.. | select(.gid? == 0)) .gid |= 100'
# run busybox detached # run busybox detached
@@ -154,7 +154,8 @@ function teardown() {
# make sure we're running # make sure we're running
testcontainer test_busybox running testcontainer test_busybox running
tty_info_with_consize_size=$( cat <<EOF tty_info_with_consize_size=$(
cat <<EOF
{ {
"terminal": true, "terminal": true,
"consoleSize": { "consoleSize": {
@@ -172,7 +173,7 @@ EOF
) )
# run the exec # run the exec
runc exec -t --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" -p <( echo "$tty_info_with_consize_size" ) test_busybox runc exec -t --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" -p <(echo "$tty_info_with_consize_size") test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check the pid was generated # check the pid was generated
@@ -181,7 +182,8 @@ EOF
#wait user process to finish #wait user process to finish
timeout 1 tail --pid="$(head -n 1 pid.txt)" -f /dev/null timeout 1 tail --pid="$(head -n 1 pid.txt)" -f /dev/null
tty_info=$( cat <<EOF tty_info=$(
cat <<EOF
{ {
"args": [ "args": [
"/bin/cat", "/bin/cat",
@@ -193,7 +195,7 @@ EOF
) )
# run the exec # run the exec
runc exec -t -p <( echo "$tty_info" ) test_busybox runc exec -t -p <(echo "$tty_info") test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# test tty width and height against original process.json # test tty width and height against original process.json
@@ -203,7 +205,7 @@ EOF
@test "runc create [terminal=false]" { @test "runc create [terminal=false]" {
# Disable terminal creation. # Disable terminal creation.
# Replace sh script with sleep. # Replace sh script with sleep.
update_config ' (.. | select(.terminal? != null)) .terminal |= false update_config ' (.. | select(.terminal? != null)) .terminal |= false
| (.. | select(.[]? == "sh")) += ["sleep", "1000s"] | (.. | select(.[]? == "sh")) += ["sleep", "1000s"]
| del(.. | select(.? == "sh"))' | del(.. | select(.? == "sh"))'
@@ -225,7 +227,7 @@ EOF
# Disable terminal creation. # Disable terminal creation.
# Replace sh script with sleep. # Replace sh script with sleep.
update_config ' (.. | select(.terminal? != null)) .terminal |= false update_config ' (.. | select(.terminal? != null)) .terminal |= false
| (.. | select(.[]? == "sh")) += ["sleep", "1000s"] | (.. | select(.[]? == "sh")) += ["sleep", "1000s"]
| del(.. | select(.? == "sh"))' | del(.. | select(.? == "sh"))'
@@ -245,7 +247,7 @@ EOF
@test "runc run -d [terminal=false]" { @test "runc run -d [terminal=false]" {
# Disable terminal creation. # Disable terminal creation.
# Replace sh script with sleep. # Replace sh script with sleep.
update_config ' (.. | select(.terminal? != null)) .terminal |= false update_config ' (.. | select(.terminal? != null)) .terminal |= false
| (.. | select(.[]? == "sh")) += ["sleep", "1000s"] | (.. | select(.[]? == "sh")) += ["sleep", "1000s"]
| del(.. | select(.? == "sh"))' | del(.. | select(.? == "sh"))'
+354 -355
View File
@@ -3,20 +3,20 @@
load helpers load helpers
function teardown() { function teardown() {
rm -f "$BATS_TMPDIR"/runc-cgroups-integration-test.json rm -f "$BATS_TMPDIR"/runc-cgroups-integration-test.json
teardown_running_container test_update teardown_running_container test_update
teardown_running_container test_update_rt teardown_running_container test_update_rt
teardown_busybox teardown_busybox
} }
function setup() { function setup() {
teardown teardown
setup_busybox setup_busybox
set_cgroups_path "$BUSYBOX_BUNDLE" set_cgroups_path "$BUSYBOX_BUNDLE"
# Set some initial known values # Set some initial known values
update_config ' .linux.resources.memory |= {"limit": 33554432, "reservation": 25165824} update_config ' .linux.resources.memory |= {"limit": 33554432, "reservation": 25165824}
| .linux.resources.cpu |= {"shares": 100, "quota": 500000, "period": 1000000, "cpus": "0"} | .linux.resources.cpu |= {"shares": 100, "quota": 500000, "period": 1000000, "cpus": "0"}
| .linux.resources.pids |= {"limit": 20}' "${BUSYBOX_BUNDLE}" | .linux.resources.pids |= {"limit": 20}' "${BUSYBOX_BUNDLE}"
} }
@@ -24,146 +24,146 @@ function setup() {
# Tests whatever limits are (more or less) common between cgroup # Tests whatever limits are (more or less) common between cgroup
# v1 and v2: memory/swap, pids, and cpuset. # v1 and v2: memory/swap, pids, and cpuset.
@test "update cgroup v1/v2 common limits" { @test "update cgroup v1/v2 common limits" {
[[ "$ROOTLESS" -ne 0 && -z "$RUNC_USE_SYSTEMD" ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 && -z "$RUNC_USE_SYSTEMD" ]] && requires rootless_cgroup
if [[ "$ROOTLESS" -ne 0 && -n "$RUNC_USE_SYSTEMD" ]]; then if [[ "$ROOTLESS" -ne 0 && -n "$RUNC_USE_SYSTEMD" ]]; then
file="/sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers" file="/sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers"
# NOTE: delegation of cpuset requires systemd >= 244 (Fedora >= 32, Ubuntu >= 20.04). # NOTE: delegation of cpuset requires systemd >= 244 (Fedora >= 32, Ubuntu >= 20.04).
for f in memory pids cpuset; do for f in memory pids cpuset; do
if grep -qwv $f "$file"; then if grep -qwv $f "$file"; then
skip "$f is not enabled in $file" skip "$f is not enabled in $file"
fi fi
done done
fi fi
init_cgroup_paths init_cgroup_paths
# run a few busyboxes detached # run a few busyboxes detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# Set a few variables to make the code below work for both v1 and v2 # Set a few variables to make the code below work for both v1 and v2
case $CGROUP_UNIFIED in case $CGROUP_UNIFIED in
no) no)
MEM_LIMIT="memory.limit_in_bytes" MEM_LIMIT="memory.limit_in_bytes"
SD_MEM_LIMIT="MemoryLimit" SD_MEM_LIMIT="MemoryLimit"
MEM_RESERVE="memory.soft_limit_in_bytes" MEM_RESERVE="memory.soft_limit_in_bytes"
SD_MEM_RESERVE="unsupported" SD_MEM_RESERVE="unsupported"
MEM_SWAP="memory.memsw.limit_in_bytes" MEM_SWAP="memory.memsw.limit_in_bytes"
SD_MEM_SWAP="unsupported" SD_MEM_SWAP="unsupported"
SYSTEM_MEM=$(cat "${CGROUP_MEMORY_BASE_PATH}/${MEM_LIMIT}") SYSTEM_MEM=$(cat "${CGROUP_MEMORY_BASE_PATH}/${MEM_LIMIT}")
HAVE_SWAP="no" HAVE_SWAP="no"
if [ -f "${CGROUP_MEMORY_BASE_PATH}/${MEM_SWAP}" ]; then if [ -f "${CGROUP_MEMORY_BASE_PATH}/${MEM_SWAP}" ]; then
HAVE_SWAP="yes" HAVE_SWAP="yes"
fi fi
;; ;;
yes) yes)
MEM_LIMIT="memory.max" MEM_LIMIT="memory.max"
SD_MEM_LIMIT="MemoryMax" SD_MEM_LIMIT="MemoryMax"
MEM_RESERVE="memory.low" MEM_RESERVE="memory.low"
SD_MEM_RESERVE="MemoryLow" SD_MEM_RESERVE="MemoryLow"
MEM_SWAP="memory.swap.max" MEM_SWAP="memory.swap.max"
SD_MEM_SWAP="MemorySwapMax" SD_MEM_SWAP="MemorySwapMax"
SYSTEM_MEM="max" SYSTEM_MEM="max"
HAVE_SWAP="yes" HAVE_SWAP="yes"
;; ;;
esac esac
SD_UNLIMITED="infinity" SD_UNLIMITED="infinity"
SD_VERSION=$(systemctl --version | awk '{print $2; exit}') SD_VERSION=$(systemctl --version | awk '{print $2; exit}')
if [ "$SD_VERSION" -lt 227 ]; then if [ "$SD_VERSION" -lt 227 ]; then
SD_UNLIMITED="18446744073709551615" SD_UNLIMITED="18446744073709551615"
fi fi
# check that initial values were properly set # check that initial values were properly set
check_cgroup_value "cpuset.cpus" 0 check_cgroup_value "cpuset.cpus" 0
if [[ "$CGROUP_UNIFIED" = "yes" ]] && ! grep -qw memory "$CGROUP_PATH/cgroup.controllers"; then if [[ "$CGROUP_UNIFIED" = "yes" ]] && ! grep -qw memory "$CGROUP_PATH/cgroup.controllers"; then
# This happen on containerized environment because "echo +memory > /sys/fs/cgroup/cgroup.subtree_control" fails with EINVAL # This happen on containerized environment because "echo +memory > /sys/fs/cgroup/cgroup.subtree_control" fails with EINVAL
skip "memory controller not available" skip "memory controller not available"
fi fi
check_cgroup_value $MEM_LIMIT 33554432 check_cgroup_value $MEM_LIMIT 33554432
check_systemd_value $SD_MEM_LIMIT 33554432 check_systemd_value $SD_MEM_LIMIT 33554432
check_cgroup_value $MEM_RESERVE 25165824 check_cgroup_value $MEM_RESERVE 25165824
check_systemd_value $SD_MEM_RESERVE 25165824 check_systemd_value $SD_MEM_RESERVE 25165824
check_cgroup_value "pids.max" 20 check_cgroup_value "pids.max" 20
check_systemd_value "TasksMax" 20 check_systemd_value "TasksMax" 20
# update cpuset if supported (i.e. we're running on a multicore cpu) # update cpuset if supported (i.e. we're running on a multicore cpu)
cpu_count=$(grep -c '^processor' /proc/cpuinfo) cpu_count=$(grep -c '^processor' /proc/cpuinfo)
if [ "$cpu_count" -gt 1 ]; then if [ "$cpu_count" -gt 1 ]; then
runc update test_update --cpuset-cpus "1" runc update test_update --cpuset-cpus "1"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "cpuset.cpus" 1 check_cgroup_value "cpuset.cpus" 1
fi fi
# update memory limit # update memory limit
runc update test_update --memory 67108864 runc update test_update --memory 67108864
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value $MEM_LIMIT 67108864 check_cgroup_value $MEM_LIMIT 67108864
check_systemd_value $SD_MEM_LIMIT 67108864 check_systemd_value $SD_MEM_LIMIT 67108864
runc update test_update --memory 50M runc update test_update --memory 50M
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value $MEM_LIMIT 52428800 check_cgroup_value $MEM_LIMIT 52428800
check_systemd_value $SD_MEM_LIMIT 52428800 check_systemd_value $SD_MEM_LIMIT 52428800
# update memory soft limit # update memory soft limit
runc update test_update --memory-reservation 33554432 runc update test_update --memory-reservation 33554432
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "$MEM_RESERVE" 33554432 check_cgroup_value "$MEM_RESERVE" 33554432
check_systemd_value "$SD_MEM_RESERVE" 33554432 check_systemd_value "$SD_MEM_RESERVE" 33554432
# Run swap memory tests if swap is available # Run swap memory tests if swap is available
if [ "$HAVE_SWAP" = "yes" ]; then if [ "$HAVE_SWAP" = "yes" ]; then
# try to remove memory swap limit # try to remove memory swap limit
runc update test_update --memory-swap -1 runc update test_update --memory-swap -1
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "$MEM_SWAP" $SYSTEM_MEM check_cgroup_value "$MEM_SWAP" $SYSTEM_MEM
check_systemd_value "$SD_MEM_SWAP" $SD_UNLIMITED check_systemd_value "$SD_MEM_SWAP" $SD_UNLIMITED
# update memory swap # update memory swap
if [ "$CGROUP_UNIFIED" = "yes" ]; then if [ "$CGROUP_UNIFIED" = "yes" ]; then
# for cgroupv2, memory and swap can only be set together # for cgroupv2, memory and swap can only be set together
runc update test_update --memory 52428800 --memory-swap 96468992 runc update test_update --memory 52428800 --memory-swap 96468992
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# for cgroupv2, swap is a separate limit (it does not include mem) # for cgroupv2, swap is a separate limit (it does not include mem)
check_cgroup_value "$MEM_SWAP" $((96468992-52428800)) check_cgroup_value "$MEM_SWAP" $((96468992 - 52428800))
check_systemd_value "$SD_MEM_SWAP" $((96468992-52428800)) check_systemd_value "$SD_MEM_SWAP" $((96468992 - 52428800))
else else
runc update test_update --memory-swap 96468992 runc update test_update --memory-swap 96468992
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "$MEM_SWAP" 96468992 check_cgroup_value "$MEM_SWAP" 96468992
check_systemd_value "$SD_MEM_SWAP" 96468992 check_systemd_value "$SD_MEM_SWAP" 96468992
fi fi
fi fi
# try to remove memory limit # try to remove memory limit
runc update test_update --memory -1 runc update test_update --memory -1
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check memory limit is gone # check memory limit is gone
check_cgroup_value $MEM_LIMIT $SYSTEM_MEM check_cgroup_value $MEM_LIMIT $SYSTEM_MEM
check_systemd_value $SD_MEM_LIMIT $SD_UNLIMITED check_systemd_value $SD_MEM_LIMIT $SD_UNLIMITED
# check swap memory limited is gone # check swap memory limited is gone
if [ "$HAVE_SWAP" = "yes" ]; then if [ "$HAVE_SWAP" = "yes" ]; then
check_cgroup_value $MEM_SWAP $SYSTEM_MEM check_cgroup_value $MEM_SWAP $SYSTEM_MEM
check_systemd_value "$SD_MEM_SWAP" $SD_UNLIMITED check_systemd_value "$SD_MEM_SWAP" $SD_UNLIMITED
fi fi
# update pids limit # update pids limit
runc update test_update --pids-limit 10 runc update test_update --pids-limit 10
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "pids.max" 10 check_cgroup_value "pids.max" 10
check_systemd_value "TasksMax" 10 check_systemd_value "TasksMax" 10
# unlimited # unlimited
runc update test_update --pids-limit -1 runc update test_update --pids-limit -1
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "pids.max" max check_cgroup_value "pids.max" max
check_systemd_value "TasksMax" $SD_UNLIMITED check_systemd_value "TasksMax" $SD_UNLIMITED
# Revert to the test initial value via json on stdin # Revert to the test initial value via json on stdin
runc update -r - test_update <<EOF runc update -r - test_update <<EOF
{ {
"memory": { "memory": {
"limit": 33554432, "limit": 33554432,
@@ -180,35 +180,35 @@ function setup() {
} }
} }
EOF EOF
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "cpuset.cpus" 0 check_cgroup_value "cpuset.cpus" 0
check_cgroup_value $MEM_LIMIT 33554432 check_cgroup_value $MEM_LIMIT 33554432
check_systemd_value $SD_MEM_LIMIT 33554432 check_systemd_value $SD_MEM_LIMIT 33554432
check_cgroup_value $MEM_RESERVE 25165824 check_cgroup_value $MEM_RESERVE 25165824
check_systemd_value $SD_MEM_RESERVE 25165824 check_systemd_value $SD_MEM_RESERVE 25165824
check_cgroup_value "pids.max" 20 check_cgroup_value "pids.max" 20
check_systemd_value "TasksMax" 20 check_systemd_value "TasksMax" 20
# redo all the changes at once # redo all the changes at once
runc update test_update \ runc update test_update \
--cpu-period 900000 --cpu-quota 600000 --cpu-share 200 \ --cpu-period 900000 --cpu-quota 600000 --cpu-share 200 \
--memory 67108864 --memory-reservation 33554432 \ --memory 67108864 --memory-reservation 33554432 \
--pids-limit 10 --pids-limit 10
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value $MEM_LIMIT 67108864 check_cgroup_value $MEM_LIMIT 67108864
check_systemd_value $SD_MEM_LIMIT 67108864 check_systemd_value $SD_MEM_LIMIT 67108864
check_cgroup_value $MEM_RESERVE 33554432 check_cgroup_value $MEM_RESERVE 33554432
check_systemd_value $SD_MEM_RESERVE 33554432 check_systemd_value $SD_MEM_RESERVE 33554432
check_cgroup_value "pids.max" 10 check_cgroup_value "pids.max" 10
check_systemd_value "TasksMax" 10 check_systemd_value "TasksMax" 10
# reset to initial test value via json file # reset to initial test value via json file
cat << EOF > "$BATS_TMPDIR"/runc-cgroups-integration-test.json cat <<EOF >"$BATS_TMPDIR"/runc-cgroups-integration-test.json
{ {
"memory": { "memory": {
"limit": 33554432, "limit": 33554432,
@@ -226,94 +226,94 @@ EOF
} }
EOF EOF
runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "cpuset.cpus" 0 check_cgroup_value "cpuset.cpus" 0
check_cgroup_value $MEM_LIMIT 33554432 check_cgroup_value $MEM_LIMIT 33554432
check_systemd_value $SD_MEM_LIMIT 33554432 check_systemd_value $SD_MEM_LIMIT 33554432
check_cgroup_value $MEM_RESERVE 25165824 check_cgroup_value $MEM_RESERVE 25165824
check_systemd_value $SD_MEM_RESERVE 25165824 check_systemd_value $SD_MEM_RESERVE 25165824
check_cgroup_value "pids.max" 20 check_cgroup_value "pids.max" 20
check_systemd_value "TasksMax" 20 check_systemd_value "TasksMax" 20
} }
function check_cpu_quota() { function check_cpu_quota() {
local quota=$1 local quota=$1
local period=$2 local period=$2
local sd_quota=$3 local sd_quota=$3
if [ "$CGROUP_UNIFIED" = "yes" ]; then if [ "$CGROUP_UNIFIED" = "yes" ]; then
if [ "$quota" = "-1" ]; then if [ "$quota" = "-1" ]; then
quota="max" quota="max"
fi fi
check_cgroup_value "cpu.max" "$quota $period" check_cgroup_value "cpu.max" "$quota $period"
else else
check_cgroup_value "cpu.cfs_quota_us" $quota check_cgroup_value "cpu.cfs_quota_us" $quota
check_cgroup_value "cpu.cfs_period_us" "$period" check_cgroup_value "cpu.cfs_period_us" "$period"
fi fi
# systemd values are the same for v1 and v2 # systemd values are the same for v1 and v2
check_systemd_value "CPUQuotaPerSecUSec" "$sd_quota" check_systemd_value "CPUQuotaPerSecUSec" "$sd_quota"
# CPUQuotaPeriodUSec requires systemd >= v242 # CPUQuotaPeriodUSec requires systemd >= v242
[ "$(systemd_version)" -lt 242 ] && return [ "$(systemd_version)" -lt 242 ] && return
local sd_period=$(( period/1000 ))ms local sd_period=$((period / 1000))ms
[ "$sd_period" = "1000ms" ] && sd_period="1s" [ "$sd_period" = "1000ms" ] && sd_period="1s"
local sd_infinity="" local sd_infinity=""
# 100ms is the default value, and if not set, shown as infinity # 100ms is the default value, and if not set, shown as infinity
[ "$sd_period" = "100ms" ] && sd_infinity="infinity" [ "$sd_period" = "100ms" ] && sd_infinity="infinity"
check_systemd_value "CPUQuotaPeriodUSec" $sd_period $sd_infinity check_systemd_value "CPUQuotaPeriodUSec" $sd_period $sd_infinity
} }
function check_cpu_shares() { function check_cpu_shares() {
local shares=$1 local shares=$1
if [ "$CGROUP_UNIFIED" = "yes" ]; then if [ "$CGROUP_UNIFIED" = "yes" ]; then
local weight=$((1 + ((shares - 2) * 9999) / 262142)) local weight=$((1 + ((shares - 2) * 9999) / 262142))
check_cgroup_value "cpu.weight" $weight check_cgroup_value "cpu.weight" $weight
check_systemd_value "CPUWeight" $weight check_systemd_value "CPUWeight" $weight
else else
check_cgroup_value "cpu.shares" "$shares" check_cgroup_value "cpu.shares" "$shares"
check_systemd_value "CPUShares" "$shares" check_systemd_value "CPUShares" "$shares"
fi fi
} }
@test "update cgroup cpu limits" { @test "update cgroup cpu limits" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
# run a few busyboxes detached # run a few busyboxes detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check that initial values were properly set # check that initial values were properly set
check_cpu_quota 500000 1000000 "500ms" check_cpu_quota 500000 1000000 "500ms"
check_cpu_shares 100 check_cpu_shares 100
# update cpu period # update cpu period
runc update test_update --cpu-period 900000 runc update test_update --cpu-period 900000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 500000 900000 "560ms" check_cpu_quota 500000 900000 "560ms"
# update cpu quota # update cpu quota
runc update test_update --cpu-quota 600000 runc update test_update --cpu-quota 600000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 600000 900000 "670ms" check_cpu_quota 600000 900000 "670ms"
# remove cpu quota # remove cpu quota
runc update test_update --cpu-quota -1 runc update test_update --cpu-quota -1
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota -1 900000 "infinity" check_cpu_quota -1 900000 "infinity"
# update cpu-shares # update cpu-shares
runc update test_update --cpu-share 200 runc update test_update --cpu-share 200
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_shares 200 check_cpu_shares 200
# Revert to the test initial value via json on stding # Revert to the test initial value via json on stding
runc update -r - test_update <<EOF runc update -r - test_update <<EOF
{ {
"cpu": { "cpu": {
"shares": 100, "shares": 100,
@@ -322,23 +322,23 @@ function check_cpu_shares() {
} }
} }
EOF EOF
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 500000 1000000 "500ms" check_cpu_quota 500000 1000000 "500ms"
# redo all the changes at once # redo all the changes at once
runc update test_update \ runc update test_update \
--cpu-period 900000 --cpu-quota 600000 --cpu-share 200 --cpu-period 900000 --cpu-quota 600000 --cpu-share 200
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 600000 900000 "670ms" check_cpu_quota 600000 900000 "670ms"
check_cpu_shares 200 check_cpu_shares 200
# remove cpu quota and reset the period # remove cpu quota and reset the period
runc update test_update --cpu-quota -1 --cpu-period 100000 runc update test_update --cpu-quota -1 --cpu-period 100000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota -1 100000 "infinity" check_cpu_quota -1 100000 "infinity"
# reset to initial test value via json file # reset to initial test value via json file
cat << EOF > "$BATS_TMPDIR"/runc-cgroups-integration-test.json cat <<EOF >"$BATS_TMPDIR"/runc-cgroups-integration-test.json
{ {
"cpu": { "cpu": {
"shares": 100, "shares": 100,
@@ -348,110 +348,110 @@ EOF
} }
EOF EOF
runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 500000 1000000 "500ms" check_cpu_quota 500000 1000000 "500ms"
check_cpu_shares 100 check_cpu_shares 100
} }
@test "set cpu period with no quota" { @test "set cpu period with no quota" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= { "period": 1000000 }' "${BUSYBOX_BUNDLE}" update_config '.linux.resources.cpu |= { "period": 1000000 }' "${BUSYBOX_BUNDLE}"
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota -1 1000000 "infinity" check_cpu_quota -1 1000000 "infinity"
} }
@test "set cpu quota with no period" { @test "set cpu quota with no period" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= { "quota": 5000 }' "${BUSYBOX_BUNDLE}" update_config '.linux.resources.cpu |= { "quota": 5000 }' "${BUSYBOX_BUNDLE}"
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 5000 100000 "50ms" check_cpu_quota 5000 100000 "50ms"
} }
@test "update cpu period with no previous period/quota set" { @test "update cpu period with no previous period/quota set" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= {}' "${BUSYBOX_BUNDLE}" update_config '.linux.resources.cpu |= {}' "${BUSYBOX_BUNDLE}"
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# update the period alone, no old values were set # update the period alone, no old values were set
runc update --cpu-period 50000 test_update runc update --cpu-period 50000 test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota -1 50000 "infinity" check_cpu_quota -1 50000 "infinity"
} }
@test "update cpu quota with no previous period/quota set" { @test "update cpu quota with no previous period/quota set" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= {}' "${BUSYBOX_BUNDLE}" update_config '.linux.resources.cpu |= {}' "${BUSYBOX_BUNDLE}"
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# update the quota alone, no old values were set # update the quota alone, no old values were set
runc update --cpu-quota 30000 test_update runc update --cpu-quota 30000 test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cpu_quota 30000 100000 "300ms" check_cpu_quota 30000 100000 "300ms"
} }
@test "update rt period and runtime" { @test "update rt period and runtime" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_v1 cgroups_rt no_systemd requires cgroups_v1 cgroups_rt no_systemd
# By default, "${CGROUP_CPU}/cpu.rt_runtime_us" is set to 0, which inhibits # By default, "${CGROUP_CPU}/cpu.rt_runtime_us" is set to 0, which inhibits
# setting the container's realtimeRuntime. (#2046) # 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: # 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/cpu.rt_{period,runtime}_us
# - sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/test-cgroup/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 . # Typically period=1000000 runtime=950000 .
# #
# TODO: support systemd # TODO: support systemd
mkdir -p "$CGROUP_CPU" mkdir -p "$CGROUP_CPU"
local root_period root_runtime local root_period root_runtime
root_period=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us") root_period=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us")
root_runtime=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_runtime_us") root_runtime=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_runtime_us")
# the following IFS magic sets dirs=("runc-cgroups-integration-test" "test-cgroup") # 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 <<<"${CGROUP_CPU//${CGROUP_CPU_BASE_PATH}/}"
for (( i = 0; i < ${#dirs[@]}; i++ )); do for ((i = 0; i < ${#dirs[@]}; i++)); do
local target="$CGROUP_CPU_BASE_PATH" local target="$CGROUP_CPU_BASE_PATH"
for (( j = 0; j <= i; j++ )); do for ((j = 0; j <= i; j++)); do
target="${target}/${dirs[$j]}" target="${target}/${dirs[$j]}"
done done
target_period="${target}/cpu.rt_period_us" target_period="${target}/cpu.rt_period_us"
echo "Writing ${root_period} to ${target_period}" echo "Writing ${root_period} to ${target_period}"
echo "$root_period" > "$target_period" echo "$root_period" >"$target_period"
target_runtime="${target}/cpu.rt_runtime_us" target_runtime="${target}/cpu.rt_runtime_us"
echo "Writing ${root_runtime} to ${target_runtime}" echo "Writing ${root_runtime} to ${target_runtime}"
echo "$root_runtime" > "$target_runtime" echo "$root_runtime" >"$target_runtime"
done done
# run a detached busybox # run a detached busybox
runc run -d --console-socket "$CONSOLE_SOCKET" test_update_rt runc run -d --console-socket "$CONSOLE_SOCKET" test_update_rt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
runc update -r - test_update_rt <<EOF runc update -r - test_update_rt <<EOF
{ {
"cpu": { "cpu": {
"realtimeRuntime": 500001 "realtimeRuntime": 500001
} }
} }
EOF EOF
check_cgroup_value "cpu.rt_period_us" "$root_period" check_cgroup_value "cpu.rt_period_us" "$root_period"
check_cgroup_value "cpu.rt_runtime_us" 500001 check_cgroup_value "cpu.rt_runtime_us" 500001
runc update -r - test_update_rt <<EOF runc update -r - test_update_rt <<EOF
{ {
"cpu": { "cpu": {
"realtimePeriod": 800001, "realtimePeriod": 800001,
@@ -459,77 +459,76 @@ EOF
} }
} }
EOF EOF
check_cgroup_value "cpu.rt_period_us" 800001 check_cgroup_value "cpu.rt_period_us" 800001
check_cgroup_value "cpu.rt_runtime_us" 500001 check_cgroup_value "cpu.rt_runtime_us" 500001
runc update test_update_rt --cpu-rt-period 900001 --cpu-rt-runtime 600001 runc update test_update_rt --cpu-rt-period 900001 --cpu-rt-runtime 600001
check_cgroup_value "cpu.rt_period_us" 900001 check_cgroup_value "cpu.rt_period_us" 900001
check_cgroup_value "cpu.rt_runtime_us" 600001 check_cgroup_value "cpu.rt_runtime_us" 600001
} }
@test "update devices [minimal transition rules]" { @test "update devices [minimal transition rules]" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
# This test currently only makes sense on cgroupv1. # This test currently only makes sense on cgroupv1.
requires cgroups_v1 requires cgroups_v1
# Run a basic shell script that tries to write to /dev/null. If "runc # Run a basic shell script that tries to write to /dev/null. If "runc
# update" makes use of minimal transition rules, updates should not cause # update" makes use of minimal transition rules, updates should not cause
# writes to fail at any point. # writes to fail at any point.
update_config '.process.args |= ["sh", "-c", "while true; do echo >/dev/null; done"]' update_config '.process.args |= ["sh", "-c", "while true; do echo >/dev/null; done"]'
# Set up a temporary console socket and recvtty so we can get the stdio. # Set up a temporary console socket and recvtty so we can get the stdio.
TMP_RECVTTY_DIR="$(mktemp -d "$BATS_TMPDIR/runc-tmp-recvtty.XXXXXX")" TMP_RECVTTY_DIR="$(mktemp -d "$BATS_TMPDIR/runc-tmp-recvtty.XXXXXX")"
TMP_RECVTTY_PID="$TMP_RECVTTY_DIR/recvtty.pid" TMP_RECVTTY_PID="$TMP_RECVTTY_DIR/recvtty.pid"
TMP_CONSOLE_SOCKET="$TMP_RECVTTY_DIR/console.sock" TMP_CONSOLE_SOCKET="$TMP_RECVTTY_DIR/console.sock"
CONTAINER_OUTPUT="$TMP_RECVTTY_DIR/output" CONTAINER_OUTPUT="$TMP_RECVTTY_DIR/output"
("$RECVTTY" --no-stdin --pid-file "$TMP_RECVTTY_PID" \ ("$RECVTTY" --no-stdin --pid-file "$TMP_RECVTTY_PID" \
--mode single "$TMP_CONSOLE_SOCKET" &>"$CONTAINER_OUTPUT" ) & --mode single "$TMP_CONSOLE_SOCKET" &>"$CONTAINER_OUTPUT") &
retry 10 0.1 [ -e "$TMP_CONSOLE_SOCKET" ] retry 10 0.1 [ -e "$TMP_CONSOLE_SOCKET" ]
# Run the container in the background. # Run the container in the background.
runc run -d --console-socket "$TMP_CONSOLE_SOCKET" test_update runc run -d --console-socket "$TMP_CONSOLE_SOCKET" test_update
cat "$CONTAINER_OUTPUT" cat "$CONTAINER_OUTPUT"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# Trigger an update. This update doesn't actually change the device rules, # Trigger an update. This update doesn't actually change the device rules,
# but it will trigger the devices cgroup code to reapply the current rules. # but it will trigger the devices cgroup code to reapply the current rules.
# We trigger the update a few times to make sure we hit the race. # We trigger the update a few times to make sure we hit the race.
for _ in {1..12} for _ in {1..12}; do
do # TODO: Update "runc update" so we can change the device rules.
# TODO: Update "runc update" so we can change the device rules. runc update --pids-limit 30 test_update
runc update --pids-limit 30 test_update [ "$status" -eq 0 ]
[ "$status" -eq 0 ] done
done
# Kill recvtty. # Kill recvtty.
kill -9 "$(<"$TMP_RECVTTY_PID")" kill -9 "$(<"$TMP_RECVTTY_PID")"
# There should've been no output from the container. # There should've been no output from the container.
cat "$CONTAINER_OUTPUT" cat "$CONTAINER_OUTPUT"
[ -z "$(<"$CONTAINER_OUTPUT")" ] [ -z "$(<"$CONTAINER_OUTPUT")" ]
} }
@test "update paused container" { @test "update paused container" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_freezer requires cgroups_freezer
# Run the container in the background. # Run the container in the background.
runc run -d --console-socket "$CONSOLE_SOCKET" test_update runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# Pause the container. # Pause the container.
runc pause test_update runc pause test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# Trigger an unrelated update. # Trigger an unrelated update.
runc update --pids-limit 30 test_update runc update --pids-limit 30 test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# The container should still be paused. # The container should still be paused.
testcontainer test_update paused testcontainer test_update paused
# Resume the container. # Resume the container.
runc resume test_update runc resume test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
+5 -5
View File
@@ -3,9 +3,9 @@
load helpers load helpers
@test "runc version" { @test "runc version" {
runc -v runc -v
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ runc\ version\ [0-9]+\.[0-9]+\.[0-9]+ ]] [[ ${lines[0]} =~ runc\ version\ [0-9]+\.[0-9]+\.[0-9]+ ]]
[[ ${lines[1]} =~ commit:+ ]] [[ ${lines[1]} =~ commit:+ ]]
[[ ${lines[2]} =~ spec:\ [0-9]+\.[0-9]+\.[0-9]+ ]] [[ ${lines[2]} =~ spec:\ [0-9]+\.[0-9]+\.[0-9]+ ]]
} }