Skip to content

Commit 3a56046

Browse files
authored
Merge pull request #4945 from kolyshkin/int-cleanup-part1
tests/int: cleanup
2 parents 7f32e50 + 3c2683f commit 3a56046

23 files changed

+48
-229
lines changed

tests/integration/README.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ to end.
1010

1111
Integration tests are written in *bash* using the
1212
[bats (Bash Automated Testing System)](https://github.com/bats-core/bats-core)
13-
framework.
13+
framework. Please see
14+
[bats documentation](https://bats-core.readthedocs.io/en/stable/index.html)
15+
for more details.
1416

1517
## Running integration tests
1618

@@ -43,38 +45,9 @@ cd bats-core
4345
./install.sh /usr/local
4446
```
4547

46-
> **Note**: There are known issues running the integration tests using
47-
> **devicemapper** as a storage driver, make sure that your docker daemon
48-
> is using **aufs** if you want to successfully run the integration tests.
49-
5048
## Writing integration tests
5149

52-
[helper functions](https://github.com/opencontainers/runc/blob/master/tests/integration/helpers.bash)
50+
[Helper functions](https://github.com/opencontainers/runc/blob/master/tests/integration/helpers.bash)
5351
are provided in order to facilitate writing tests.
5452

55-
```sh
56-
#!/usr/bin/env bats
57-
58-
# This will load the helpers.
59-
load helpers
60-
61-
# setup is called at the beginning of every test.
62-
function setup() {
63-
setup_busybox
64-
}
65-
66-
# teardown is called at the end of every test.
67-
function teardown() {
68-
teardown_bundle
69-
}
70-
71-
@test "this is a simple test" {
72-
runc run containerid
73-
# "The runc macro" automatically populates $status, $output and $lines.
74-
# Please refer to bats documentation to find out more.
75-
[ "$status" -eq 0 ]
76-
77-
# check expected output
78-
[[ "${output}" == *"Hello"* ]]
79-
}
80-
```
53+
Please see existing tests for examples.

tests/integration/cgroups.bats

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,15 @@ function setup() {
113113
[[ ${lines[0]} = "0::/foo" ]]
114114

115115
# teardown: remove "/foo"
116-
# shellcheck disable=SC2016
117-
runc exec test_cgroups_group sh -uxc 'echo -memory > /sys/fs/cgroup/cgroup.subtree_control; for f in $(cat /sys/fs/cgroup/foo/cgroup.procs); do echo $f > /sys/fs/cgroup/cgroup.procs; done; rmdir /sys/fs/cgroup/foo'
116+
cat <<'EOF' | runc exec test_cgroups_group sh -eux
117+
echo -memory > /sys/fs/cgroup/cgroup.subtree_control
118+
for pid in $(cat /sys/fs/cgroup/foo/cgroup.procs); do
119+
echo $pid > /sys/fs/cgroup/cgroup.procs || true
120+
done
121+
rmdir /sys/fs/cgroup/foo
122+
EOF
118123
runc exec test_cgroups_group test ! -d /sys/fs/cgroup/foo
119124
[ "$status" -eq 0 ]
120-
#
121125
}
122126

123127
@test "runc run (cgroup v1 + unified resources should fail)" {
@@ -490,7 +494,7 @@ convert_hugetlb_size() {
490494
runc resume ct1
491495
) &
492496

493-
# Exec should not timeout or succeed.
497+
# Exec should succeed (once the container is resumed).
494498
runc exec --ignore-paused ct1 echo ok
495499
[ "$status" -eq 0 ]
496500
[ "$output" = "ok" ]

tests/integration/checkpoint.bats

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,14 @@ function simple_cr() {
126126
testcontainer test_busybox running
127127

128128
for _ in $(seq 2); do
129-
# checkpoint the running container
130129
runc "$@" checkpoint --work-path ./work-dir test_busybox
131130
[ "$status" -eq 0 ]
132131

133-
# after checkpoint busybox is no longer running
134132
testcontainer test_busybox checkpointed
135133

136-
# restore from checkpoint
137134
runc "$@" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
138135
[ "$status" -eq 0 ]
139136

140-
# busybox should be back up and running
141137
testcontainer test_busybox running
142138
done
143139
}
@@ -160,27 +156,23 @@ function simple_cr_with_netdevice() {
160156
[ "$status" -eq 0 ]
161157

162158
testcontainer test_busybox_netdevice running
163-
run runc exec test_busybox_netdevice ip address show dev dummy0
159+
runc exec test_busybox_netdevice ip address show dev dummy0
164160
[ "$status" -eq 0 ]
165161
[[ "$output" == *" $global_ip "* ]]
166162
[[ "$output" == *"ether $mac_address "* ]]
167163
[[ "$output" == *"mtu $mtu_value "* ]]
168164

169165
for _ in $(seq 2); do
170-
# checkpoint the running container
171166
runc "$@" checkpoint --work-path ./work-dir test_busybox_netdevice
172167
[ "$status" -eq 0 ]
173168

174-
# after checkpoint busybox is no longer running
175169
testcontainer test_busybox_netdevice checkpointed
176170

177-
# restore from checkpoint
178171
runc "$@" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox_netdevice
179172
[ "$status" -eq 0 ]
180173

181-
# busybox should be back up and running
182174
testcontainer test_busybox_netdevice running
183-
run runc exec test_busybox_netdevice ip address show dev dummy0
175+
runc exec test_busybox_netdevice ip address show dev dummy0
184176
[ "$status" -eq 0 ]
185177
[[ "$output" == *" $global_ip "* ]]
186178
[[ "$output" == *"ether $mac_address "* ]]
@@ -271,15 +263,12 @@ function simple_cr_with_netdevice() {
271263
setup_pipes
272264
runc_run_with_pipes test_busybox
273265

274-
#test checkpoint pre-dump
275266
mkdir parent-dir
276267
runc checkpoint --pre-dump --image-path ./parent-dir test_busybox
277268
[ "$status" -eq 0 ]
278269

279-
# busybox should still be running
280270
testcontainer test_busybox running
281271

282-
# checkpoint the running container
283272
mkdir image-dir
284273
mkdir work-dir
285274
runc checkpoint --parent-path ../parent-dir --work-path ./work-dir --image-path ./image-dir test_busybox
@@ -288,7 +277,6 @@ function simple_cr_with_netdevice() {
288277
# check parent path is valid
289278
[ -e ./image-dir/parent ]
290279

291-
# after checkpoint busybox is no longer running
292280
testcontainer test_busybox checkpointed
293281

294282
runc_restore_with_pipes ./work-dir test_busybox
@@ -302,7 +290,6 @@ function simple_cr_with_netdevice() {
302290
setup_pipes
303291
runc_run_with_pipes test_busybox
304292

305-
# checkpoint the running container
306293
mkdir image-dir
307294
mkdir work-dir
308295

@@ -391,14 +378,12 @@ function simple_cr_with_netdevice() {
391378
runc checkpoint --work-path ./work-dir test_busybox
392379
[ "$status" -eq 0 ]
393380

394-
# after checkpoint busybox is no longer running
395381
testcontainer test_busybox checkpointed
396382

397383
# restore from checkpoint; this should restore the container into the existing network namespace
398384
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
399385
[ "$status" -eq 0 ]
400386

401-
# busybox should be back up and running
402387
testcontainer test_busybox running
403388

404389
# container should be running in same network namespace as before
@@ -436,23 +421,20 @@ function simple_cr_with_netdevice() {
436421

437422
testcontainer test_busybox running
438423

439-
# checkpoint the running container
440424
runc checkpoint --work-path ./work-dir test_busybox
441425
[ "$status" -eq 0 ]
442426
run ! test -f ./work-dir/"$tmplog1"
443427
test -f ./work-dir/"$tmplog2"
444428

445-
# after checkpoint busybox is no longer running
446429
testcontainer test_busybox checkpointed
447430

448431
test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2"
449-
# restore from checkpoint
432+
450433
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
451434
[ "$status" -eq 0 ]
452435
run ! test -f ./work-dir/"$tmplog1"
453436
test -f ./work-dir/"$tmplog2"
454437

455-
# busybox should be back up and running
456438
testcontainer test_busybox running
457439
unlink "$tmp"
458440
test -f ./work-dir/"$tmplog2" && unlink ./work-dir/"$tmplog2"
@@ -479,22 +461,18 @@ function simple_cr_with_netdevice() {
479461

480462
testcontainer test_busybox running
481463

482-
# checkpoint the running container
483464
runc checkpoint --work-path ./work-dir test_busybox
484465
[ "$status" -eq 0 ]
485466

486-
# after checkpoint busybox is no longer running
487467
testcontainer test_busybox checkpointed
488468

489469
# cleanup mountpoints created by runc during creation
490470
# the mountpoints should be recreated during restore - that is the actual thing tested here
491471
rm -rf "${bind1:?}"/*
492472

493-
# restore from checkpoint
494473
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
495474
[ "$status" -eq 0 ]
496475

497-
# busybox should be back up and running
498476
testcontainer test_busybox running
499477
}
500478

@@ -545,18 +523,14 @@ function simple_cr_with_netdevice() {
545523

546524
local execed_pid=""
547525
for _ in $(seq 2); do
548-
# checkpoint the running container
549526
runc checkpoint --work-path ./work-dir test_busybox
550527
[ "$status" -eq 0 ]
551528

552-
# after checkpoint busybox is no longer running
553529
testcontainer test_busybox checkpointed
554530

555-
# restore from checkpoint
556531
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
557532
[ "$status" -eq 0 ]
558533

559-
# busybox should be back up and running
560534
testcontainer test_busybox running
561535

562536
# verify that previously exec'd process is restored.

tests/integration/create.bats

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function teardown() {
1616

1717
testcontainer test_busybox created
1818

19-
# start the command
2019
runc start test_busybox
2120
[ "$status" -eq 0 ]
2221

@@ -34,7 +33,6 @@ function teardown() {
3433

3534
testcontainer test_busybox created
3635

37-
# start the command
3836
runc start test_busybox
3937
[ "$status" -eq 0 ]
4038

@@ -47,12 +45,9 @@ function teardown() {
4745

4846
testcontainer test_busybox created
4947

50-
# check pid.txt was generated
5148
[ -e pid.txt ]
52-
5349
[[ $(cat pid.txt) = $(__runc state test_busybox | jq '.pid') ]]
5450

55-
# start the command
5651
runc start test_busybox
5752
[ "$status" -eq 0 ]
5853

@@ -61,7 +56,6 @@ function teardown() {
6156

6257
@test "runc create --pid-file with new CWD" {
6358
bundle="$(pwd)"
64-
# create pid_file directory as the CWD
6559
mkdir pid_file
6660
cd pid_file
6761

@@ -70,12 +64,9 @@ function teardown() {
7064

7165
testcontainer test_busybox created
7266

73-
# check pid.txt was generated
7467
[ -e pid.txt ]
75-
7668
[[ $(cat pid.txt) = $(__runc state test_busybox | jq '.pid') ]]
7769

78-
# start the command
7970
runc start test_busybox
8071
[ "$status" -eq 0 ]
8172

tests/integration/debug.bats

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function check_debug() {
1818
}
1919

2020
@test "global --debug" {
21-
# run hello-world
2221
runc --debug run test_hello
2322
[ "$status" -eq 0 ]
2423

@@ -28,7 +27,6 @@ function check_debug() {
2827
}
2928

3029
@test "global --debug to --log" {
31-
# run hello-world
3230
runc --log log.out --debug run test_hello
3331
[ "$status" -eq 0 ]
3432

@@ -43,7 +41,6 @@ function check_debug() {
4341
}
4442

4543
@test "global --debug to --log --log-format 'text'" {
46-
# run hello-world
4744
runc --log log.out --log-format "text" --debug run test_hello
4845
[ "$status" -eq 0 ]
4946

@@ -58,7 +55,6 @@ function check_debug() {
5855
}
5956

6057
@test "global --debug to --log --log-format 'json'" {
61-
# run hello-world
6258
runc --log log.out --log-format "json" --debug run test_hello
6359
[ "$status" -eq 0 ]
6460

tests/integration/delete.bats

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,11 @@ function test_runc_delete_host_pidns() {
115115
}
116116

117117
@test "runc delete --force" {
118-
# run busybox detached
119118
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
120119
[ "$status" -eq 0 ]
121120

122-
# check state
123121
testcontainer test_busybox running
124122

125-
# force delete test_busybox
126123
runc delete --force test_busybox
127124

128125
runc state test_busybox
@@ -145,11 +142,19 @@ function test_runc_delete_host_pidns() {
145142
}
146143

147144
@test "runc delete --force [paused container]" {
145+
requires cgroups_freezer
146+
if [ $EUID -ne 0 ]; then
147+
requires rootless_cgroup
148+
# Rootless containers have no default cgroup path.
149+
set_cgroups_path
150+
fi
151+
148152
runc run -d --console-socket "$CONSOLE_SOCKET" ct1
149153
[ "$status" -eq 0 ]
150154
testcontainer ct1 running
151155

152156
runc pause ct1
157+
[ "$status" -eq 0 ]
153158
runc delete --force ct1
154159
[ "$status" -eq 0 ]
155160
}
@@ -209,11 +214,9 @@ EOF
209214
set_cgroups_path
210215
set_cgroup_mount_writable
211216

212-
# run busybox detached
213217
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
214218
[ "$status" -eq 0 ]
215219

216-
# check state
217220
testcontainer test_busybox running
218221

219222
# create a sub process

tests/integration/events.bats

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ function test_events() {
4747
[ $EUID -ne 0 ] && requires rootless_cgroup
4848
init_cgroup_paths
4949

50-
# run busybox detached
5150
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
5251
[ "$status" -eq 0 ]
5352

@@ -121,7 +120,6 @@ function test_events() {
121120
# we need the container to hit OOM, so disable swap
122121
update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}'
123122

124-
# run busybox detached
125123
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
126124
[ "$status" -eq 0 ]
127125

0 commit comments

Comments
 (0)