Skip to content

Commit 972c176

Browse files
committed
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 <[email protected]>
1 parent bda3055 commit 972c176

File tree

20 files changed

+91
-65
lines changed

20 files changed

+91
-65
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all dbuild man \
1+
.PHONY: all shell dbuild man \
22
localtest localunittest localintegration \
33
test unittest integration
44

@@ -103,6 +103,9 @@ integration: runcimage
103103
localintegration: all
104104
bats -t tests/integration${TESTFLAGS}
105105

106+
shell: all
107+
docker run -e TESTFLAGS -ti --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) $(RUNC_IMAGE) bash
108+
106109
install:
107110
install -D -m0755 runc $(BINDIR)/runc
108111

libcontainer/integration/execin_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,6 @@ func TestExecInError(t *testing.T) {
247247
}
248248
}
249249

250-
// XXX: This test will fail.
251-
/*
252250
func TestExecInTTY(t *testing.T) {
253251
if testing.Short() {
254252
return
@@ -281,15 +279,15 @@ func TestExecInTTY(t *testing.T) {
281279
Args: []string{"ps"},
282280
Env: standardEnvironment,
283281
}
284-
console, err := ps.NewConsole(0, 0)
282+
err = container.Run(ps)
283+
ok(t, err)
284+
console, err := ps.GetConsole()
285285
copy := make(chan struct{})
286286
go func() {
287287
io.Copy(&stdout, console)
288288
close(copy)
289289
}()
290290
ok(t, err)
291-
err = container.Run(ps)
292-
ok(t, err)
293291
select {
294292
case <-time.After(5 * time.Second):
295293
t.Fatal("Waiting for copy timed out")
@@ -308,7 +306,6 @@ func TestExecInTTY(t *testing.T) {
308306
t.Fatalf("unexpected carriage-return in output")
309307
}
310308
}
311-
*/
312309

