Skip to content

Commit 8591c33

Browse files
authored
Merge pull request opencontainers#2658 from kolyshkin/tests-ex-run
tests/integration: rm excessive run use; fix exec --preserve-fds test
2 parents 60b2a47 + 2ceb971 commit 8591c33

File tree

9 files changed

+43
-89
lines changed

9 files changed

+43
-89
lines changed

tests/integration/checkpoint.bats

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ function check_pipes() {
4343
echo Ping >&${in_w}
4444
exec {in_w}>&-
4545
exec {out_w}>&-
46-
run cat <&${out_r}
47-
[ "$status" -eq 0 ]
46+
output=$(cat <&${out_r})
4847
[[ "${output}" == *"ponG Ping"* ]]
4948
}
5049

@@ -159,8 +158,7 @@ function simple_cr() {
159158

160159
@test "checkpoint --lazy-pages and restore" {
161160
# check if lazy-pages is supported
162-
run "${CRIU}" check --feature uffd-noncoop
163-
if [ "$status" -eq 1 ]; then
161+
if ! "${CRIU}" check --feature uffd-noncoop; then
164162
skip "this criu does not support lazy migration"
165163
fi
166164

@@ -218,8 +216,7 @@ function simple_cr() {
218216

219217
@test "checkpoint and restore in external network namespace" {
220218
# check if external_net_ns is supported; only with criu 3.10++
221-
run "${CRIU}" check --feature external_net_ns
222-
if [ "$status" -eq 1 ]; then
219+
if ! "${CRIU}" check --feature external_net_ns; then
223220
# this criu does not support external_net_ns; skip the test
224221
skip "this criu does not support external network namespaces"
225222
fi

tests/integration/create.bats

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ function teardown() {
5151
# check pid.txt was generated
5252
[ -e pid.txt ]
5353

54-
run cat pid.txt
55-
[ "$status" -eq 0 ]
56-
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
54+
[[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]]
5755

5856
# start the command
5957
runc start test_busybox
@@ -64,10 +62,8 @@ function teardown() {
6462

6563
@test "runc create --pid-file with new CWD" {
6664
# create pid_file directory as the CWD
67-
run mkdir pid_file
68-
[ "$status" -eq 0 ]
69-
run cd pid_file
70-
[ "$status" -eq 0 ]
65+
mkdir pid_file
66+
cd pid_file
7167

7268
runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
7369
[ "$status" -eq 0 ]
@@ -77,9 +73,7 @@ function teardown() {
7773
# check pid.txt was generated
7874
[ -e pid.txt ]
7975

80-
run cat pid.txt
81-
[ "$status" -eq 0 ]
82-
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
76+
[[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]]
8377

8478
# start the command
8579
runc start test_busybox

tests/integration/debug.bats

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ function teardown() {
3535
[ -e log.out ]
3636

3737
# check expected debug output was sent to log.out
38-
run cat log.out
39-
[ "$status" -eq 0 ]
38+
output=$(cat log.out)
4039
[[ "${output}" == *"level=debug"* ]]
4140
[[ "${output}" == *"nsexec started"* ]]
4241
[[ "${output}" == *"child process in init()"* ]]
@@ -54,8 +53,7 @@ function teardown() {
5453
[ -e log.out ]
5554

5655
# check expected debug output was sent to log.out
57-
run cat log.out
58-
[ "$status" -eq 0 ]
56+
output=$(cat log.out)
5957
[[ "${output}" == *"level=debug"* ]]
6058
[[ "${output}" == *"nsexec started"* ]]
6159
[[ "${output}" == *"child process in init()"* ]]
@@ -73,8 +71,7 @@ function teardown() {
7371
[ -e log.out ]
7472

7573
# check expected debug output was sent to log.out
76-
run cat log.out
77-
[ "$status" -eq 0 ]
74+
output=$(cat log.out)
7875
[[ "${output}" == *'"level":"debug"'* ]]
7976
[[ "${output}" == *"nsexec started"* ]]
8077
[[ "${output}" == *"child process in init()"* ]]

tests/integration/delete.bats

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ function teardown() {
2828
runc state testbusyboxdelete
2929
[ "$status" -ne 0 ]
3030

31-
run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
32-
[ "$status" -eq 0 ]
31+
output=$(find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d)
3332
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
3433
}
3534

@@ -99,8 +98,7 @@ EOF
9998
runc state test_busybox
10099
[ "$status" -ne 0 ]
101100

102-
run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
103-
[ "$status" -eq 0 ]
101+
output=$(find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d)
104102
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
105103
}
106104

tests/integration/events.bats

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ function teardown() {
4949

5050
[ -e events.log ]
5151

52-
run cat events.log
53-
[ "$status" -eq 0 ]
54-
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
55-
[[ "${lines[0]}" == *"data"* ]]
52+
output=$(head -1 events.log)
53+
[[ "$output" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
54+
[[ "$output" == *"data"* ]]
5655
}
5756

5857
@test "events --interval 1s" {
@@ -78,8 +77,7 @@ function teardown() {
7877

7978
[ -e events.log ]
8079

81-
run eval "grep -q 'test_busybox' events.log"
82-
[ "$status" -eq 0 ]
80+
grep -q 'test_busybox' events.log
8381
}
8482

8583
@test "events --interval 100ms" {
@@ -108,8 +106,7 @@ function teardown() {
108106

109107
[ -e events.log ]
110108

111-
run eval "grep -q 'test_busybox' events.log"
112-
[ "$status" -eq 0 ]
109+
grep -q 'test_busybox' events.log
113110
}
114111

115112
@test "events oom" {

tests/integration/exec.bats

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ function teardown() {
3535
# check pid.txt was generated
3636
[ -e pid.txt ]
3737

38-
run cat pid.txt
39-
[ "$status" -eq 0 ]
40-
[[ ${lines[0]} =~ [0-9]+ ]]
41-
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
38+
output=$(cat pid.txt)
39+
[[ "$output" =~ [0-9]+ ]]
40+
[[ "$output" != $(__runc state test_busybox | jq '.pid') ]]
4241
}
4342

4443
@test "runc exec --pid-file with new CWD" {
4544
# create pid_file directory as the CWD
46-
run mkdir pid_file
47-
[ "$status" -eq 0 ]
48-
run cd pid_file
49-
[ "$status" -eq 0 ]
45+
mkdir pid_file
46+
cd pid_file
5047

5148
# run busybox detached
5249
runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
@@ -60,10 +57,9 @@ function teardown() {
6057
# check pid.txt was generated
6158
[ -e pid.txt ]
6259

63-
run cat pid.txt
64-
[ "$status" -eq 0 ]
65-
[[ ${lines[0]} =~ [0-9]+ ]]
66-
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
60+
output=$(cat pid.txt)
61+
[[ "$output" =~ [0-9]+ ]]
62+
[[ "$output" != $(__runc state test_busybox | jq '.pid') ]]
6763
}
6864

6965
@test "runc exec ls -la" {
@@ -133,8 +129,9 @@ function teardown() {
133129
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
134130
[ "$status" -eq 0 ]
135131

136-
run bash -c "cat hello > preserve-fds.test; exec 3<preserve-fds.test; $RUNC ${RUNC_USE_SYSTEMD:+--systemd-cgroup} --log /proc/self/fd/2 --root $ROOT exec --preserve-fds=1 test_busybox cat /proc/self/fd/3"
137-
[ "$status" -eq 0 ]
138-
139-
[[ "${output}" == *"hello"* ]]
132+
echo hello >preserve-fds.test
133+
# fd 3 is used by bats, so we use 4
134+
exec 4<preserve-fds.test
135+
output=$(__runc exec --preserve-fds=2 test_busybox cat /proc/self/fd/4)
136+
[[ "${output}" == "hello" ]]
140137
}

tests/integration/helpers.bash

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ function teardown_recvtty() {
423423

424424
function setup_busybox() {
425425
setup_recvtty
426-
run mkdir "$BUSYBOX_BUNDLE"
427-
run mkdir "$BUSYBOX_BUNDLE"/rootfs
426+
mkdir -p "$BUSYBOX_BUNDLE"/rootfs
428427
if [ -e "/testdata/busybox.tar" ]; then
429428
BUSYBOX_IMAGE="/testdata/busybox.tar"
430429
fi
@@ -438,8 +437,7 @@ function setup_busybox() {
438437

439438
function setup_hello() {
440439
setup_recvtty
441-
run mkdir "$HELLO_BUNDLE"
442-
run mkdir "$HELLO_BUNDLE"/rootfs
440+
mkdir -p "$HELLO_BUNDLE"/rootfs
443441
tar --exclude './dev/*' -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
444442
cd "$HELLO_BUNDLE"
445443
runc_spec
@@ -453,7 +451,7 @@ function setup_debian() {
453451
fi
454452

455453
setup_recvtty
456-
run mkdir "$DEBIAN_BUNDLE"
454+
mkdir -p "$DEBIAN_BUNDLE"
457455

458456
if [ ! -d "$DEBIAN_ROOTFS/rootfs" ]; then
459457
get_and_extract_debian "$DEBIAN_BUNDLE"
@@ -468,46 +466,30 @@ function setup_debian() {
468466
}
469467

470468
function teardown_running_container() {
471-
runc list
472-
# $1 should be a container name such as "test_busybox"
473-
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
474-
# e.g. "test_busybox" and "test_busybox_update"
475-
if [[ "${output}" == *"$1 "* ]]; then
476-
runc kill $1 KILL
477-
retry 10 1 eval "__runc state '$1' | grep -q 'stopped'"
478-
runc delete $1
479-
fi
469+
__runc delete -f "$1"
480470
}
481471

482472
function teardown_running_container_inroot() {
483-
ROOT=$2 runc list
484-
# $1 should be a container name such as "test_busybox"
485-
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
486-
# e.g. "test_busybox" and "test_busybox_update"
487-
if [[ "${output}" == *"$1 "* ]]; then
488-
ROOT=$2 runc kill $1 KILL
489-
retry 10 1 eval "ROOT='$2' __runc state '$1' | grep -q 'stopped'"
490-
ROOT=$2 runc delete $1
491-
fi
473+
ROOT="$2" __runc delete -f "$1"
492474
}
493475

494476
function teardown_busybox() {
495477
cd "$INTEGRATION_ROOT"
496478
teardown_recvtty
497479
teardown_running_container test_busybox
498-
run rm -f -r "$BUSYBOX_BUNDLE"
480+
rm -f -r "$BUSYBOX_BUNDLE"
499481
}
500482

501483
function teardown_hello() {
502484
cd "$INTEGRATION_ROOT"
503485
teardown_recvtty
504486
teardown_running_container test_hello
505-
run rm -f -r "$HELLO_BUNDLE"
487+
rm -f -r "$HELLO_BUNDLE"
506488
}
507489

508490
function teardown_debian() {
509491
cd "$INTEGRATION_ROOT"
510492
teardown_recvtty
511493
teardown_running_container test_debian
512-
run rm -f -r "$DEBIAN_BUNDLE"
494+
rm -f -r "$DEBIAN_BUNDLE"
513495
}

tests/integration/start_detached.bats

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ function teardown() {
4848
# check pid.txt was generated
4949
[ -e pid.txt ]
5050

51-
run cat pid.txt
52-
[ "$status" -eq 0 ]
53-
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
51+
[[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
5452
}
5553

5654
@test "runc run detached --pid-file with new CWD" {
5755
# create pid_file directory as the CWD
58-
run mkdir pid_file
59-
[ "$status" -eq 0 ]
60-
run cd pid_file
61-
[ "$status" -eq 0 ]
56+
mkdir pid_file
57+
cd pid_file
6258

6359
# run busybox detached
6460
runc run --pid-file pid.txt -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
@@ -70,7 +66,5 @@ function teardown() {
7066
# check pid.txt was generated
7167
[ -e pid.txt ]
7268

73-
run cat pid.txt
74-
[ "$status" -eq 0 ]
75-
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
69+
[[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
7670
}

tests/integration/start_hello.bats

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,5 @@ function teardown() {
5858
# check pid.txt was generated
5959
[ -e pid.txt ]
6060

61-
run cat pid.txt
62-
[ "$status" -eq 0 ]
63-
[[ ${lines[0]} =~ [0-9]+ ]]
61+
[[ "$(cat pid.txt)" =~ [0-9]+ ]]
6462
}

0 commit comments

Comments
 (0)