3
3
load helpers
4
4
5
5
function setup() {
6
- if [[ -n " ${RUNC_USE_SYSTEMD} " ]] ; then
7
- skip " CRIU test suite is skipped on systemd cgroup driver for now."
8
- fi
9
6
# All checkpoint tests are currently failing on v2
10
7
requires cgroups_v1
8
+ # XXX: currently criu require root containers.
9
+ requires criu root
11
10
12
11
teardown_busybox
13
12
setup_busybox
@@ -17,10 +16,34 @@ function teardown() {
17
16
teardown_busybox
18
17
}
19
18
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
+ }
23
45
46
+ @test " checkpoint and restore" {
24
47
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
25
48
[ " $status " -eq 0 ]
26
49
@@ -29,15 +52,11 @@ function teardown() {
29
52
for i in ` seq 2` ; do
30
53
# checkpoint the running container
31
54
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
35
55
cat ./work-dir/dump.log | grep -B 5 Error || true
36
- [ " $ret " -eq 0 ]
56
+ [ " $status " -eq 0 ]
37
57
38
58
# after checkpoint busybox is no longer running
39
- runc state test_busybox
40
- [ " $status " -ne 0 ]
59
+ testcontainer test_busybox checkpointed
41
60
42
61
# restore from checkpoint
43
62
runc --criu " $CRIU " restore -d --work-path ./work-dir --console-socket $CONSOLE_SOCKET test_busybox
@@ -51,32 +70,7 @@ function teardown() {
51
70
}
52
71
53
72
@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
80
74
81
75
# run busybox
82
76
__runc run -d test_busybox < & 60 >&51 2>&51
@@ -90,9 +84,7 @@ function teardown() {
90
84
[ " $status " -eq 0 ]
91
85
92
86
# busybox should still be running
93
- runc state test_busybox
94
- [ " $status " -eq 0 ]
95
- [[ " ${output} " == * " running" * ]]
87
+ testcontainer test_busybox running
96
88
97
89
# checkpoint the running container
98
90
mkdir image-dir
@@ -102,8 +94,7 @@ function teardown() {
102
94
[ " $status " -eq 0 ]
103
95
104
96
# after checkpoint busybox is no longer running
105
- runc state test_busybox
106
- [ " $status " -ne 0 ]
97
+ testcontainer test_busybox checkpointed
107
98
108
99
# restore from checkpoint
109
100
__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() {
118
109
[ " $status " -eq 0 ]
119
110
[[ ${output} == " ok" ]]
120
111
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
127
113
}
128
114
129
115
@test " checkpoint --lazy-pages and restore" {
130
- # XXX: currently criu require root containers.
131
- requires criu root
132
-
133
116
# check if lazy-pages is supported
134
117
run ${CRIU} check --feature uffd-noncoop
135
118
if [ " $status " -eq 1 ]; then
136
- # this criu does not support lazy migration; skip the test
137
119
skip " this criu does not support lazy migration"
138
120
fi
139
121
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
+
142
124
# This should not be necessary: https://github.com/checkpoint-restore/criu/issues/575
143
125
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
150
126
151
127
# For lazy migration we need to know when CRIU is ready to serve
152
128
# the memory pages via TCP.
@@ -156,21 +132,6 @@ function teardown() {
156
132
# TCP port for lazy migration
157
133
port=27277
158
134
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
-
174
135
# run busybox
175
136
__runc run -d test_busybox < & 60 >&51 2>&51
176
137
[ $? -eq 0 ]
@@ -216,8 +177,7 @@ function teardown() {
216
177
# Killing the CRIU on the checkpoint side will let the container
217
178
# continue to run if the migration failed at some point.
218
179
__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 ]
221
181
run grep -B 5 Error ./work-dir/dump.log -q
222
182
[ " $status " -eq 1 ]
223
183
@@ -228,18 +188,10 @@ function teardown() {
228
188
[ " $status " -eq 0 ]
229
189
[[ ${output} == " ok" ]]
230
190
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
237
192
}
238
193
239
194
@test " checkpoint and restore in external network namespace" {
240
- # XXX: currently criu require root containers.
241
- requires criu root
242
-
243
195
# check if external_net_ns is supported; only with criu 3.10++
244
196
run ${CRIU} check --feature external_net_ns
245
197
if [ " $status " -eq 1 ]; then
@@ -269,15 +221,13 @@ function teardown() {
269
221
# checkpoint the running container; this automatically tells CRIU to
270
222
# handle the network namespace defined in config.json as an external
271
223
runc --criu " $CRIU " checkpoint --work-path ./work-dir test_busybox
272
- ret=$?
273
224
# if you are having problems getting criu to work uncomment the following dump:
274
225
# cat /run/opencontainer/containers/test_busybox/criu.work/dump.log
275
226
cat ./work-dir/dump.log | grep -B 5 Error || true
276
- [ " $ret " -eq 0 ]
227
+ [ " $status " -eq 0 ]
277
228
278
229
# after checkpoint busybox is no longer running
279
- runc state test_busybox
280
- [ " $status " -ne 0 ]
230
+ testcontainer test_busybox checkpointed
281
231
282
232
# restore from checkpoint; this should restore the container into the existing network namespace
283
233
runc --criu " $CRIU " restore -d --work-path ./work-dir --console-socket $CONSOLE_SOCKET test_busybox
@@ -299,9 +249,6 @@ function teardown() {
299
249
}
300
250
301
251
@test " checkpoint and restore with container specific CRIU config" {
302
- # XXX: currently criu require root containers.
303
- requires criu root
304
-
305
252
tmp=` mktemp /tmp/runc-criu-XXXXXX.conf`
306
253
# This is the file we write to /etc/criu/default.conf
307
254
tmplog1=` mktemp /tmp/runc-criu-log-XXXXXX.log`
@@ -332,8 +279,7 @@ function teardown() {
332
279
test -f ./work-dir/$tmplog2
333
280
334
281
# after checkpoint busybox is no longer running
335
- runc state test_busybox
336
- [ " $status " -ne 0 ]
282
+ testcontainer test_busybox checkpointed
337
283
338
284
test -f ./work-dir/$tmplog2 && unlink ./work-dir/$tmplog2
339
285
# restore from checkpoint
0 commit comments