Skip to content

Commit e530b2a

Browse files
kolyshkinlifubang
authored andcommitted
tests/int/update: fix v2 swap check
If swap is disabled, we should not run swap tests. Fixes 4166. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 8fc5be4 commit e530b2a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tests/integration/update.bats

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ function setup() {
3838
MEM_SWAP="memory.memsw.limit_in_bytes"
3939
SD_MEM_SWAP="unsupported"
4040
SYSTEM_MEM=$(cat "${CGROUP_MEMORY_BASE_PATH}/${MEM_LIMIT}")
41-
HAVE_SWAP="no"
42-
if [ -f "${CGROUP_MEMORY_BASE_PATH}/${MEM_SWAP}" ]; then
43-
HAVE_SWAP="yes"
44-
fi
4541
else
4642
MEM_LIMIT="memory.max"
4743
SD_MEM_LIMIT="MemoryMax"
@@ -50,9 +46,11 @@ function setup() {
5046
MEM_SWAP="memory.swap.max"
5147
SD_MEM_SWAP="MemorySwapMax"
5248
SYSTEM_MEM="max"
53-
HAVE_SWAP="yes"
5449
fi
5550

51+
unset HAVE_SWAP
52+
get_cgroup_value $MEM_SWAP >/dev/null && HAVE_SWAP=yes
53+
5654
SD_UNLIMITED="infinity"
5755
SD_VERSION=$(systemctl --version | awk '{print $2; exit}')
5856
if [ "$SD_VERSION" -lt 227 ]; then
@@ -94,8 +92,8 @@ function setup() {
9492
check_cgroup_value "$MEM_RESERVE" 33554432
9593
check_systemd_value "$SD_MEM_RESERVE" 33554432
9694

97-
# Run swap memory tests if swap is available
98-
if [ "$HAVE_SWAP" = "yes" ]; then
95+
# Run swap memory tests if swap is available.
96+
if [ -v HAVE_SWAP ]; then
9997
# try to remove memory swap limit
10098
runc update test_update --memory-swap -1
10199
[ "$status" -eq 0 ]
@@ -127,7 +125,7 @@ function setup() {
127125
check_systemd_value "$SD_MEM_LIMIT" "$SD_UNLIMITED"
128126

129127
# check swap memory limited is gone
130-
if [ "$HAVE_SWAP" = "yes" ]; then
128+
if [ -v HAVE_SWAP ]; then
131129
check_cgroup_value "$MEM_SWAP" "$SYSTEM_MEM"
132130
check_systemd_value "$SD_MEM_SWAP" "$SD_UNLIMITED"
133131
fi
@@ -221,7 +219,7 @@ EOF
221219
check_cgroup_value "pids.max" 20
222220
check_systemd_value "TasksMax" 20
223221

224-
if [ "$HAVE_SWAP" = "yes" ]; then
222+
if [ -v HAVE_SWAP ]; then
225223
# Test case for https://github.com/opencontainers/runc/pull/592,
226224
# checking libcontainer/cgroups/fs/memory.go:setMemoryAndSwap.
227225

0 commit comments

Comments
 (0)