From fb6b16520c0ac59c0e2a5ba21b7c72b5d5486a8c Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 18 Feb 2021 18:50:10 -0800 Subject: [PATCH] tests/int/update: add test case for PR #592 Add test coverage for code initially added by commit d8b8f76c4ff584 ("Fix problem when update memory and swap memory", 2016-04-05). Signed-off-by: Kir Kolyshkin --- tests/integration/update.bats | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/integration/update.bats b/tests/integration/update.bats index c03e7c6def0..8cbde5bd91f 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -238,6 +238,42 @@ EOF check_cgroup_value "pids.max" 20 check_systemd_value "TasksMax" 20 + + if [ "$HAVE_SWAP" = "yes" ]; then + # Test case for https://github.com/opencontainers/runc/pull/592, + # checking libcontainer/cgroups/fs/memory.go:setMemoryAndSwap. + + runc update test_update --memory 30M --memory-swap 50M + [ "$status" -eq 0 ] + + check_cgroup_value $MEM_LIMIT $((30*1024*1024)) + check_systemd_value $SD_MEM_LIMIT $((30*1024*1024)) + + if [ "$CGROUP_UNIFIED" = "yes" ]; then + # for cgroupv2, swap does not include mem + check_cgroup_value "$MEM_SWAP" $((20*1024*1024)) + check_systemd_value "$SD_MEM_SWAP" $((20*1024*1024)) + else + check_cgroup_value "$MEM_SWAP" $((50*1024*1024)) + check_systemd_value "$SD_MEM_SWAP" $((50*1024*1024)) + fi + + # Now, set new memory to more than old swap + runc update test_update --memory 60M --memory-swap 80M + [ "$status" -eq 0 ] + + check_cgroup_value $MEM_LIMIT $((60*1024*1024)) + check_systemd_value $SD_MEM_LIMIT $((60*1024*1024)) + + if [ "$CGROUP_UNIFIED" = "yes" ]; then + # for cgroupv2, swap does not include mem + check_cgroup_value "$MEM_SWAP" $((20*1024*1024)) + check_systemd_value "$SD_MEM_SWAP" $((20*1024*1024)) + else + check_cgroup_value "$MEM_SWAP" $((80*1024*1024)) + check_systemd_value "$SD_MEM_SWAP" $((80*1024*1024)) + fi + fi } @test "update cgroup cpu limits" {