2016-05-05 10:12:25 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
TEST_CGROUP_NAME="runc-cgroups-integration-test"
|
2016-08-05 19:17:06 +08:00
|
|
|
CGROUP_MEMORY="${CGROUP_BASE_PATH}/${TEST_CGROUP_NAME}"
|
2016-05-05 10:12:25 +08:00
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
rm -f $BATS_TMPDIR/runc-update-integration-test.json
|
2016-05-11 14:17:32 +08:00
|
|
|
teardown_running_container test_cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
teardown_busybox
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
teardown
|
|
|
|
setup_busybox
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_cgroup_value() {
|
|
|
|
cgroup=$1
|
|
|
|
source=$2
|
|
|
|
expected=$3
|
|
|
|
|
|
|
|
current=$(cat $cgroup/$source)
|
|
|
|
echo $cgroup/$source
|
|
|
|
echo "current" $current "!?" "$expected"
|
|
|
|
[ "$current" -eq "$expected" ]
|
|
|
|
}
|
|
|
|
|
2016-05-11 14:17:32 +08:00
|
|
|
@test "runc update --kernel-memory (initialized)" {
|
2016-08-05 19:17:06 +08:00
|
|
|
requires cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
# Add cgroup path
|
2016-08-07 10:47:09 +08:00
|
|
|
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "\/runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
|
2016-05-05 10:12:25 +08:00
|
|
|
|
|
|
|
# Set some initial known values
|
|
|
|
DATA=$(cat <<-EOF
|
|
|
|
"memory": {
|
|
|
|
"kernel": 16777216
|
|
|
|
},
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
DATA=$(echo ${DATA} | sed 's/\n/\\n/g')
|
|
|
|
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
|
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# run a detached busybox to work with
|
|
|
|
runc run -d --console /dev/pts/ptmx test_cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-11 14:17:32 +08:00
|
|
|
wait_for_container 15 1 test_cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
|
|
|
|
# update kernel memory limit
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_cgroups_kmem --kernel-memory 50331648
|
2016-05-05 10:12:25 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-09 21:06:42 +08:00
|
|
|
|
|
|
|
# check the value
|
2016-05-05 10:12:25 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
|
|
|
|
}
|
|
|
|
|
2016-05-11 14:17:32 +08:00
|
|
|
@test "runc update --kernel-memory (uninitialized)" {
|
2016-08-05 19:17:06 +08:00
|
|
|
requires cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
# Add cgroup path
|
2016-08-07 10:47:09 +08:00
|
|
|
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "\/runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
|
2016-05-05 10:12:25 +08:00
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# run a detached busybox to work with
|
|
|
|
runc run -d --console /dev/pts/ptmx test_cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-11 14:17:32 +08:00
|
|
|
wait_for_container 15 1 test_cgroups_kmem
|
2016-05-05 10:12:25 +08:00
|
|
|
|
|
|
|
# update kernel memory limit
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_cgroups_kmem --kernel-memory 50331648
|
2016-05-18 08:51:02 +08:00
|
|
|
# Since kernel 4.6, we can update kernel memory without initialization
|
|
|
|
# because it's accounted by default.
|
|
|
|
if [ "$KERNEL_MAJOR" -lt 4 ] || [ "$KERNEL_MAJOR" -eq 4 -a "$KERNEL_MINOR" -le 5 ]; then
|
|
|
|
[ ! "$status" -eq 0 ]
|
|
|
|
else
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
|
|
|
|
fi
|
2016-05-05 10:12:25 +08:00
|
|
|
}
|