tests: fix all the things

This fixes all of the tests that were broken as part of the console
rewrite. This includes fixing the integration tests that used TTY
handling inside libcontainer, as well as the bats integration tests that
needed to be rewritten to use recvtty (as they rely on detached
containers that are running).

This patch is part of the console rewrite patchset.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2016-09-06 22:40:01 +10:00
parent bda3055055
commit 972c176ae4
No known key found for this signature in database
GPG Key ID: 9E18AA267DDB8DB4
20 changed files with 91 additions and 65 deletions

View File

@ -1,4 +1,4 @@
.PHONY: all dbuild man \
.PHONY: all shell dbuild man \
localtest localunittest localintegration \
test unittest integration
@ -103,6 +103,9 @@ integration: runcimage
localintegration: all
bats -t tests/integration${TESTFLAGS}
shell: all
docker run -e TESTFLAGS -ti --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) $(RUNC_IMAGE) bash
install:
install -D -m0755 runc $(BINDIR)/runc

View File

@ -247,8 +247,6 @@ func TestExecInError(t *testing.T) {
}
}
// XXX: This test will fail.
/*
func TestExecInTTY(t *testing.T) {
if testing.Short() {
return
@ -281,15 +279,15 @@ func TestExecInTTY(t *testing.T) {
Args: []string{"ps"},
Env: standardEnvironment,
}
console, err := ps.NewConsole(0, 0)
err = container.Run(ps)
ok(t, err)
console, err := ps.GetConsole()
copy := make(chan struct{})
go func() {
io.Copy(&stdout, console)
close(copy)
}()
ok(t, err)
err = container.Run(ps)
ok(t, err)
select {
case <-time.After(5 * time.Second):
t.Fatal("Waiting for copy timed out")
@ -308,7 +306,6 @@ func TestExecInTTY(t *testing.T) {
t.Fatalf("unexpected carriage-return in output")
}
}
*/
func TestExecInEnvironment(t *testing.T) {
if testing.Short() {

View File

@ -36,13 +36,13 @@ type Process struct {
Cwd string
// Stdin is a pointer to a reader which provides the standard input stream.
Stdin *os.File
Stdin io.Reader
// Stdout is a pointer to a writer which receives the standard output stream.
Stdout *os.File
Stdout io.Writer
// Stderr is a pointer to a writer which receives the standard error stream.
Stderr *os.File
Stderr io.Writer
// ExtraFiles specifies additional open files to be inherited by the container
ExtraFiles []*os.File

View File

@ -43,7 +43,7 @@ EOF
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
# run a detached busybox to work with
runc run -d --console /dev/pts/ptmx test_cgroups_kmem
runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_kmem
[ "$status" -eq 0 ]
wait_for_container 15 1 test_cgroups_kmem
@ -61,7 +61,7 @@ EOF
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "\/runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
# run a detached busybox to work with
runc run -d --console /dev/pts/ptmx test_cgroups_kmem
runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_kmem
[ "$status" -eq 0 ]
wait_for_container 15 1 test_cgroups_kmem

View File

@ -12,7 +12,7 @@ function teardown() {
}
@test "runc create" {
runc create --console /dev/pts/ptmx test_busybox
runc create --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
testcontainer test_busybox created
@ -25,7 +25,7 @@ function teardown() {
}
@test "runc create exec" {
runc create --console /dev/pts/ptmx test_busybox
runc create --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
testcontainer test_busybox created
@ -33,6 +33,8 @@ function teardown() {
runc exec test_busybox true
[ "$status" -eq 0 ]
testcontainer test_busybox created
# start the command
runc start test_busybox
[ "$status" -eq 0 ]
@ -41,7 +43,7 @@ function teardown() {
}
@test "runc create --pid-file" {
runc create --pid-file pid.txt --console /dev/pts/ptmx test_busybox
runc create --pid-file pid.txt --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
testcontainer test_busybox created
@ -67,7 +69,7 @@ function teardown() {
run cd pid_file
[ "$status" -eq 0 ]
runc create --pid-file pid.txt -b $BUSYBOX_BUNDLE --console /dev/pts/ptmx test_busybox
runc create --pid-file pid.txt -b $BUSYBOX_BUNDLE --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
testcontainer test_busybox created

View File

@ -13,7 +13,7 @@ function teardown() {
@test "runc delete" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -34,7 +34,7 @@ function teardown() {
@test "runc delete --force" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -51,13 +51,13 @@ function teardown() {
@test "run delete with multi-containers" {
# create busybox1 detached
runc create --console /dev/pts/ptmx test_busybox1
runc create --console-socket $CONSOLE_SOCKET test_busybox1
[ "$status" -eq 0 ]
testcontainer test_busybox1 created
# run busybox2 detached
runc run -d --console /dev/pts/ptmx test_busybox2
runc run -d --console-socket $CONSOLE_SOCKET test_busybox2
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox2
@ -86,13 +86,13 @@ function teardown() {
@test "run delete --force with multi-containers" {
# create busybox1 detached
runc create --console /dev/pts/ptmx test_busybox1
runc create --console-socket $CONSOLE_SOCKET test_busybox1
[ "$status" -eq 0 ]
testcontainer test_busybox1 created
# run busybox2 detached
runc run -d --console /dev/pts/ptmx test_busybox2
runc run -d --console-socket $CONSOLE_SOCKET test_busybox2
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox2

View File

@ -13,7 +13,7 @@ function teardown() {
@test "events --stats" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -28,7 +28,7 @@ function teardown() {
@test "events --interval default " {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -55,7 +55,7 @@ function teardown() {
@test "events --interval 1s " {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -81,7 +81,7 @@ function teardown() {
@test "events --interval 100ms " {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state

View File

@ -13,7 +13,7 @@ function teardown() {
@test "runc exec" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -26,7 +26,7 @@ function teardown() {
@test "runc exec --pid-file" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -53,7 +53,7 @@ function teardown() {
[ "$status" -eq 0 ]
# run busybox detached
runc run -d -b $BUSYBOX_BUNDLE --console /dev/pts/ptmx test_busybox
runc run -d -b $BUSYBOX_BUNDLE --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -74,7 +74,7 @@ function teardown() {
@test "runc exec ls -la" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -88,7 +88,7 @@ function teardown() {
@test "runc exec ls -la with --cwd" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -100,7 +100,7 @@ function teardown() {
@test "runc exec --env" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -113,7 +113,7 @@ function teardown() {
@test "runc exec --user" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox

View File

@ -3,6 +3,7 @@
# Root directory of integration tests.
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
RUNC="${INTEGRATION_ROOT}/../../runc"
RECVTTY="${INTEGRATION_ROOT}/../../contrib/cmd/recvtty/recvtty"
GOPATH="${INTEGRATION_ROOT}/../../../.."
# Test data path.
@ -17,7 +18,7 @@ HELLO_IMAGE="$TESTDATA/hello-world.tar"
HELLO_BUNDLE="$BATS_TMPDIR/hello-world"
# CRIU PATH
CRIU="/usr/local/sbin/criu"
CRIU="$(which criu)"
# Kernel version
KERNEL_VERSION="$(uname -r)"
@ -28,6 +29,9 @@ KERNEL_MINOR="${KERNEL_MINOR%%.*}"
# Root state path.
ROOT="$BATS_TMPDIR/runc"
# Path to console socket.
CONSOLE_SOCKET="$BATS_TMPDIR/console.sock"
# Cgroup mount
CGROUP_BASE_PATH=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<MEMORY\>/ { print $5; exit }')
@ -142,7 +146,24 @@ function testcontainer() {
[[ "${output}" == *"$2"* ]]
}
function setup_recvtty() {
# We need to start recvtty in the background, so we double fork in the shell.
("$RECVTTY" --pid-file "$BATS_TMPDIR/recvtty.pid" --mode null "$CONSOLE_SOCKET" &) &
}
function teardown_recvtty() {
# When we kill recvtty, the container will also be killed.
if [ -f "$BATS_TMPDIR/recvtty.pid" ]; then
kill -9 $(cat "$BATS_TMPDIR/recvtty.pid")
fi
# Clean up the files that might be left over.
rm -f "$BATS_TMPDIR/recvtty.pid"
rm -f "$CONSOLE_SOCKET"
}
function setup_busybox() {
setup_recvtty
run mkdir "$BUSYBOX_BUNDLE"
run mkdir "$BUSYBOX_BUNDLE"/rootfs
if [ -e "/testdata/busybox.tar" ]; then
@ -157,6 +178,7 @@ function setup_busybox() {
}
function setup_hello() {
setup_recvtty
run mkdir "$HELLO_BUNDLE"
run mkdir "$HELLO_BUNDLE"/rootfs
tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
@ -185,12 +207,14 @@ function teardown_running_container_inroot() {
function teardown_busybox() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_busybox
run rm -f -r "$BUSYBOX_BUNDLE"
}
function teardown_hello() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_hello
run rm -f -r "$HELLO_BUNDLE"
}

View File

@ -15,7 +15,7 @@ function teardown() {
@test "kill detached busybox" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state

View File

@ -19,15 +19,15 @@ function teardown() {
@test "list" {
# run a few busyboxes detached
ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box1
ROOT=$HELLO_BUNDLE runc run -d --console-socket $CONSOLE_SOCKET test_box1
[ "$status" -eq 0 ]
wait_for_container_inroot 15 1 test_box1 $HELLO_BUNDLE
ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box2
ROOT=$HELLO_BUNDLE runc run -d --console-socket $CONSOLE_SOCKET test_box2
[ "$status" -eq 0 ]
wait_for_container_inroot 15 1 test_box2 $HELLO_BUNDLE
ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box3
ROOT=$HELLO_BUNDLE runc run -d --console-socket $CONSOLE_SOCKET test_box3
[ "$status" -eq 0 ]
wait_for_container_inroot 15 1 test_box3 $HELLO_BUNDLE

View File

@ -20,7 +20,7 @@ function teardown() {
@test "mask paths [file]" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -40,7 +40,7 @@ function teardown() {
@test "mask paths [directory]" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox

View File

@ -13,7 +13,7 @@ function teardown() {
@test "runc pause and resume" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox
@ -35,13 +35,13 @@ function teardown() {
@test "runc pause and resume with multi-container" {
# run test_busybox1 detached
runc run -d --console /dev/pts/ptmx test_busybox1
runc run -d --console-socket $CONSOLE_SOCKET test_busybox1
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox1
# run test_busybox2 detached
runc run -d --console /dev/pts/ptmx test_busybox2
runc run -d --console-socket $CONSOLE_SOCKET test_busybox2
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox2
@ -74,27 +74,27 @@ function teardown() {
@test "runc pause and resume with nonexist container" {
# run test_busybox1 detached
runc run -d --console /dev/pts/ptmx test_busybox1
runc run -d --console-socket $CONSOLE_SOCKET test_busybox1
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox1
# run test_busybox2 detached
runc run -d --console /dev/pts/ptmx test_busybox2
runc run -d --console-socket $CONSOLE_SOCKET test_busybox2
[ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox2
# pause test_busybox1, test_busybox2 and nonexistant container
runc pause test_busybox1 test_busybox2 nonexistant
# pause test_busybox1, test_busybox2 and nonexistent container
runc pause test_busybox1 test_busybox2 nonexistent
[ "$status" -ne 0 ]
# test state of test_busybox1 and test_busybox2 is paused
testcontainer test_busybox1 paused
testcontainer test_busybox2 paused
# resume test_busybox1, test_busybox2 and nonexistant container
runc resume test_busybox1 test_busybox2 nonexistant
# resume test_busybox1, test_busybox2 and nonexistent container
runc resume test_busybox1 test_busybox2 nonexistent
[ "$status" -ne 0 ]
# test state of two containers is back to running

View File

@ -13,7 +13,7 @@ function teardown() {
@test "ps" {
# start busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -29,7 +29,7 @@ function teardown() {
@test "ps -f json" {
# start busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -44,7 +44,7 @@ function teardown() {
@test "ps -e -x" {
# start busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state

View File

@ -15,11 +15,11 @@ function teardown() {
@test "global --root" {
# run busybox detached using $HELLO_BUNDLE for state
ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_dotbox
ROOT=$HELLO_BUNDLE runc run -d --console-socket $CONSOLE_SOCKET test_dotbox
[ "$status" -eq 0 ]
# run busybox detached in default root
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state of the busyboxes are only in their respective root path

View File

@ -12,12 +12,12 @@ function teardown() {
}
@test "runc start" {
runc create --console /dev/pts/ptmx test_busybox1
runc create --console-socket $CONSOLE_SOCKET test_busybox1
[ "$status" -eq 0 ]
testcontainer test_busybox1 created
runc create --console /dev/pts/ptmx test_busybox2
runc create --console-socket $CONSOLE_SOCKET test_busybox2
[ "$status" -eq 0 ]
testcontainer test_busybox2 created

View File

@ -13,7 +13,7 @@ function teardown() {
@test "runc run detached" {
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -29,7 +29,7 @@ function teardown() {
sed -i 's;"gid": 0;"gid": 100;g' config.json
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -40,7 +40,7 @@ function teardown() {
@test "runc run detached --pid-file" {
# run busybox detached
runc run --pid-file pid.txt -d --console /dev/pts/ptmx test_busybox
runc run --pid-file pid.txt -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state
@ -64,7 +64,7 @@ function teardown() {
[ "$status" -eq 0 ]
# run busybox detached
runc run --pid-file pid.txt -d -b $BUSYBOX_BUNDLE --console /dev/pts/ptmx test_busybox
runc run --pid-file pid.txt -d -b $BUSYBOX_BUNDLE --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state

View File

@ -16,7 +16,7 @@ function teardown() {
[ "$status" -ne 0 ]
# run busybox detached
runc run -d --console /dev/pts/ptmx test_busybox
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]
# check state

View File

@ -51,7 +51,7 @@ function check_cgroup_value() {
@test "update" {
requires cgroups_kmem
# run a few busyboxes detached
runc run -d --console /dev/pts/ptmx test_update
runc run -d --console-socket $CONSOLE_SOCKET test_update
[ "$status" -eq 0 ]
wait_for_container 15 1 test_update