Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 5 additions & 32 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ to end.

Integration tests are written in *bash* using the
[bats (Bash Automated Testing System)](https://github.com/bats-core/bats-core)
framework.
framework. Please see
[bats documentation](https://bats-core.readthedocs.io/en/stable/index.html)
for more details.

## Running integration tests

Expand Down Expand Up @@ -43,38 +45,9 @@ cd bats-core
./install.sh /usr/local
```

> **Note**: There are known issues running the integration tests using
> **devicemapper** as a storage driver, make sure that your docker daemon
> is using **aufs** if you want to successfully run the integration tests.

## Writing integration tests

[helper functions](https://github.com/opencontainers/runc/blob/master/tests/integration/helpers.bash)
[Helper functions](https://github.com/opencontainers/runc/blob/master/tests/integration/helpers.bash)
are provided in order to facilitate writing tests.

```sh
#!/usr/bin/env bats

# This will load the helpers.
load helpers

# setup is called at the beginning of every test.
function setup() {
setup_busybox
}

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

@test "this is a simple test" {
runc run containerid
# "The runc macro" automatically populates $status, $output and $lines.
# Please refer to bats documentation to find out more.
[ "$status" -eq 0 ]

# check expected output
[[ "${output}" == *"Hello"* ]]
}
```
Please see existing tests for examples.
12 changes: 8 additions & 4 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@ function setup() {
[[ ${lines[0]} = "0::/foo" ]]

# teardown: remove "/foo"
# 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'
cat <<'EOF' | runc exec test_cgroups_group sh -eux
echo -memory > /sys/fs/cgroup/cgroup.subtree_control
for pid in $(cat /sys/fs/cgroup/foo/cgroup.procs); do
echo $pid > /sys/fs/cgroup/cgroup.procs || true
done
rmdir /sys/fs/cgroup/foo
EOF
runc exec test_cgroups_group test ! -d /sys/fs/cgroup/foo
[ "$status" -eq 0 ]
#
}

@test "runc run (cgroup v1 + unified resources should fail)" {
Expand Down Expand Up @@ -490,7 +494,7 @@ convert_hugetlb_size() {
runc resume ct1
) &

# Exec should not timeout or succeed.
# Exec should succeed (once the container is resumed).
runc exec --ignore-paused ct1 echo ok
[ "$status" -eq 0 ]
[ "$output" = "ok" ]
Expand Down
32 changes: 3 additions & 29 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,14 @@ function simple_cr() {
testcontainer test_busybox running

for _ in $(seq 2); do
# checkpoint the running container
runc "$@" checkpoint --work-path ./work-dir test_busybox
[ "$status" -eq 0 ]

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

# restore from checkpoint
runc "$@" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

# busybox should be back up and running
testcontainer test_busybox running
done
}
Expand All @@ -160,27 +156,23 @@ function simple_cr_with_netdevice() {
[ "$status" -eq 0 ]

testcontainer test_busybox_netdevice running
run runc exec test_busybox_netdevice ip address show dev dummy0
runc exec test_busybox_netdevice ip address show dev dummy0
[ "$status" -eq 0 ]
[[ "$output" == *" $global_ip "* ]]
[[ "$output" == *"ether $mac_address "* ]]
[[ "$output" == *"mtu $mtu_value "* ]]

for _ in $(seq 2); do
# checkpoint the running container
runc "$@" checkpoint --work-path ./work-dir test_busybox_netdevice
[ "$status" -eq 0 ]

# after checkpoint busybox is no longer running
testcontainer test_busybox_netdevice checkpointed

# restore from checkpoint
runc "$@" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox_netdevice
[ "$status" -eq 0 ]

# busybox should be back up and running
testcontainer test_busybox_netdevice running
run runc exec test_busybox_netdevice ip address show dev dummy0
runc exec test_busybox_netdevice ip address show dev dummy0
[ "$status" -eq 0 ]
[[ "$output" == *" $global_ip "* ]]
[[ "$output" == *"ether $mac_address "* ]]
Expand Down Expand Up @@ -271,15 +263,12 @@ function simple_cr_with_netdevice() {
setup_pipes
runc_run_with_pipes test_busybox

#test checkpoint pre-dump
mkdir parent-dir
runc checkpoint --pre-dump --image-path ./parent-dir test_busybox
[ "$status" -eq 0 ]

# busybox should still be running
testcontainer test_busybox running

# checkpoint the running container
mkdir image-dir
mkdir work-dir
runc checkpoint --parent-path ../parent-dir --work-path ./work-dir --image-path ./image-dir test_busybox
Expand All @@ -288,7 +277,6 @@ function simple_cr_with_netdevice() {
# check parent path is valid
[ -e ./image-dir/parent ]

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

runc_restore_with_pipes ./work-dir test_busybox
Expand All @@ -302,7 +290,6 @@ function simple_cr_with_netdevice() {
setup_pipes
runc_run_with_pipes test_busybox

# checkpoint the running container
mkdir image-dir
mkdir work-dir

Expand Down Expand Up @@ -391,14 +378,12 @@ function simple_cr_with_netdevice() {
runc checkpoint --work-path ./work-dir test_busybox
[ "$status" -eq 0 ]

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

# restore from checkpoint; this should restore the container into the existing network namespace
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

# busybox should be back up and running
testcontainer test_busybox running

# container should be running in same network namespace as before
Expand Down Expand Up @@ -436,23 +421,20 @@ function simple_cr_with_netdevice() {

testcontainer test_busybox running

# checkpoint the running container
runc checkpoint --work-path ./work-dir test_busybox
[ "$status" -eq 0 ]
run ! test -f ./work-dir/"$tmplog1"
test -f ./work-dir/"$tmplog2"

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2"
# restore from checkpoint

runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
run ! test -f ./work-dir/"$tmplog1"
test -f ./work-dir/"$tmplog2"

# busybox should be back up and running
testcontainer test_busybox running
unlink "$tmp"
test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2"
Expand All @@ -479,22 +461,18 @@ function simple_cr_with_netdevice() {

testcontainer test_busybox running

# checkpoint the running container
runc checkpoint --work-path ./work-dir test_busybox
[ "$status" -eq 0 ]

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

# cleanup mountpoints created by runc during creation
# the mountpoints should be recreated during restore - that is the actual thing tested here
rm -rf "${bind1:?}"/*

# restore from checkpoint
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

# busybox should be back up and running
testcontainer test_busybox running
}

Expand Down Expand Up @@ -545,18 +523,14 @@ function simple_cr_with_netdevice() {

local execed_pid=""
for _ in $(seq 2); do
# checkpoint the running container
runc checkpoint --work-path ./work-dir test_busybox
[ "$status" -eq 0 ]

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

# restore from checkpoint
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

# busybox should be back up and running
testcontainer test_busybox running

# verify that previously exec'd process is restored.
Expand Down
9 changes: 0 additions & 9 deletions tests/integration/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function teardown() {

testcontainer test_busybox created

# start the command
runc start test_busybox
[ "$status" -eq 0 ]

Expand All @@ -34,7 +33,6 @@ function teardown() {

testcontainer test_busybox created

# start the command
runc start test_busybox
[ "$status" -eq 0 ]

Expand All @@ -47,12 +45,9 @@ function teardown() {

testcontainer test_busybox created

# check pid.txt was generated
[ -e pid.txt ]

[[ $(cat pid.txt) = $(__runc state test_busybox | jq '.pid') ]]

# start the command
runc start test_busybox
[ "$status" -eq 0 ]

Expand All @@ -61,7 +56,6 @@ 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

Expand All @@ -70,12 +64,9 @@ function teardown() {

testcontainer test_busybox created

# check pid.txt was generated
[ -e pid.txt ]

[[ $(cat pid.txt) = $(__runc state test_busybox | jq '.pid') ]]

# start the command
runc start test_busybox
[ "$status" -eq 0 ]

Expand Down
4 changes: 0 additions & 4 deletions tests/integration/debug.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function check_debug() {
}

@test "global --debug" {
# run hello-world
runc --debug run test_hello
[ "$status" -eq 0 ]

Expand All @@ -28,7 +27,6 @@ function check_debug() {
}

@test "global --debug to --log" {
# run hello-world
runc --log log.out --debug run test_hello
[ "$status" -eq 0 ]

Expand All @@ -43,7 +41,6 @@ function check_debug() {
}

@test "global --debug to --log --log-format 'text'" {
# run hello-world
runc --log log.out --log-format "text" --debug run test_hello
[ "$status" -eq 0 ]

Expand All @@ -58,7 +55,6 @@ function check_debug() {
}

@test "global --debug to --log --log-format 'json'" {
# run hello-world
runc --log log.out --log-format "json" --debug run test_hello
[ "$status" -eq 0 ]

Expand Down
13 changes: 8 additions & 5 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,11 @@ function test_runc_delete_host_pidns() {
}

@test "runc delete --force" {
# run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

# check state
testcontainer test_busybox running

# force delete test_busybox
runc delete --force test_busybox

runc state test_busybox
Expand All @@ -145,11 +142,19 @@ function test_runc_delete_host_pidns() {
}

@test "runc delete --force [paused container]" {
requires cgroups_freezer
if [ $EUID -ne 0 ]; then
requires rootless_cgroup
# Rootless containers have no default cgroup path.
set_cgroups_path
fi

runc run -d --console-socket "$CONSOLE_SOCKET" ct1
[ "$status" -eq 0 ]
testcontainer ct1 running

runc pause ct1
[ "$status" -eq 0 ]
runc delete --force ct1
[ "$status" -eq 0 ]
}
Expand Down Expand Up @@ -209,11 +214,9 @@ EOF
set_cgroups_path
set_cgroup_mount_writable

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

# check state
testcontainer test_busybox running

# create a sub process
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function test_events() {
[ $EUID -ne 0 ] && requires rootless_cgroup
init_cgroup_paths

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

Expand Down Expand Up @@ -121,7 +120,6 @@ function test_events() {
# we need the container to hit OOM, so disable swap
update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}'

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

Expand Down
Loading
Loading