mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 14:13:58 +08:00
41670e21f0
1. Get rid of fixed ROOT, *_BUNDLE, and CONSOLE_SOCKET dirs. Now they are temporary directories created in setup_bundle. 2. Automate containers cleanup: instead of having to specify all containers to be removed, list and destroy everything (which is now possible since every test case has its own unique root). 3. Randomize cgroup paths so two tests running in parallel won't use the same cgroup. Now it's theoretically possible to execute tests in parallel. Practically it's not possible yet because bats uses GNU parallel, which do not provide a terminal for whatever it executes, and many runc tests (all those that run containers with terminal: true) needs a tty. This may possibly be addressed later. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
56 lines
2.2 KiB
Bash
56 lines
2.2 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load helpers
|
|
|
|
function setup() {
|
|
setup_busybox
|
|
ALT_ROOT="$ROOT/alt"
|
|
mkdir -p "$ALT_ROOT/state"
|
|
}
|
|
|
|
function teardown() {
|
|
if [ -n "$ALT_ROOT" ]; then
|
|
ROOT="$ALT_ROOT" teardown_bundle
|
|
fi
|
|
teardown_bundle
|
|
}
|
|
|
|
@test "list" {
|
|
bundle=$(pwd)
|
|
# run a few busyboxes detached
|
|
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
|
|
[ "$status" -eq 0 ]
|
|
|
|
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
|
|
[ "$status" -eq 0 ]
|
|
|
|
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
|
|
[ "$status" -eq 0 ]
|
|
|
|
ROOT=$ALT_ROOT runc list
|
|
[ "$status" -eq 0 ]
|
|
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
|
|
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
|
|
ROOT=$ALT_ROOT runc list -q
|
|
[ "$status" -eq 0 ]
|
|
[[ "${lines[0]}" == "test_box1" ]]
|
|
[[ "${lines[1]}" == "test_box2" ]]
|
|
[[ "${lines[2]}" == "test_box3" ]]
|
|
|
|
ROOT=$ALT_ROOT runc list --format table
|
|
[ "$status" -eq 0 ]
|
|
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
|
|
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
|
|
ROOT=$ALT_ROOT runc list --format json
|
|
[ "$status" -eq 0 ]
|
|
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
|
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
|
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
|
|
}
|