diff --git a/Makefile b/Makefile index 7ec779c82..581a05384 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/libcontainer/integration/execin_test.go b/libcontainer/integration/execin_test.go index 1f714975e..971ad166e 100644 --- a/libcontainer/integration/execin_test.go +++ b/libcontainer/integration/execin_test.go @@ -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() { diff --git a/libcontainer/process.go b/libcontainer/process.go index 7915a4f08..859d2708b 100644 --- a/libcontainer/process.go +++ b/libcontainer/process.go @@ -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 diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 73eff1d0b..9cd95a7de 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -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 diff --git a/tests/integration/create.bats b/tests/integration/create.bats index c3527955d..abd4da24d 100644 --- a/tests/integration/create.bats +++ b/tests/integration/create.bats @@ -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 diff --git a/tests/integration/delete.bats b/tests/integration/delete.bats index 78f982c51..61a9c4c9e 100644 --- a/tests/integration/delete.bats +++ b/tests/integration/delete.bats @@ -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,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 ] diff --git a/tests/integration/events.bats b/tests/integration/events.bats index 18855d5e7..182b721b8 100644 --- a/tests/integration/events.bats +++ b/tests/integration/events.bats @@ -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 diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 23d5c24f5..ba60ea171 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -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 diff --git a/tests/integration/help.bats b/tests/integration/help.bats index e63b0c110..ca404f342 100644 --- a/tests/integration/help.bats +++ b/tests/integration/help.bats @@ -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+ ]] diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 9e16f7f85..1903eda1a 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -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) ~ /\/ { 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" } diff --git a/tests/integration/kill.bats b/tests/integration/kill.bats index e0d89e947..a049de657 100644 --- a/tests/integration/kill.bats +++ b/tests/integration/kill.bats @@ -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 diff --git a/tests/integration/list.bats b/tests/integration/list.bats index 41c9e10db..302728a54 100644 --- a/tests/integration/list.bats +++ b/tests/integration/list.bats @@ -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 diff --git a/tests/integration/mask.bats b/tests/integration/mask.bats index d645b5126..074b0f2ed 100644 --- a/tests/integration/mask.bats +++ b/tests/integration/mask.bats @@ -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 diff --git a/tests/integration/pause.bats b/tests/integration/pause.bats index 02642f433..e657d0a1e 100644 --- a/tests/integration/pause.bats +++ b/tests/integration/pause.bats @@ -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 diff --git a/tests/integration/ps.bats b/tests/integration/ps.bats index 75f955f99..7a200150d 100644 --- a/tests/integration/ps.bats +++ b/tests/integration/ps.bats @@ -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 diff --git a/tests/integration/root.bats b/tests/integration/root.bats index a2cb377cb..ee1329179 100644 --- a/tests/integration/root.bats +++ b/tests/integration/root.bats @@ -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 diff --git a/tests/integration/start.bats b/tests/integration/start.bats index 502103c96..cd33dee55 100644 --- a/tests/integration/start.bats +++ b/tests/integration/start.bats @@ -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 diff --git a/tests/integration/start_detached.bats b/tests/integration/start_detached.bats index 02ca90d17..605fde225 100644 --- a/tests/integration/start_detached.bats +++ b/tests/integration/start_detached.bats @@ -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 diff --git a/tests/integration/state.bats b/tests/integration/state.bats index 0073a2a39..eed2eb3c4 100644 --- a/tests/integration/state.bats +++ b/tests/integration/state.bats @@ -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 diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 4d84cb2d7..6790e0b4e 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -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