Skip to content

Commit cdce577

Browse files
authored
Merge pull request #2332 from kolyshkin/cgroupv2-cr
Fix/improve checkpoint integration tests
2 parents 46be7b6 + d5e68ce commit cdce577

File tree

2 files changed

+46
-96
lines changed

2 files changed

+46
-96
lines changed

tests/integration/checkpoint.bats

Lines changed: 42 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
load helpers
44

55
function setup() {
6-
if [[ -n "${RUNC_USE_SYSTEMD}" ]] ; then
7-
skip "CRIU test suite is skipped on systemd cgroup driver for now."
8-
fi
96
# All checkpoint tests are currently failing on v2
107
requires cgroups_v1
8+
# XXX: currently criu require root containers.
9+
requires criu root
1110

1211
teardown_busybox
1312
setup_busybox
@@ -17,10 +16,34 @@ function teardown() {
1716
teardown_busybox
1817
}
1918

20-
@test "checkpoint and restore" {
21-
# XXX: currently criu require root containers.
22-
requires criu root
19+
function setup_pipes() {
20+
# The changes to 'terminal' are needed for running in detached mode
21+
sed -i 's;"terminal": true;"terminal": false;' config.json
22+
sed -i 's/"sh"/"sh","-c","for i in `seq 10`; do read xxx || continue; echo ponG $xxx; done"/' config.json
23+
24+
# Create two sets of pipes
25+
# for stdout/stderr
26+
exec 52<> <(:)
27+
exec 50</proc/self/fd/52
28+
exec 51>/proc/self/fd/52
29+
exec 52>&-
30+
# ... and stdin
31+
exec 62<> <(:)
32+
exec 60</proc/self/fd/62
33+
exec 61>/proc/self/fd/62
34+
exec 62>&-
35+
}
36+
37+
function check_pipes() {
38+
echo Ping >&61
39+
exec 61>&-
40+
exec 51>&-
41+
run cat <&50
42+
[ "$status" -eq 0 ]
43+
[[ "${output}" == *"ponG Ping"* ]]
44+
}
2345

46+
@test "checkpoint and restore" {
2447
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
2548
[ "$status" -eq 0 ]
2649

@@ -29,15 +52,11 @@ function teardown() {
2952
for i in `seq 2`; do
3053
# checkpoint the running container
3154
runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox
32-
ret=$?
33-
# if you are having problems getting criu to work uncomment the following dump:
34-
#cat /run/opencontainer/containers/test_busybox/criu.work/dump.log
3555
cat ./work-dir/dump.log | grep -B 5 Error || true
36-
[ "$ret" -eq 0 ]
56+
[ "$status" -eq 0 ]
3757

3858
# after checkpoint busybox is no longer running
39-
runc state test_busybox
40-
[ "$status" -ne 0 ]
59+
testcontainer test_busybox checkpointed
4160

4261
# restore from checkpoint
4362
runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket $CONSOLE_SOCKET test_busybox
@@ -51,32 +70,7 @@ function teardown() {
5170
}
5271

5372
@test "checkpoint --pre-dump and restore" {
54-
# XXX: currently criu require root containers.
55-
requires criu root
56-
57-
# The changes to 'terminal' are needed for running in detached mode
58-
sed -i 's;"terminal": true;"terminal": false;' config.json
59-
sed -i 's/"sh"/"sh","-c","for i in `seq 10`; do read xxx || continue; echo ponG $xxx; done"/' config.json
60-
61-
# The following code creates pipes for stdin and stdout.
62-
# CRIU can't handle fifo-s, so we need all these tricks.
63-
fifo=`mktemp -u /tmp/runc-fifo-XXXXXX`
64-
mkfifo $fifo
65-
66-
# stdout
67-
cat $fifo | cat $fifo &
68-
pid=$!
69-
exec 50</proc/$pid/fd/0
70-
exec 51>/proc/$pid/fd/0
71-
72-
# stdin
73-
cat $fifo | cat $fifo &
74-
pid=$!
75-
exec 60</proc/$pid/fd/0
76-
exec 61>/proc/$pid/fd/0
77-
78-
echo -n > $fifo
79-
unlink $fifo
73+
setup_pipes
8074

8175
# run busybox
8276
__runc run -d test_busybox <&60 >&51 2>&51
@@ -90,9 +84,7 @@ function teardown() {
9084
[ "$status" -eq 0 ]
9185

9286
# busybox should still be running
93-
runc state test_busybox
94-
[ "$status" -eq 0 ]
95-
[[ "${output}" == *"running"* ]]
87+
testcontainer test_busybox running
9688

9789
# checkpoint the running container
9890
mkdir image-dir
@@ -102,8 +94,7 @@ function teardown() {
10294
[ "$status" -eq 0 ]
10395

10496
# after checkpoint busybox is no longer running
105-
runc state test_busybox
106-
[ "$status" -ne 0 ]
97+
testcontainer test_busybox checkpointed
10798

10899
# restore from checkpoint
109100
__runc --criu "$CRIU" restore -d --work-path ./work-dir --image-path ./image-dir test_busybox <&60 >&51 2>&51
@@ -118,35 +109,20 @@ function teardown() {
118109
[ "$status" -eq 0 ]
119110
[[ ${output} == "ok" ]]
120111

121-
echo Ping >&61
122-
exec 61>&-
123-
exec 51>&-
124-
run cat <&50
125-
[ "$status" -eq 0 ]
126-
[[ "${output}" == *"ponG Ping"* ]]
112+
check_pipes
127113
}
128114

129115
@test "checkpoint --lazy-pages and restore" {
130-
# XXX: currently criu require root containers.
131-
requires criu root
132-
133116
# check if lazy-pages is supported
134117
run ${CRIU} check --feature uffd-noncoop
135118
if [ "$status" -eq 1 ]; then
136-
# this criu does not support lazy migration; skip the test
137119
skip "this criu does not support lazy migration"
138120
fi
139121

140-
# The changes to 'terminal' are needed for running in detached mode
141-
sed -i 's;"terminal": true;"terminal": false;' config.json
122+
setup_pipes
123+
142124
# This should not be necessary: https://github.com/checkpoint-restore/criu/issues/575
143125
sed -i 's;"readonly": true;"readonly": false;' config.json
144-
sed -i 's/"sh"/"sh","-c","for i in `seq 10`; do read xxx || continue; echo ponG $xxx; done"/' config.json
145-
146-
# The following code creates pipes for stdin and stdout.
147-
# CRIU can't handle fifo-s, so we need all these tricks.
148-
fifo=`mktemp -u /tmp/runc-fifo-XXXXXX`
149-
mkfifo $fifo
150126

151127
# For lazy migration we need to know when CRIU is ready to serve
152128
# the memory pages via TCP.
@@ -156,21 +132,6 @@ function teardown() {
156132
# TCP port for lazy migration
157133
port=27277
158134

159-
# stdout
160-
cat $fifo | cat $fifo &
161-
pid=$!
162-
exec 50</proc/$pid/fd/0
163-
exec 51>/proc/$pid/fd/0
164-
165-
# stdin
166-
cat $fifo | cat $fifo &
167-
pid=$!
168-
exec 60</proc/$pid/fd/0
169-
exec 61>/proc/$pid/fd/0
170-
171-
echo -n > $fifo
172-
unlink $fifo
173-
174135
# run busybox
175136
__runc run -d test_busybox <&60 >&51 2>&51
176137
[ $? -eq 0 ]
@@ -216,8 +177,7 @@ function teardown() {
216177
# Killing the CRIU on the checkpoint side will let the container
217178
# continue to run if the migration failed at some point.
218179
__runc --criu "$CRIU" restore -d --work-path ./image-dir --image-path ./image-dir --lazy-pages test_busybox_restore <&60 >&51 2>&51
219-
ret=$?
220-
[ $ret -eq 0 ]
180+
[ $? -eq 0 ]
221181
run grep -B 5 Error ./work-dir/dump.log -q
222182
[ "$status" -eq 1 ]
223183

@@ -228,18 +188,10 @@ function teardown() {
228188
[ "$status" -eq 0 ]
229189
[[ ${output} == "ok" ]]
230190

231-
echo Ping >&61
232-
exec 61>&-
233-
exec 51>&-
234-
run cat <&50
235-
[ "$status" -eq 0 ]
236-
[[ "${output}" == *"ponG Ping"* ]]
191+
check_pipes
237192
}
238193

239194
@test "checkpoint and restore in external network namespace" {
240-
# XXX: currently criu require root containers.
241-
requires criu root
242-
243195
# check if external_net_ns is supported; only with criu 3.10++
244196
run ${CRIU} check --feature external_net_ns
245197
if [ "$status" -eq 1 ]; then
@@ -269,15 +221,13 @@ function teardown() {
269221
# checkpoint the running container; this automatically tells CRIU to
270222
# handle the network namespace defined in config.json as an external
271223
runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox
272-
ret=$?
273224
# if you are having problems getting criu to work uncomment the following dump:
274225
#cat /run/opencontainer/containers/test_busybox/criu.work/dump.log
275226
cat ./work-dir/dump.log | grep -B 5 Error || true
276-
[ "$ret" -eq 0 ]
227+
[ "$status" -eq 0 ]
277228

278229
# after checkpoint busybox is no longer running
279-
runc state test_busybox
280-
[ "$status" -ne 0 ]
230+
testcontainer test_busybox checkpointed
281231

282232
# restore from checkpoint; this should restore the container into the existing network namespace
283233
runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket $CONSOLE_SOCKET test_busybox
@@ -299,9 +249,6 @@ function teardown() {
299249
}
300250

301251
@test "checkpoint and restore with container specific CRIU config" {
302-
# XXX: currently criu require root containers.
303-
requires criu root
304-
305252
tmp=`mktemp /tmp/runc-criu-XXXXXX.conf`
306253
# This is the file we write to /etc/criu/default.conf
307254
tmplog1=`mktemp /tmp/runc-criu-log-XXXXXX.log`
@@ -332,8 +279,7 @@ function teardown() {
332279
test -f ./work-dir/$tmplog2
333280

334281
# after checkpoint busybox is no longer running
335-
runc state test_busybox
336-
[ "$status" -ne 0 ]
282+
testcontainer test_busybox checkpointed
337283

338284
test -f ./work-dir/$tmplog2 && unlink ./work-dir/$tmplog2
339285
# restore from checkpoint

tests/integration/helpers.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ function wait_for_container_inroot() {
310310
function testcontainer() {
311311
# test state of container
312312
runc state $1
313+
if [ $2 == "checkpointed" ]; then
314+
[ "$status" -eq 1 ]
315+
return
316+
fi
313317
[ "$status" -eq 0 ]
314318
[[ "${output}" == *"$2"* ]]
315319
}

0 commit comments

Comments
 (0)