tests/int/kill: add kill -a with host pidns test

This is roughly the same as TestPIDHostInitProcessWait in libct/int,
except that here we use separate processes to create and to kill a
container, so the processes inside a container are not children of "runc kill", and
also we hit different codepaths (nonChildProcess.signal rather than
initProcess.signal).

One other thing is, rootless is also tested.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2023-05-11 19:47:26 -07:00
parent 67bc4bc240
commit e0e8d9c886
+48
View File
@@ -29,3 +29,51 @@ function teardown() {
runc delete test_busybox
[ "$status" -eq 0 ]
}
# This is roughly the same as TestPIDHostInitProcessWait in libcontainer/integration.
@test "kill --all KILL [host pidns]" {
# kill -a currently requires cgroup freezer.
requires cgroups_freezer
update_config ' .linux.namespaces -= [{"type": "pid"}]'
set_cgroups_path
if [ $EUID -ne 0 ]; then
# kill --all requires working cgroups.
requires rootless_cgroup
update_config ' .mounts |= map((select(.type == "proc")
| .type = "none"
| .source = "/proc"
| .options = ["rbind", "nosuid", "nodev", "noexec"]
) // .)'
fi
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
# Start a few more processes.
for _ in 1 2 3 4 5; do
__runc exec -d test_busybox sleep 1h
[ "$status" -eq 0 ]
done
# Get the list of all container processes.
path=$(get_cgroup_path "pids")
pids=$(cat "$path"/cgroup.procs)
echo "pids: $pids"
# Sanity check -- make sure all processes exist.
for p in $pids; do
kill -0 "$p"
done
runc kill -a test_busybox KILL
[ "$status" -eq 0 ]
wait_for_container 10 1 test_busybox stopped
# Make sure all processes are gone.
pids=$(cat "$path"/cgroup.procs) || true # OK if cgroup is gone
echo "pids: $pids"
for p in $pids; do
run ! kill -0 "$p"
[[ "$output" = *"No such process" ]]
done
}