Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/integration: rm excessive run use; fix exec --preserve-fds test #2658

Merged
merged 3 commits into from
Nov 6, 2020
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
9 changes: 3 additions & 6 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ function check_pipes() {
echo Ping >&${in_w}
exec {in_w}>&-
exec {out_w}>&-
run cat <&${out_r}
[ "$status" -eq 0 ]
output=$(cat <&${out_r})
[[ "${output}" == *"ponG Ping"* ]]
}

Expand Down Expand Up @@ -159,8 +158,7 @@ function simple_cr() {

@test "checkpoint --lazy-pages and restore" {
# check if lazy-pages is supported
run "${CRIU}" check --feature uffd-noncoop
if [ "$status" -eq 1 ]; then
if ! "${CRIU}" check --feature uffd-noncoop; then
skip "this criu does not support lazy migration"
fi

Expand Down Expand Up @@ -218,8 +216,7 @@ function simple_cr() {

@test "checkpoint and restore in external network namespace" {
# check if external_net_ns is supported; only with criu 3.10++
run "${CRIU}" check --feature external_net_ns
if [ "$status" -eq 1 ]; then
if ! "${CRIU}" check --feature external_net_ns; then
# this criu does not support external_net_ns; skip the test
skip "this criu does not support external network namespaces"
fi
Expand Down
14 changes: 4 additions & 10 deletions tests/integration/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]]

# start the command
runc start test_busybox
Expand All @@ -64,10 +62,8 @@ function teardown() {

@test "runc create --pid-file with new CWD" {
# create pid_file directory as the CWD
run mkdir pid_file
[ "$status" -eq 0 ]
run cd pid_file
[ "$status" -eq 0 ]
mkdir pid_file
cd pid_file

runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
Expand All @@ -77,9 +73,7 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]]

# start the command
runc start test_busybox
Expand Down
9 changes: 3 additions & 6 deletions tests/integration/debug.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ function teardown() {
[ -e log.out ]

# check expected debug output was sent to log.out
run cat log.out
[ "$status" -eq 0 ]
output=$(cat log.out)
[[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]]
Expand All @@ -54,8 +53,7 @@ function teardown() {
[ -e log.out ]

# check expected debug output was sent to log.out
run cat log.out
[ "$status" -eq 0 ]
output=$(cat log.out)
[[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]]
Expand All @@ -73,8 +71,7 @@ function teardown() {
[ -e log.out ]

# check expected debug output was sent to log.out
run cat log.out
[ "$status" -eq 0 ]
output=$(cat log.out)
[[ "${output}" == *'"level":"debug"'* ]]
[[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]]
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ function teardown() {
runc state testbusyboxdelete
[ "$status" -ne 0 ]

run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ]
output=$(find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d)
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
}

Expand Down Expand Up @@ -99,8 +98,7 @@ EOF
runc state test_busybox
[ "$status" -ne 0 ]

run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ]
output=$(find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d)
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
}

Expand Down
13 changes: 5 additions & 8 deletions tests/integration/events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ function teardown() {

[ -e events.log ]

run cat events.log
[ "$status" -eq 0 ]
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
[[ "${lines[0]}" == *"data"* ]]
output=$(head -1 events.log)
[[ "$output" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
[[ "$output" == *"data"* ]]
}

@test "events --interval 1s" {
Expand All @@ -78,8 +77,7 @@ function teardown() {

[ -e events.log ]

run eval "grep -q 'test_busybox' events.log"
[ "$status" -eq 0 ]
grep -q 'test_busybox' events.log
}

@test "events --interval 100ms" {
Expand Down Expand Up @@ -108,8 +106,7 @@ function teardown() {

[ -e events.log ]

run eval "grep -q 'test_busybox' events.log"
[ "$status" -eq 0 ]
grep -q 'test_busybox' events.log
}

@test "events oom" {
Expand Down
29 changes: 13 additions & 16 deletions tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]]
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
output=$(cat pid.txt)
[[ "$output" =~ [0-9]+ ]]
[[ "$output" != $(__runc state test_busybox | jq '.pid') ]]
}

@test "runc exec --pid-file with new CWD" {
# create pid_file directory as the CWD
run mkdir pid_file
[ "$status" -eq 0 ]
run cd pid_file
[ "$status" -eq 0 ]
mkdir pid_file
cd pid_file

# run busybox detached
runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
Expand All @@ -60,10 +57,9 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]]
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
output=$(cat pid.txt)
[[ "$output" =~ [0-9]+ ]]
[[ "$output" != $(__runc state test_busybox | jq '.pid') ]]
}

@test "runc exec ls -la" {
Expand Down Expand Up @@ -133,8 +129,9 @@ function teardown() {
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

run bash -c "cat hello > preserve-fds.test; exec 3<preserve-fds.test; $RUNC ${RUNC_USE_SYSTEMD:+--systemd-cgroup} --log /proc/self/fd/2 --root $ROOT exec --preserve-fds=1 test_busybox cat /proc/self/fd/3"
[ "$status" -eq 0 ]

[[ "${output}" == *"hello"* ]]
echo hello >preserve-fds.test
# fd 3 is used by bats, so we use 4
exec 4<preserve-fds.test
output=$(__runc exec --preserve-fds=2 test_busybox cat /proc/self/fd/4)
[[ "${output}" == "hello" ]]
}
34 changes: 8 additions & 26 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ function teardown_recvtty() {

function setup_busybox() {
setup_recvtty
run mkdir "$BUSYBOX_BUNDLE"
run mkdir "$BUSYBOX_BUNDLE"/rootfs
mkdir -p "$BUSYBOX_BUNDLE"/rootfs
if [ -e "/testdata/busybox.tar" ]; then
BUSYBOX_IMAGE="/testdata/busybox.tar"
fi
Expand All @@ -438,8 +437,7 @@ function setup_busybox() {

function setup_hello() {
setup_recvtty
run mkdir "$HELLO_BUNDLE"
run mkdir "$HELLO_BUNDLE"/rootfs
mkdir -p "$HELLO_BUNDLE"/rootfs
tar --exclude './dev/*' -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
cd "$HELLO_BUNDLE"
runc_spec
Expand All @@ -453,7 +451,7 @@ function setup_debian() {
fi

setup_recvtty
run mkdir "$DEBIAN_BUNDLE"
mkdir -p "$DEBIAN_BUNDLE"

if [ ! -d "$DEBIAN_ROOTFS/rootfs" ]; then
get_and_extract_debian "$DEBIAN_BUNDLE"
Expand All @@ -468,46 +466,30 @@ function setup_debian() {
}

function teardown_running_container() {
runc list
# $1 should be a container name such as "test_busybox"
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
# e.g. "test_busybox" and "test_busybox_update"
if [[ "${output}" == *"$1 "* ]]; then
runc kill $1 KILL
retry 10 1 eval "__runc state '$1' | grep -q 'stopped'"
runc delete $1
fi
__runc delete -f "$1"
}

function teardown_running_container_inroot() {
ROOT=$2 runc list
# $1 should be a container name such as "test_busybox"
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
# e.g. "test_busybox" and "test_busybox_update"
if [[ "${output}" == *"$1 "* ]]; then
ROOT=$2 runc kill $1 KILL
retry 10 1 eval "ROOT='$2' __runc state '$1' | grep -q 'stopped'"
ROOT=$2 runc delete $1
fi
ROOT="$2" __runc delete -f "$1"
}

function teardown_busybox() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_busybox
run rm -f -r "$BUSYBOX_BUNDLE"
rm -f -r "$BUSYBOX_BUNDLE"
}

function teardown_hello() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_hello
run rm -f -r "$HELLO_BUNDLE"
rm -f -r "$HELLO_BUNDLE"
}

function teardown_debian() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_debian
run rm -f -r "$DEBIAN_BUNDLE"
rm -f -r "$DEBIAN_BUNDLE"
}
14 changes: 4 additions & 10 deletions tests/integration/start_detached.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
}

@test "runc run detached --pid-file with new CWD" {
# create pid_file directory as the CWD
run mkdir pid_file
[ "$status" -eq 0 ]
run cd pid_file
[ "$status" -eq 0 ]
mkdir pid_file
cd pid_file

# run busybox detached
runc run --pid-file pid.txt -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
Expand All @@ -70,7 +66,5 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
}
4 changes: 1 addition & 3 deletions tests/integration/start_hello.bats
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,5 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]]
[[ "$(cat pid.txt)" =~ [0-9]+ ]]
}