|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load helpers |
| 4 | + |
| 5 | +UPDATE_TEST_RUNC_ROOT="$BATS_TMPDIR/runc-cgroups-integration-test" |
| 6 | + |
| 7 | +CGROUP_MEMORY="" |
| 8 | + |
| 9 | +TEST_CGROUP_NAME="runc-cgroups-integration-test" |
| 10 | + |
| 11 | +function init_cgroup_path() { |
| 12 | + base_path=$(grep "rw," /proc/self/mountinfo | grep -i -m 1 'MEMORY$' | cut -d ' ' -f 5) |
| 13 | + CGROUP_MEMORY="${base_path}/${TEST_CGROUP_NAME}" |
| 14 | +} |
| 15 | + |
| 16 | +function teardown() { |
| 17 | + rm -f $BATS_TMPDIR/runc-update-integration-test.json |
| 18 | + teardown_running_container_inroot test_cgroups_kmem $UPDATE_TEST_RUNC_ROOT |
| 19 | + teardown_busybox |
| 20 | +} |
| 21 | + |
| 22 | +function setup() { |
| 23 | + teardown |
| 24 | + setup_busybox |
| 25 | + |
| 26 | + init_cgroup_path |
| 27 | +} |
| 28 | + |
| 29 | +function check_cgroup_value() { |
| 30 | + cgroup=$1 |
| 31 | + source=$2 |
| 32 | + expected=$3 |
| 33 | + |
| 34 | + current=$(cat $cgroup/$source) |
| 35 | + echo $cgroup/$source |
| 36 | + echo "current" $current "!?" "$expected" |
| 37 | + [ "$current" -eq "$expected" ] |
| 38 | +} |
| 39 | + |
| 40 | +@test "cgroups-kernel-memory-initialized" { |
| 41 | + # Add cgroup path |
| 42 | + sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json |
| 43 | + |
| 44 | + # Set some initial known values |
| 45 | + DATA=$(cat <<-EOF |
| 46 | + "memory": { |
| 47 | + "kernel": 16777216 |
| 48 | + }, |
| 49 | +EOF |
| 50 | + ) |
| 51 | + DATA=$(echo ${DATA} | sed 's/\n/\\n/g') |
| 52 | + sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json |
| 53 | + |
| 54 | + # start a detached busybox to work with |
| 55 | + "$RUNC" --root $UPDATE_TEST_RUNC_ROOT start -d --console /dev/pts/ptmx test_cgroups_kmem |
| 56 | + [ "$status" -eq 0 ] |
| 57 | + wait_for_container_inroot 15 1 test_cgroups_kmem $UPDATE_TEST_RUNC_ROOT |
| 58 | + |
| 59 | + # update kernel memory limit |
| 60 | + "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_cgroups_kmem --kernel-memory 50331648 |
| 61 | + [ "$status" -eq 0 ] |
| 62 | + check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648 |
| 63 | +} |
| 64 | + |
| 65 | +@test "cgroups-kernel-memory-uninitialized" { |
| 66 | + # Add cgroup path |
| 67 | + sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json |
| 68 | + |
| 69 | + # start a detached busybox to work with |
| 70 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT start -d --console /dev/pts/ptmx test_cgroups_kmem |
| 71 | + [ "$status" -eq 0 ] |
| 72 | + wait_for_container_inroot 15 1 test_cgroups_kmem $UPDATE_TEST_RUNC_ROOT |
| 73 | + |
| 74 | + # update kernel memory limit |
| 75 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_cgroups_kmem --kernel-memory 50331648 |
| 76 | + [ ! "$status" -eq 0 ] |
| 77 | +} |
0 commit comments