From 772e91062dc53f62a63926b824d99eb3259358bb Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 17 Oct 2025 12:39:36 -0700 Subject: [PATCH 1/9] tests/int/README: update 1. Remove the devicemapper driver mentions, and is it no longer supported by docker (or podman). 2. Remove the test example -- we have plenty of real ones. 3. Add a link to (well written and extensive) bats documentation. 4. Fix capitalization in a sentence. Signed-off-by: Kir Kolyshkin --- tests/integration/README.md | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/tests/integration/README.md b/tests/integration/README.md index 6f934c620e9..aec65961716 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -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 @@ -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. From 0eb03ef86fc54ab41e3d0dcb822ce42b6b40f8f4 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 16 Oct 2025 14:06:22 -0700 Subject: [PATCH 2/9] tests/int: remove useless/obvious comments This is a bit opinionated, but some comments in integration tests do not really help to understand the nature of the tests being performed by stating something very obvious, like # run busybox detached runc run -d busybox To make things worse, these not-so-helpful messages are being copy/pasted over and over, and that is the main reason to remove them. Signed-off-by: Kir Kolyshkin --- tests/integration/checkpoint.bats | 28 +-------------------------- tests/integration/create.bats | 9 --------- tests/integration/debug.bats | 4 ---- tests/integration/delete.bats | 5 ----- tests/integration/events.bats | 2 -- tests/integration/exec.bats | 14 -------------- tests/integration/kill.bats | 2 -- tests/integration/list.bats | 1 - tests/integration/mask.bats | 2 -- tests/integration/pause.bats | 11 ----------- tests/integration/start.bats | 2 -- tests/integration/start_detached.bats | 14 -------------- tests/integration/start_hello.bats | 10 ---------- tests/integration/state.bats | 9 --------- tests/integration/tty.bats | 21 -------------------- tests/integration/umask.bats | 1 - tests/integration/update.bats | 3 --- 17 files changed, 1 insertion(+), 137 deletions(-) diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index eb7557f5acb..503f5a8f460 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -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 } @@ -167,18 +163,14 @@ function simple_cr_with_netdevice() { [[ "$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 [ "$status" -eq 0 ] @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 } @@ -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. diff --git a/tests/integration/create.bats b/tests/integration/create.bats index f12291ca9d9..b1693518a99 100644 --- a/tests/integration/create.bats +++ b/tests/integration/create.bats @@ -16,7 +16,6 @@ function teardown() { testcontainer test_busybox created - # start the command runc start test_busybox [ "$status" -eq 0 ] @@ -34,7 +33,6 @@ function teardown() { testcontainer test_busybox created - # start the command runc start test_busybox [ "$status" -eq 0 ] @@ -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 ] @@ -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 @@ -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 ] diff --git a/tests/integration/debug.bats b/tests/integration/debug.bats index 9db676b89b2..cb9276a4afd 100644 --- a/tests/integration/debug.bats +++ b/tests/integration/debug.bats @@ -18,7 +18,6 @@ function check_debug() { } @test "global --debug" { - # run hello-world runc --debug run test_hello [ "$status" -eq 0 ] @@ -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 ] @@ -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 ] @@ -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 ] diff --git a/tests/integration/delete.bats b/tests/integration/delete.bats index bdb94516b9e..967f8e25ff1 100644 --- a/tests/integration/delete.bats +++ b/tests/integration/delete.bats @@ -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 @@ -209,11 +206,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 diff --git a/tests/integration/events.bats b/tests/integration/events.bats index ab5b320b99e..2076e8e95b8 100644 --- a/tests/integration/events.bats +++ b/tests/integration/events.bats @@ -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 ] @@ -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 ] diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 1426e198269..056c53545df 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -11,7 +11,6 @@ function teardown() { } @test "runc exec" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -42,7 +41,6 @@ function teardown() { } @test "runc exec --pid-file" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -51,9 +49,7 @@ function teardown() { echo text echoed = "'""${output}""'" [[ "${output}" == *"Hello from exec"* ]] - # check pid.txt was generated [ -e pid.txt ] - output=$(cat pid.txt) [[ "$output" =~ [0-9]+ ]] [[ "$output" != $(__runc state test_busybox | jq '.pid') ]] @@ -61,11 +57,9 @@ 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 "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -74,16 +68,13 @@ function teardown() { echo text echoed = "'""${output}""'" [[ "${output}" == *"Hello from exec"* ]] - # check pid.txt was generated [ -e pid.txt ] - output=$(cat pid.txt) [[ "$output" =~ [0-9]+ ]] [[ "$output" != $(__runc state test_busybox | jq '.pid') ]] } @test "runc exec ls -la" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -95,7 +86,6 @@ function teardown() { } @test "runc exec ls -la with --cwd" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -105,7 +95,6 @@ function teardown() { } @test "runc exec --env" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -119,7 +108,6 @@ function teardown() { # --user can't work in rootless containers that don't have idmap. [ $EUID -ne 0 ] && requires rootless_idmap - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -159,7 +147,6 @@ function teardown() { @test "runc exec --additional-gids" { requires root - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -171,7 +158,6 @@ function teardown() { } @test "runc exec --preserve-fds" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] diff --git a/tests/integration/kill.bats b/tests/integration/kill.bats index 355407eccdb..f8fdd328b7d 100644 --- a/tests/integration/kill.bats +++ b/tests/integration/kill.bats @@ -76,11 +76,9 @@ test_host_pidns_kill() { } @test "kill detached busybox" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # check state testcontainer test_busybox running runc kill test_busybox KILL diff --git a/tests/integration/list.bats b/tests/integration/list.bats index b8821bc706f..2d23b8afef0 100644 --- a/tests/integration/list.bats +++ b/tests/integration/list.bats @@ -16,7 +16,6 @@ function teardown() { @test "list" { bundle=$(pwd) - # run a few busyboxes detached ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box1 [ "$status" -eq 0 ] diff --git a/tests/integration/mask.bats b/tests/integration/mask.bats index d324eb32524..5783332ea18 100644 --- a/tests/integration/mask.bats +++ b/tests/integration/mask.bats @@ -18,7 +18,6 @@ function teardown() { } @test "mask paths [file]" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] @@ -36,7 +35,6 @@ function teardown() { } @test "mask paths [directory]" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] diff --git a/tests/integration/pause.bats b/tests/integration/pause.bats index 787d2d0d0b1..398788c2382 100644 --- a/tests/integration/pause.bats +++ b/tests/integration/pause.bats @@ -17,24 +17,19 @@ function teardown() { set_cgroups_path fi - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] testcontainer test_busybox running - # pause busybox runc pause test_busybox [ "$status" -eq 0 ] - # test state of busybox is paused testcontainer test_busybox paused - # resume busybox runc resume test_busybox [ "$status" -eq 0 ] - # test state of busybox is back to running testcontainer test_busybox running } @@ -45,31 +40,25 @@ function teardown() { set_cgroups_path fi - # run test_busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] testcontainer test_busybox running - # pause test_busybox and nonexistent container runc pause test_busybox [ "$status" -eq 0 ] runc pause nonexistent [ "$status" -ne 0 ] - # test state of test_busybox is paused testcontainer test_busybox paused - # resume test_busybox and nonexistent container runc resume test_busybox [ "$status" -eq 0 ] runc resume nonexistent [ "$status" -ne 0 ] - # test state of test_busybox is back to running testcontainer test_busybox running - # delete test_busybox runc delete --force test_busybox runc state test_busybox diff --git a/tests/integration/start.bats b/tests/integration/start.bats index 1c844b25148..10609102974 100644 --- a/tests/integration/start.bats +++ b/tests/integration/start.bats @@ -16,13 +16,11 @@ function teardown() { testcontainer test_busybox created - # start container test_busybox runc start test_busybox [ "$status" -eq 0 ] testcontainer test_busybox running - # delete test_busybox runc delete --force test_busybox runc state test_busybox diff --git a/tests/integration/start_detached.bats b/tests/integration/start_detached.bats index 73e10c8cb65..25a5f364205 100644 --- a/tests/integration/start_detached.bats +++ b/tests/integration/start_detached.bats @@ -11,11 +11,8 @@ function teardown() { } @test "runc run detached" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - - # check state testcontainer test_busybox running } @@ -28,43 +25,32 @@ function teardown() { update_config ' (.. | select(.uid? == 0)) .uid |= 1000 | (.. | select(.gid? == 0)) .gid |= 100' - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # check state testcontainer test_busybox running } @test "runc run detached --pid-file" { - # run busybox detached runc run --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # check state testcontainer test_busybox running - # check pid.txt was generated [ -e pid.txt ] - [[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]] } @test "runc run detached --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 --pid-file pid.txt -d -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # check state testcontainer test_busybox running - # check pid.txt was generated [ -e pid.txt ] - [[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]] } diff --git a/tests/integration/start_hello.bats b/tests/integration/start_hello.bats index 6fbb893e695..77cd5dcd1ae 100644 --- a/tests/integration/start_hello.bats +++ b/tests/integration/start_hello.bats @@ -12,11 +12,8 @@ function teardown() { } @test "runc run" { - # run hello-world runc run test_hello [ "$status" -eq 0 ] - - # check expected output [[ "${output}" == *"Hello"* ]] } @@ -29,11 +26,8 @@ function teardown() { update_config ' (.. | select(.uid? == 0)) .uid |= 1000 | (.. | select(.gid? == 0)) .gid |= 100' - # run hello-world runc run test_hello [ "$status" -eq 0 ] - - # check expected output [[ "${output}" == *"Hello"* ]] } @@ -72,21 +66,17 @@ function teardown() { cd rootfs update_config '(.. | select(. == "rootfs")) |= "."' - # run hello-world runc run test_hello [ "$status" -eq 0 ] [[ "${output}" == *"Hello"* ]] } @test "runc run --pid-file" { - # run hello-world runc run --pid-file pid.txt test_hello [ "$status" -eq 0 ] [[ "${output}" == *"Hello"* ]] - # check pid.txt was generated [ -e pid.txt ] - [[ "$(cat pid.txt)" =~ [0-9]+ ]] } diff --git a/tests/integration/state.bats b/tests/integration/state.bats index 5e88a3e2830..4a8da0579b0 100644 --- a/tests/integration/state.bats +++ b/tests/integration/state.bats @@ -14,18 +14,15 @@ function teardown() { runc state test_busybox [ "$status" -ne 0 ] - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # check state testcontainer test_busybox running runc kill test_busybox KILL [ "$status" -eq 0 ] wait_for_container 10 1 test_busybox stopped - # delete test_busybox runc delete test_busybox [ "$status" -eq 0 ] @@ -40,24 +37,18 @@ function teardown() { runc state test_busybox [ "$status" -ne 0 ] - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # check state testcontainer test_busybox running - # pause busybox runc pause test_busybox [ "$status" -eq 0 ] - # test state of busybox is paused testcontainer test_busybox paused - # resume busybox runc resume test_busybox [ "$status" -eq 0 ] - # test state of busybox is back to running testcontainer test_busybox running } diff --git a/tests/integration/tty.bats b/tests/integration/tty.bats index d1180a6bc26..9e8e4c14c0f 100644 --- a/tests/integration/tty.bats +++ b/tests/integration/tty.bats @@ -23,7 +23,6 @@ function teardown() { # shellcheck disable=SC2016 update_config '(.. | select(.[]? == "sh")) += ["-c", "for file in /proc/self/fd/[012]; do readlink $file; done"]' - # run busybox runc run test_busybox [ "$status" -eq 0 ] [[ ${lines[0]} =~ /dev/pts/+ ]] @@ -40,7 +39,6 @@ function teardown() { # shellcheck disable=SC2016 update_config '(.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]' - # run busybox runc run test_busybox [ "$status" -eq 0 ] [[ ${lines[0]} =~ 0 ]] @@ -60,7 +58,6 @@ function teardown() { | (.. | select(.gid? == 0)) .gid |= 100 | (.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]' - # run busybox runc run test_busybox [ "$status" -eq 0 ] [[ ${lines[0]} =~ 1000 ]] @@ -72,7 +69,6 @@ function teardown() { runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # make sure we're running testcontainer test_busybox running # note that stdout/stderr are already redirected by bats' run @@ -81,14 +77,11 @@ function teardown() { } @test "runc exec [tty ptsname]" { - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # make sure we're running testcontainer test_busybox running - # run the exec # shellcheck disable=SC2016 runc exec -t test_busybox sh -c 'for file in /proc/self/fd/[012]; do readlink $file; done' [ "$status" -eq 0 ] @@ -102,14 +95,11 @@ function teardown() { # TODO: this can be made as a change to the gid test. [ $EUID -ne 0 ] && requires rootless_idmap - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # make sure we're running testcontainer test_busybox running - # run the exec # shellcheck disable=SC2016 runc exec -t test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' [ "$status" -eq 0 ] @@ -126,14 +116,11 @@ function teardown() { update_config ' (.. | select(.uid? == 0)) .uid |= 1000 | (.. | select(.gid? == 0)) .gid |= 100' - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # make sure we're running testcontainer test_busybox running - # run the exec # shellcheck disable=SC2016 runc exec -t test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' [ "$status" -eq 0 ] @@ -145,11 +132,9 @@ function teardown() { # allow writing to filesystem update_config '(.. | select(.readonly? != null)) .readonly |= false' - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] - # make sure we're running testcontainer test_busybox running tty_info_with_consize_size=' @@ -184,7 +169,6 @@ function teardown() { "cwd": "/" }' - # run the exec runc exec -t -p <(echo "$tty_info") test_busybox [ "$status" -eq 0 ] @@ -202,13 +186,11 @@ function teardown() { # Make sure that the handling of detached IO is done properly. See #1354. __runc create test_busybox - # Start the command. runc start test_busybox [ "$status" -eq 0 ] testcontainer test_busybox running - # Kill the container. runc kill test_busybox KILL [ "$status" -eq 0 ] } @@ -216,7 +198,6 @@ function teardown() { @test "runc run [terminal=false]" { # Disable terminal creation. # Replace sh script with sleep. - update_config ' (.. | select(.terminal? != null)) .terminal |= false | (.. | select(.[]? == "sh")) += ["sleep", "1000s"] | del(.. | select(.? == "sh"))' @@ -229,7 +210,6 @@ function teardown() { wait_for_container 15 1 test_busybox running testcontainer test_busybox running - # Kill the container. runc kill test_busybox KILL [ "$status" -eq 0 ] } @@ -246,7 +226,6 @@ function teardown() { testcontainer test_busybox running - # Kill the container. runc kill test_busybox KILL [ "$status" -eq 0 ] } diff --git a/tests/integration/umask.bats b/tests/integration/umask.bats index 38e8f62160c..a90b2e80c97 100644 --- a/tests/integration/umask.bats +++ b/tests/integration/umask.bats @@ -13,7 +13,6 @@ function teardown() { @test "umask" { update_config '.process.user += {"umask":63}' - # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox [ "$status" -eq 0 ] diff --git a/tests/integration/update.bats b/tests/integration/update.bats index e3d1922efba..0509be43426 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -25,7 +25,6 @@ function setup() { requires cgroups_memory cgroups_pids cgroups_cpuset init_cgroup_paths - # run a few busyboxes detached runc run -d --console-socket "$CONSOLE_SOCKET" test_update [ "$status" -eq 0 ] @@ -259,7 +258,6 @@ EOF @test "update cgroup cpu limits" { [ $EUID -ne 0 ] && requires rootless_cgroup - # run a few busyboxes detached runc run -d --console-socket "$CONSOLE_SOCKET" test_update [ "$status" -eq 0 ] @@ -732,7 +730,6 @@ EOF echo "$root_runtime" >"$target_runtime" done - # run a detached busybox runc run -d --console-socket "$CONSOLE_SOCKET" test_update_rt [ "$status" -eq 0 ] From 773a44cc1df46fbfc01bba092df94d87f4d1985e Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sat, 18 Oct 2025 13:22:13 -0700 Subject: [PATCH 3/9] tests/int/netdev: slight refactoring Move the repetitive code and comment into setup_netns. Signed-off-by: Kir Kolyshkin --- tests/integration/netdev.bats | 49 +++++++++++------------------------ 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/tests/integration/netdev.bats b/tests/integration/netdev.bats index 6eec8c88cab..ef2176702bb 100644 --- a/tests/integration/netdev.bats +++ b/tests/integration/netdev.bats @@ -2,7 +2,9 @@ load helpers -function create_netns() { +function setup_netns() { + local tmp + # Create a temporary name for the test network namespace. tmp=$(mktemp -u) ns_name=$(basename "$tmp") @@ -10,6 +12,9 @@ function create_netns() { # Create the network namespace. ip netns add "$ns_name" ns_path=$(ip netns add "$ns_name" 2>&1 | sed -e 's/.*"\(.*\)".*/\1/') + + # Tell runc to use it. + update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' } function delete_netns() { @@ -40,10 +45,7 @@ function teardown() { } @test "move network device to container network namespace and restore it back" { - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - + setup_netns update_config ' .linux.netDevices |= {"dummy0": {} }' runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox @@ -61,13 +63,10 @@ function teardown() { } @test "move network device to precreated container network namespace" { + setup_netns update_config ' .linux.netDevices |= {"dummy0": {} } | .process.args |= ["ip", "address", "show", "dev", "dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - runc run test_busybox [ "$status" -eq 0 ] @@ -76,13 +75,10 @@ function teardown() { } @test "move network device to precreated container network namespace and set ip address with global scope" { + setup_netns update_config ' .linux.netDevices |= {"dummy0": {} } | .process.args |= ["ip", "address", "show", "dev", "dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - global_ip="169.254.169.77/32" # Set the interface down to avoid possible network problems. @@ -101,13 +97,10 @@ function teardown() { } @test "move network device to precreated container network namespace and set ip address without global scope" { + setup_netns update_config ' .linux.netDevices |= {"dummy0": {} } | .process.args |= ["ip", "address", "show", "dev", "dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - non_global_ip="127.0.0.33" # Set the interface down to avoid possible network problems. @@ -124,15 +117,12 @@ function teardown() { } @test "move network device to precreated container network namespace and set mtu" { + setup_netns update_config ' .linux.netDevices |= {"dummy0": {} } | .process.args |= ["ip", "address", "show", "dev", "dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - mtu_value=1789 - # Cet a custom mtu to the interface. + # Set a custom mtu to the interface. ip link set mtu "$mtu_value" dev dummy0 runc run test_busybox @@ -146,13 +136,10 @@ function teardown() { } @test "move network device to precreated container network namespace and set mac address" { + setup_netns update_config ' .linux.netDevices |= {"dummy0": {} } | .process.args |= ["ip", "address", "show", "dev", "dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - mac_address="00:11:22:33:44:55" # set a custom mac address to the interface ip link set address "$mac_address" dev dummy0 @@ -168,13 +155,10 @@ function teardown() { } @test "move network device to precreated container network namespace and rename" { + setup_netns update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } } | .process.args |= ["ip", "address", "show", "dev", "ctr_dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - runc run test_busybox [ "$status" -eq 0 ] @@ -183,13 +167,10 @@ function teardown() { } @test "move network device to precreated container network namespace and rename and set mtu and mac and ip address" { + setup_netns update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } } | .process.args |= ["ip", "address", "show", "dev", "ctr_dummy0"]' - # Tell runc which network namespace to use. - create_netns - update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' - mtu_value=1789 mac_address="00:11:22:33:44:55" global_ip="169.254.169.77/32" From 693a471af890469b1ae97af7774efcea609216c3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 16 Oct 2025 16:28:51 -0700 Subject: [PATCH 4/9] tests/int: use run with a status check ...instead of an explicit or absent status check. Signed-off-by: Kir Kolyshkin --- tests/integration/netdev.bats | 12 ++++-------- tests/integration/scheduler.bats | 2 +- tests/integration/update.bats | 4 ++-- tests/integration/userns.bats | 6 ++---- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/integration/netdev.bats b/tests/integration/netdev.bats index ef2176702bb..b14ad834a65 100644 --- a/tests/integration/netdev.bats +++ b/tests/integration/netdev.bats @@ -91,8 +91,7 @@ function teardown() { [[ "$output" == *"$global_ip "* ]] # Verify the interface is still present in the network namespace. - run ip netns exec "$ns_name" ip address show dev dummy0 - [ "$status" -eq 0 ] + run -0 ip netns exec "$ns_name" ip address show dev dummy0 [[ "$output" == *"$global_ip "* ]] } @@ -130,8 +129,7 @@ function teardown() { [[ "$output" == *"mtu $mtu_value "* ]] # Verify the interface is still present in the network namespace. - run ip netns exec "$ns_name" ip address show dev dummy0 - [ "$status" -eq 0 ] + run -0 ip netns exec "$ns_name" ip address show dev dummy0 [[ "$output" == *"mtu $mtu_value "* ]] } @@ -149,8 +147,7 @@ function teardown() { [[ "$output" == *"ether $mac_address "* ]] # Verify the interface is still present in the network namespace. - run ip netns exec "$ns_name" ip address show dev dummy0 - [ "$status" -eq 0 ] + run -0 ip netns exec "$ns_name" ip address show dev dummy0 [[ "$output" == *"ether $mac_address "* ]] } @@ -189,8 +186,7 @@ function teardown() { [[ "$output" == *"mtu $mtu_value "* ]] # Verify the interface is still present in the network namespace. - run ip netns exec "$ns_name" ip address show dev ctr_dummy0 - [ "$status" -eq 0 ] + run -0 ip netns exec "$ns_name" ip address show dev ctr_dummy0 [[ "$output" == *" $global_ip "* ]] [[ "$output" == *"ether $mac_address "* ]] [[ "$output" == *"mtu $mtu_value "* ]] diff --git a/tests/integration/scheduler.bats b/tests/integration/scheduler.bats index 6c80d86426b..853f36f60c6 100644 --- a/tests/integration/scheduler.bats +++ b/tests/integration/scheduler.bats @@ -51,7 +51,7 @@ function teardown() { }' __runc exec -d --pid-file pid.txt --process <(echo "$proc") test_scheduler - run chrt -p "$(cat pid.txt)" + run -0 chrt -p "$(cat pid.txt)" [[ "${lines[0]}" == *"scheduling policy: SCHED_DEADLINE|SCHED_RESET_ON_FORK" ]] [[ "${lines[1]}" == *"priority: 0" ]] [[ "${lines[2]}" == *"runtime/deadline/period parameters: 42000/100000/1000000" ]] diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 0509be43426..dee7250e2cd 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -424,9 +424,9 @@ EOF echo 50000 >"/sys/fs/cgroup/cpu/$REL_PARENT_PATH/cpu.cfs_quota_us" fi # Sanity checks. - run cat "/sys/fs/cgroup/cpu$REL_PARENT_PATH/cpu.cfs_period_us" + run -0 cat "/sys/fs/cgroup/cpu$REL_PARENT_PATH/cpu.cfs_period_us" [ "$output" -eq 100000 ] - run cat "/sys/fs/cgroup/cpu$REL_PARENT_PATH/cpu.cfs_quota_us" + run -0 cat "/sys/fs/cgroup/cpu$REL_PARENT_PATH/cpu.cfs_quota_us" [ "$output" -eq 50000 ] runc run -d --console-socket "$CONSOLE_SOCKET" test_update diff --git a/tests/integration/userns.bats b/tests/integration/userns.bats index 16afa30f805..1f2e83400e8 100644 --- a/tests/integration/userns.bats +++ b/tests/integration/userns.bats @@ -261,8 +261,7 @@ function teardown() { # The interface is virtual and should not exist because # is deleted during the namespace cleanup. - run ip link del dummy0 - [ "$status" -ne 0 ] + run ! ip link del dummy0 } @test "userns with network interface renamed" { @@ -279,6 +278,5 @@ function teardown() { # The interface is virtual and should not exist because # is deleted during the namespace cleanup. - run ip link del dummy0 - [ "$status" -ne 0 ] + run ! ip link del dummy0 } From b3a9f423b9788147710ce6e73d97b77fb42a6d72 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 16 Oct 2025 16:31:01 -0700 Subject: [PATCH 5/9] tests/int: remove bogus $status checks Commands that are not run via "run" helper (cat, mkdir, __runc) do not set $status, so it makes no sense to check it. Fixes: 94505a04, ed548376 Signed-off-by: Kir Kolyshkin --- tests/integration/pidfd-socket.bats | 4 ---- tests/integration/update.bats | 1 - 2 files changed, 5 deletions(-) diff --git a/tests/integration/pidfd-socket.bats b/tests/integration/pidfd-socket.bats index 9c10f26e1df..5dbd8660bb8 100644 --- a/tests/integration/pidfd-socket.bats +++ b/tests/integration/pidfd-socket.bats @@ -48,12 +48,10 @@ function teardown() { # Use sub-cgroup to ensure that exec process has been killed test_pidfd_cgroup_path=$(get_cgroup_path "pids") mkdir "${test_pidfd_cgroup_path}/exec_pidfd" - [ "$status" -eq 0 ] setup_pidfd_kill "SIGKILL" __runc exec -d --cgroup "pids:exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d - [ "$status" -eq 0 ] exec_pid=$(cat exec_pid.txt) exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs") @@ -79,12 +77,10 @@ function teardown() { # Use sub-cgroup to ensure that exec process has been killed test_pidfd_cgroup_path=$(get_cgroup_path "pids") mkdir "${test_pidfd_cgroup_path}/exec_pidfd" - [ "$status" -eq 0 ] setup_pidfd_kill "SIGKILL" __runc exec -d --cgroup "exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d - [ "$status" -eq 0 ] exec_pid=$(cat exec_pid.txt) exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs") diff --git a/tests/integration/update.bats b/tests/integration/update.bats index dee7250e2cd..29d36fdfa2a 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -320,7 +320,6 @@ EOF } } EOF - [ "$status" -eq 0 ] runc update -r "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json test_update [ "$status" -eq 0 ] From 92f3d1b22511fd54ab4efc2baa25e8ece6ca8935 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 17 Oct 2025 15:41:32 -0700 Subject: [PATCH 6/9] tests/int/cgroups.bats: fix a wrong comment This misleading comment is obviously a copy/paste from the previous test. Fix it. Fixes: dd696235 Signed-off-by: Kir Kolyshkin --- tests/integration/cgroups.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index b21c0efc58f..7c2129a6d60 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -490,7 +490,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" ] From ad72eab6c7451c6931c0633a7c872e22f3fba9eb Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 17 Oct 2025 16:24:11 -0700 Subject: [PATCH 7/9] tests/int/checkpoint: fix using run twice In our bats tests, runc itself is a wrapper which calls bats run helper, so using "run runc" is wrong as it results in calling run helper twice. Fixes: 8d180e965 Signed-off-by: Kir Kolyshkin --- tests/integration/checkpoint.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 503f5a8f460..c694cebe035 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -156,7 +156,7 @@ 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 "* ]] @@ -172,7 +172,7 @@ 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 "* ]] From b82ae3afdc8be7b26d454f85d2dbd3f3081a495a Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sat, 18 Oct 2025 12:52:17 -0700 Subject: [PATCH 8/9] tests/int/delete: fix pause test for rootless case The "runc delete --force [paused container]" test case does not check runc pause exit code, and if added, the test fails in rootless tests, because: - not all rootless tests have access to cgroups; - rootless containers doesn't have default cgroups path. To fix, add: - setup for rootless case; - require cgroups_freezer; - runc pause exit code check. Signed-off-by: Kir Kolyshkin --- tests/integration/delete.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/delete.bats b/tests/integration/delete.bats index 967f8e25ff1..78321c3b433 100644 --- a/tests/integration/delete.bats +++ b/tests/integration/delete.bats @@ -142,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 ] } From 3c2683f52fa1bc4f58b928ec541d13ef848583df Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sat, 18 Oct 2025 13:04:06 -0700 Subject: [PATCH 9/9] tests/int/cgroups: use heredoc to break a long line This is mostly to improve readability. While at it, make the script more robust by adding -e option to shell. The exception is echo $pid which is opportunistic and may fail depending on the order of pids in the file. Also, remove the empty comment and a shellcheck annotation. Fixes: c91fe9ae Signed-off-by: Kir Kolyshkin --- tests/integration/cgroups.bats | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 7c2129a6d60..a2df63e8002 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -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)" {