313310
func TestExecInEnvironment(t *testing.T) {
314311
if testing.Short() {

libcontainer/process.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type Process struct {
3636
Cwd string
3737

3838
// Stdin is a pointer to a reader which provides the standard input stream.
39-
Stdin *os.File
39+
Stdin io.Reader
4040

4141
// Stdout is a pointer to a writer which receives the standard output stream.
42-
Stdout *os.File
42+
Stdout io.Writer
4343

4444
// Stderr is a pointer to a writer which receives the standard error stream.
45-
Stderr *os.File
45+
Stderr io.Writer
4646

4747
// ExtraFiles specifies additional open files to be inherited by the container
4848
ExtraFiles []*os.File

tests/integration/cgroups.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ EOF
4343
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
4444

4545
# run a detached busybox to work with
46-
runc run -d --console /dev/pts/ptmx test_cgroups_kmem
46+
runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_kmem
4747
[ "$status" -eq 0 ]
4848
wait_for_container 15 1 test_cgroups_kmem
4949

@@ -61,7 +61,7 @@ EOF
6161
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "\/runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
6262

6363
# run a detached busybox to work with
64-
runc run -d --console /dev/pts/ptmx test_cgroups_kmem
64+
runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_kmem
6565
[ "$status" -eq 0 ]
6666
wait_for_container 15 1 test_cgroups_kmem
6767

tests/integration/create.bats

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function teardown() {
1212
}
1313

1414
@test "runc create" {
15-
runc create --console /dev/pts/ptmx test_busybox
15+
runc create --console-socket $CONSOLE_SOCKET test_busybox
1616
[ "$status" -eq 0 ]
1717

1818
testcontainer test_busybox created
@@ -25,14 +25,16 @@ function teardown() {
2525
}
2626

2727
@test "runc create exec" {
28-
runc create --console /dev/pts/ptmx test_busybox
28+
runc create --console-socket $CONSOLE_SOCKET test_busybox
2929
[ "$status" -eq 0 ]
3030

3131
testcontainer test_busybox created
3232

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

36+
testcontainer test_busybox created
37+
3638
# start the command
3739
runc start test_busybox
3840
[ "$status" -eq 0 ]
@@ -41,7 +43,7 @@ function teardown() {
4143
}
4244

4345
@test "runc create --pid-file" {
44-
runc create --pid-file pid.txt --console /dev/pts/ptmx test_busybox
46+
runc create --pid-file pid.txt --console-socket $CONSOLE_SOCKET test_busybox
4547
[ "$status" -eq 0 ]
4648

4749
testcontainer test_busybox created
@@ -67,7 +69,7 @@ function teardown() {
6769
run cd pid_file
6870
[ "$status" -eq 0 ]
6971

70-
runc create --pid-file pid.txt -b $BUSYBOX_BUNDLE --console /dev/pts/ptmx test_busybox
72+
runc create --pid-file pid.txt -b $BUSYBOX_BUNDLE --console-socket $CONSOLE_SOCKET test_busybox
7173
[ "$status" -eq 0 ]
7274

7375
testcontainer test_busybox created

tests/integration/delete.bats

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function teardown() {
1313

1414
@test "runc delete" {
1515
# run busybox detached
16-
runc run -d --console /dev/pts/ptmx test_busybox
16+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
1717
[ "$status" -eq 0 ]
1818

1919
# check state
@@ -34,7 +34,7 @@ function teardown() {
3434

3535
@test "runc delete --force" {
3636
# run busybox detached
37-
runc run -d --console /dev/pts/ptmx test_busybox
37+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
3838
[ "$status" -eq 0 ]
3939

4040
# check state
@@ -51,13 +51,13 @@ function teardown() {
5151

5252
@test "run delete with multi-containers" {
5353
# create busybox1 detached
54-
runc create --console /dev/pts/ptmx test_busybox1
54+
runc create --console-socket $CONSOLE_SOCKET test_busybox1
5555
[ "$status" -eq 0 ]
5656

5757
testcontainer test_busybox1 created
5858

5959
# run busybox2 detached
60-
runc run -d --console /dev/pts/ptmx test_busybox2
60+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox2
6161
[ "$status" -eq 0 ]
6262

6363
wait_for_container 15 1 test_busybox2
@@ -86,20 +86,20 @@ function teardown() {
8686

8787
@test "run delete --force with multi-containers" {
8888
# create busybox1 detached
89-
runc create --console /dev/pts/ptmx test_busybox1
89+
runc create --console-socket $CONSOLE_SOCKET test_busybox1
9090
[ "$status" -eq 0 ]
9191

9292
testcontainer test_busybox1 created
9393

9494
# run busybox2 detached
95-
runc run -d --console /dev/pts/ptmx test_busybox2
95+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox2
9696
[ "$status" -eq 0 ]
9797

9898
wait_for_container 15 1 test_busybox2
9999
testcontainer test_busybox2 running
100100

101101
# delete both test_busybox1 and test_busybox2 container
102-
runc delete --force test_busybox1 test_busybox2
102+
runc delete --force test_busybox1 test_busybox2
103103

104104
runc state test_busybox1
105105
[ "$status" -ne 0 ]

tests/integration/events.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function teardown() {
1313

1414
@test "events --stats" {
1515
# run busybox detached
16-
runc run -d --console /dev/pts/ptmx test_busybox
16+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
1717
[ "$status" -eq 0 ]
1818

1919
# check state
@@ -28,7 +28,7 @@ function teardown() {
2828

2929
@test "events --interval default " {
3030
# run busybox detached
31-
runc run -d --console /dev/pts/ptmx test_busybox
31+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
3232
[ "$status" -eq 0 ]
3333

3434
# check state
@@ -55,7 +55,7 @@ function teardown() {
5555

5656
@test "events --interval 1s " {
5757
# run busybox detached
58-
runc run -d --console /dev/pts/ptmx test_busybox
58+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
5959
[ "$status" -eq 0 ]
6060

6161
# check state
@@ -81,7 +81,7 @@ function teardown() {
8181

8282
@test "events --interval 100ms " {
8383
# run busybox detached
84-
runc run -d --console /dev/pts/ptmx test_busybox
84+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
8585
[ "$status" -eq 0 ]
8686

8787
# check state

tests/integration/exec.bats

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function teardown() {
1313

1414
@test "runc exec" {
1515
# run busybox detached
16-
runc run -d --console /dev/pts/ptmx test_busybox
16+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
1717
[ "$status" -eq 0 ]
1818

1919
wait_for_container 15 1 test_busybox
@@ -26,7 +26,7 @@ function teardown() {
2626

2727
@test "runc exec --pid-file" {
2828
# run busybox detached
29-
runc run -d --console /dev/pts/ptmx test_busybox
29+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
3030
[ "$status" -eq 0 ]
3131

3232
wait_for_container 15 1 test_busybox
@@ -53,7 +53,7 @@ function teardown() {
5353
[ "$status" -eq 0 ]
5454

5555
# run busybox detached
56-
runc run -d -b $BUSYBOX_BUNDLE --console /dev/pts/ptmx test_busybox
56+
runc run -d -b $BUSYBOX_BUNDLE --console-socket $CONSOLE_SOCKET test_busybox
5757
[ "$status" -eq 0 ]
5858

5959
wait_for_container 15 1 test_busybox
@@ -74,7 +74,7 @@ function teardown() {
7474

7575
@test "runc exec ls -la" {
7676
# run busybox detached
77-
runc run -d --console /dev/pts/ptmx test_busybox
77+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
7878
[ "$status" -eq 0 ]
7979

8080
wait_for_container 15 1 test_busybox
@@ -88,7 +88,7 @@ function teardown() {
8888

8989
@test "runc exec ls -la with --cwd" {
9090
# run busybox detached
91-
runc run -d --console /dev/pts/ptmx test_busybox
91+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
9292
[ "$status" -eq 0 ]
9393

9494
wait_for_container 15 1 test_busybox
@@ -100,7 +100,7 @@ function teardown() {
100100

101101
@test "runc exec --env" {
102102
# run busybox detached
103-
runc run -d --console /dev/pts/ptmx test_busybox
103+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
104104
[ "$status" -eq 0 ]
105105

106106
wait_for_container 15 1 test_busybox
@@ -113,7 +113,7 @@ function teardown() {
113113

114114
@test "runc exec --user" {
115115
# run busybox detached
116-
runc run -d --console /dev/pts/ptmx test_busybox
116+
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
117117
[ "$status" -eq 0 ]
118118

119119
wait_for_container 15 1 test_busybox

tests/integration/help.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ load helpers
6464
runc start -h
6565
[ "$status" -eq 0 ]
6666
[[ ${lines[1]} =~ runc\ start+ ]]
67-
67+
6868
runc run -h
6969
[ "$status" -eq 0 ]
7070
[[ ${lines[1]} =~ runc\ run+ ]]
71-
71+
7272
runc state -h
7373
[ "$status" -eq 0 ]
7474
[[ ${lines[1]} =~ runc\ state+ ]]

tests/integration/helpers.bash

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Root directory of integration tests.
44
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
55
RUNC="${INTEGRATION_ROOT}/../../runc"
6+
RECVTTY="${INTEGRATION_ROOT}/../../contrib/cmd/recvtty/recvtty"
67
GOPATH="${INTEGRATION_ROOT}/../../../.."
78

89
# Test data path.
@@ -17,7 +18,7 @@ HELLO_IMAGE="$TESTDATA/hello-world.tar"
1718
HELLO_BUNDLE="$BATS_TMPDIR/hello-world"
1819

1920
# CRIU PATH
20-
CRIU="/usr/local/sbin/criu"
21+
CRIU="$(which criu)"
2122

2223
# Kernel version
2324
KERNEL_VERSION="$(uname -r)"
@@ -28,6 +29,9 @@ KERNEL_MINOR="${KERNEL_MINOR%%.*}"
2829
# Root state path.
2930
ROOT="$BATS_TMPDIR/runc"
3031

32+
# Path to console socket.
33+
CONSOLE_SOCKET="$BATS_TMPDIR/console.sock"
34+
3135
# Cgroup mount
3236
CGROUP_BASE_PATH=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<MEMORY\>/ { print $5; exit }')
3337

@@ -142,7 +146,24 @@ function testcontainer() {
142146
[[ "${output}" == *"$2"* ]]
143147
}
144148

149+
function setup_recvtty() {
150+
# We need to start recvtty in the background, so we double fork in the shell.
151+
("$RECVTTY" --pid-file "$BATS_TMPDIR/recvtty.pid" --mode null "$CONSOLE_SOCKET" &) &
152+
}
153+
154+
function teardown_recvtty() {
155+
# When we kill recvtty, the container will also be killed.
156+
if [ -f "$BATS_TMPDIR/recvtty.pid" ]; then
157+
kill -9 $(cat "$BATS_TMPDIR/recvtty.pid")
158+
fi
159+
160+
# Clean up the files that might be left over.
161+
rm -f "$BATS_TMPDIR/recvtty.pid"
162+
rm -f "$CONSOLE_SOCKET"
163+
}
164+
145165
function setup_busybox() {
166+
setup_recvtty
146167
run mkdir "$BUSYBOX_BUNDLE"
147168
run mkdir "$BUSYBOX_BUNDLE"/rootfs
148169
if [ -e "/testdata/busybox.tar" ]; then
@@ -157,6 +178,7 @@ function setup_busybox() {
157178
}
158179

159180
function setup_hello() {
181+
setup_recvtty
160182
run mkdir "$HELLO_BUNDLE"
161183
run mkdir "$HELLO_BUNDLE"/rootfs
162184
tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
@@ -185,12 +207,14 @@ function teardown_running_container_inroot() {
185207

186208
function teardown_busybox() {
187209
cd "$INTEGRATION_ROOT"
210+
teardown_recvtty
188211
teardown_running_container test_busybox
189212
run rm -f -r "$BUSYBOX_BUNDLE"
190213
}
191214

192215
function teardown_hello() {
193216
cd "$INTEGRATION_ROOT"
217+
teardown_recvtty
194218
teardown_running_container test_hello
195219
run rm -f -r "$HELLO_BUNDLE"
196220
}

0 commit comments

Comments
 (0)