mirror of
https://github.com/opencontainers/runc.git
synced 2026-11-06 05:17:05 +00:00
Now that runc is a real binary (a wrapper script in PATH), tests can
call it the way any other command is called, using bats' run helper
directly:
run -0 runc start ctr
instead of the old
runc start ctr
[ "$status" -eq 0 ]
where runc was a bash function hiding a call to run. The exit code check
is now part of the call: -N for an expected exit code, ! for "any
failure", and no argument where the exit code is checked later or not at
all.
This has to be done in one go: while the runc function exists, "run runc"
would call it, resulting in a nested run.
Other changes made necessary or possible by this:
- The runc and sane_run functions are gone. The output of a failed
command is now printed by bats itself, see the previous commit.
- __runc (a raw runc call, not using run) is now simply runc.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
92 lines
2.3 KiB
Bash
92 lines
2.3 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load helpers
|
|
|
|
function setup() {
|
|
requires root
|
|
requires_kernel 5.3
|
|
setup_busybox
|
|
update_config '.process.args = ["/bin/sleep", "1d"]'
|
|
}
|
|
|
|
function teardown() {
|
|
teardown_pidfd_kill
|
|
teardown_bundle
|
|
}
|
|
|
|
@test "runc create [ --pidfd-socket ] " {
|
|
setup_pidfd_kill "SIGTERM"
|
|
|
|
run -0 runc create --console-socket "$CONSOLE_SOCKET" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd
|
|
testcontainer test_pidfd created
|
|
|
|
pidfd_kill
|
|
wait_for_container 10 1 test_pidfd stopped
|
|
}
|
|
|
|
@test "runc run [ --pidfd-socket ] " {
|
|
setup_pidfd_kill "SIGKILL"
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd
|
|
testcontainer test_pidfd running
|
|
|
|
pidfd_kill
|
|
wait_for_container 10 1 test_pidfd stopped
|
|
}
|
|
|
|
@test "runc exec [ --pidfd-socket ] [cgroups_v1] " {
|
|
requires cgroups_v1
|
|
|
|
set_cgroups_path
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_pidfd
|
|
testcontainer test_pidfd running
|
|
|
|
# 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"
|
|
|
|
setup_pidfd_kill "SIGKILL"
|
|
|
|
runc exec -d --cgroup "pids:exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d
|
|
|
|
exec_pid=$(cat exec_pid.txt)
|
|
exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs")
|
|
[ "${exec_pid}" -eq "${exec_pid_in_cgroup}" ]
|
|
|
|
pidfd_kill
|
|
|
|
# ensure exec process has been reaped
|
|
retry 10 1 rmdir "${test_pidfd_cgroup_path}/exec_pidfd"
|
|
|
|
testcontainer test_pidfd running
|
|
}
|
|
|
|
@test "runc exec [ --pidfd-socket ] [cgroups_v2] " {
|
|
requires cgroups_v2
|
|
|
|
set_cgroups_path
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_pidfd
|
|
testcontainer test_pidfd running
|
|
|
|
# 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"
|
|
|
|
setup_pidfd_kill "SIGKILL"
|
|
|
|
runc exec -d --cgroup "exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d
|
|
|
|
exec_pid=$(cat exec_pid.txt)
|
|
exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs")
|
|
[ "${exec_pid}" -eq "${exec_pid_in_cgroup}" ]
|
|
|
|
pidfd_kill
|
|
|
|
# ensure exec process has been reaped
|
|
retry 10 1 rmdir "${test_pidfd_cgroup_path}/exec_pidfd"
|
|
|
|
testcontainer test_pidfd running
|
|
}
|