]> git.proxmox.com Git - mirror_lxcfs.git/blob - tests/test_meminfo_hierarchy.sh
Merge pull request #473 from brauner/2021-08-31.fixes
[mirror_lxcfs.git] / tests / test_meminfo_hierarchy.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: LGPL-2.1+
3
4 set -eu
5 [ -n "${DEBUG:-}" ] && set -x
6
7 LXCFSDIR=${LXCFSDIR:-/var/lib/lxcfs}
8
9 cg1=$(uuidgen).$$
10 cg2=$(uuidgen).$$
11
12 cleanup() {
13 if [ $FAILED -eq 1 ]; then
14 exit 1
15 fi
16 exit 0
17 }
18
19 FAILED=1
20 trap cleanup EXIT HUP INT TERM
21
22 [ ! -d /sys/fs/cgroup/memory ] && exit 0
23 echo "==> Setting up memory cgroup"
24 initmemory=`awk -F: '/memory/ { print $3 }' /proc/1/cgroup`
25 mempath=/sys/fs/cgroup/memory/${initmemory}
26 rmdir ${mempath}/${cg1} 2>/dev/null || true
27 rmdir ${mempath}/${cg2} 2>/dev/null || true
28
29 echo "==> Testing /proc/meminfo with limit"
30 mkdir ${mempath}/${cg1}
31 echo 500000000 > ${mempath}/${cg1}/memory.limit_in_bytes
32 echo 1 > ${mempath}/${cg1}/tasks
33 m1=`awk '/^MemTotal:/ { print $2 }' ${LXCFSDIR}/proc/meminfo`
34
35 echo "==> Testing /proc/meminfo with sub-cgroup"
36 mkdir ${mempath}/${cg1}/${cg2}
37 echo 1 > ${mempath}/${cg1}/${cg2}/tasks
38 m2=`awk '/^MemTotal:/ { print $2 }' ${LXCFSDIR}/proc/meminfo`
39
40 echo "==> Confirming same limits"
41 [ $m1 -eq $m2 ]
42
43 FAILED=0