Skip to content

Commit

Permalink
tests: fix all the things
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cyphar committed Dec 1, 2016
1 parent bda3055 commit 972c176
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 65 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all dbuild man \
.PHONY: all shell dbuild man \
localtest localunittest localintegration \
test unittest integration

Expand Down Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions libcontainer/integration/execin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ func TestExecInError(t *testing.T) {
}
}

// XXX: This test will fail.
/*
func TestExecInTTY(t *testing.T) {
if testing.Short() {
return
Expand Down Expand Up @@ -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")
Expand All @@ -308,7 +306,6 @@ func TestExecInTTY(t *testing.T) {
t.Fatalf("unexpected carriage-return in output")
}
}
*/

func TestExecInEnvironment(t *testing.T) {
if testing.Short() {
Expand Down
6 changes: 3 additions & 3 deletions libcontainer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
10 changes: 6 additions & 4 deletions tests/integration/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,14 +25,16 @@ 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

runc exec test_busybox true
[ "$status" -eq 0 ]

testcontainer test_busybox created

# start the command
runc start test_busybox
[ "$status" -eq 0 ]
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -86,20 +86,20 @@ 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
testcontainer test_busybox2 running

# delete both test_busybox1 and test_busybox2 container
runc delete --force test_busybox1 test_busybox2
runc delete --force test_busybox1 test_busybox2

runc state test_busybox1
[ "$status" -ne 0 ]
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/help.bats
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ load helpers
runc start -h
[ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ start+ ]]

runc run -h
[ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ run+ ]]

runc state -h
[ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ state+ ]]
Expand Down
26 changes: 25 additions & 1 deletion tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)"
Expand All @@ -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 }')

Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion tests/integration/kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 972c176

Please sign in to comment.