Skip to content

Commit

Permalink
Merge pull request #2757 from kolyshkin/test-int-cleanups
Browse files Browse the repository at this point in the history
tests/int: cleanups
  • Loading branch information
kolyshkin authored Feb 24, 2021
2 parents f36d64d + 41670e2 commit 6511671
Show file tree
Hide file tree
Showing 29 changed files with 180 additions and 264 deletions.
5 changes: 1 addition & 4 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ load helpers

# setup is called at the beginning of every test.
function setup() {
# see functions teardown_hello and setup_hello in helpers.bash, used to
# create a pristine environment for running your tests
teardown_hello
setup_hello
}

# teardown is called at the end of every test.
function teardown() {
teardown_hello
teardown_bundle
}

@test "this is a simple test" {
Expand Down
43 changes: 19 additions & 24 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
load helpers

function teardown() {
teardown_running_container test_cgroups_kmem
teardown_running_container test_cgroups_permissions
teardown_running_container test_cgroups_group
teardown_running_container test_cgroups_unified
teardown_busybox
teardown_bundle
}

function setup() {
teardown
setup_busybox
}

@test "runc update --kernel-memory{,-tcp} (initialized)" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_kmem

set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path

# 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}'

# run a detached busybox to work with
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem
Expand All @@ -46,7 +41,7 @@ function setup() {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_kmem

set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path

# run a detached busybox to work with
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem
Expand Down Expand Up @@ -75,7 +70,7 @@ function setup() {
# systemd controls the permission, so error does not happen
requires no_systemd

set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 1 ]
Expand All @@ -88,7 +83,7 @@ function setup() {
# systemd controls the permission, so error does not happen
requires no_systemd

set_resources_limit "$BUSYBOX_BUNDLE"
set_resources_limit

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 1 ]
Expand All @@ -98,8 +93,8 @@ function setup() {
@test "runc create (limits + cgrouppath + permission on the cgroup dir) succeeds" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup

set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE"
set_cgroups_path
set_resources_limit

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ]
Expand All @@ -120,8 +115,8 @@ function setup() {
@test "runc exec (limits + cgrouppath + permission on the cgroup dir) succeeds" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup

set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE"
set_cgroups_path
set_resources_limit

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ]
Expand All @@ -134,8 +129,8 @@ function setup() {
@test "runc exec (cgroup v2 + init process in non-root cgroup) succeeds" {
requires root cgroups_v2

set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
set_cgroups_path
set_cgroup_mount_writable

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_group
[ "$status" -eq 0 ]
Expand Down Expand Up @@ -181,9 +176,9 @@ function setup() {
@test "runc run (cgroup v1 + unified resources should fail)" {
requires root cgroups_v1

set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE"
update_config '.linux.resources.unified |= {"memory.min": "131072"}' "$BUSYBOX_BUNDLE"
set_cgroups_path
set_resources_limit
update_config '.linux.resources.unified |= {"memory.min": "131072"}'

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -ne 0 ]
Expand All @@ -193,7 +188,7 @@ function setup() {
@test "runc run (cgroup v2 resources.unified only)" {
requires root cgroups_v2

set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
update_config ' .linux.resources.unified |= {
"memory.min": "131072",
"memory.low": "524288",
Expand All @@ -203,7 +198,7 @@ function setup() {
"pids.max": "99",
"cpu.max": "10000 100000",
"cpu.weight": "42"
}' "$BUSYBOX_BUNDLE"
}'

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ]
Expand Down Expand Up @@ -233,7 +228,7 @@ function setup() {
@test "runc run (cgroup v2 resources.unified override)" {
requires root cgroups_v2

set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
# CPU shares of 3333 corresponds to CPU weight of 128.
update_config ' .linux.resources.memory |= {"limit": 33554432}
| .linux.resources.memorySwap |= {"limit": 33554432}
Expand All @@ -248,7 +243,7 @@ function setup() {
"pids.max": "42",
"cpu.max": "5000 50000",
"cpu.weight": "42"
}' "$BUSYBOX_BUNDLE"
}'

runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ]
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ function setup() {
# XXX: currently criu require root containers.
requires criu root

teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_running_container test_busybox_restore
teardown_bundle
}

function setup_pipes() {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
load helpers

function setup() {
teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_bundle
}

@test "runc create" {
Expand Down Expand Up @@ -61,11 +60,12 @@ function teardown() {
}

@test "runc create --pid-file with new CWD" {
bundle="$(pwd)"
# create pid_file directory as the CWD
mkdir pid_file
cd pid_file

runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
runc create --pid-file pid.txt -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

testcontainer test_busybox created
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/cwd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
load helpers

function setup() {
teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_bundle
}

# Test case for https://github.com/opencontainers/runc/pull/2086
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/debug.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
load helpers

function setup() {
teardown_hello
setup_hello
}

function teardown() {
teardown_hello
teardown_bundle
}

@test "global --debug" {
Expand Down
14 changes: 6 additions & 8 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
load helpers

function setup() {
teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_running_container testbusyboxdelete
teardown_bundle
}

@test "runc delete" {
Expand All @@ -20,7 +18,7 @@ function teardown() {

runc kill testbusyboxdelete KILL
[ "$status" -eq 0 ]
retry 10 1 eval "__runc state testbusyboxdelete | grep -q 'stopped'"
wait_for_container 10 1 testbusyboxdelete stopped

runc delete testbusyboxdelete
[ "$status" -eq 0 ]
Expand Down Expand Up @@ -54,8 +52,8 @@ function teardown() {

@test "runc delete --force in cgroupv1 with subcgroups" {
requires cgroups_v1 root cgroupns
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
set_cgroups_path
set_cgroup_mount_writable
# enable cgroupns
update_config '.linux.namespaces += [{"type": "cgroup"}]'

Expand Down Expand Up @@ -104,8 +102,8 @@ EOF

@test "runc delete --force in cgroupv2 with subcgroups" {
requires cgroups_v2 root
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
set_cgroups_path
set_cgroup_mount_writable

# run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/dev.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
load helpers

function setup() {
teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_running_container test_dev
teardown_bundle
}

@test "runc run [redundant default /dev/tty]" {
Expand Down
13 changes: 6 additions & 7 deletions tests/integration/events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
load helpers

function setup() {
teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_bundle
}

@test "events --stats" {
Expand Down Expand Up @@ -47,8 +46,8 @@ function test_events() {
# 2. Waits for an event that includes test_busybox then kills the
# test_busybox container which causes the event logger to exit.
(
retry 10 "$retry_every" eval "grep -q 'test_busybox' events.log"
teardown_running_container test_busybox
retry 10 "$retry_every" grep -q test_busybox events.log
__runc delete -f test_busybox
) &
wait # for both subshells to finish

Expand Down Expand Up @@ -77,7 +76,7 @@ function test_events() {
init_cgroup_paths

# 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}'

# run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
Expand All @@ -89,10 +88,10 @@ function test_events() {
# and waits for an oom event
(__runc events test_busybox >events.log) &
(
retry 10 1 eval "grep -q 'test_busybox' events.log"
retry 10 1 grep -q test_busybox events.log
# shellcheck disable=SC2016
__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 grep -q oom events.log
__runc delete -f test_busybox
) &
wait # wait for the above sub shells to finish
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
load helpers

function setup() {
teardown_busybox
setup_busybox
}

function teardown() {
teardown_busybox
teardown_bundle
}

@test "runc exec" {
Expand Down Expand Up @@ -41,12 +40,13 @@ function teardown() {
}

@test "runc exec --pid-file with new CWD" {
bundle="$(pwd)"
# create pid_file directory as the CWD
mkdir pid_file
cd pid_file

# run busybox detached
runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
runc run -d -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

runc exec --pid-file pid.txt test_busybox echo Hello from exec
Expand Down
Loading

0 comments on commit 6511671

Please sign in to comment.