]> git.proxmox.com Git - mirror_lxcfs.git/blob - tests/test_cgroup
tree-wide: align lxcfs and lxc licensing
[mirror_lxcfs.git] / tests / test_cgroup
1 #!/bin/sh -eux
2 # SPDX-License-Identifier: LGPL-2.1+
3
4 PASS=0
5 UUID=$(uuidgen)
6
7 cleanup() {
8 [ "$PASS" = "1" ] || (echo FAIL && exit 1)
9 }
10
11 LXCFSDIR=${LXCFSDIR:-/var/lib/lxcfs}
12
13 trap cleanup EXIT HUP INT TERM
14
15 if ! mountpoint -q ${LXCFSDIR}; then
16 echo "lxcfs isn't mounted on ${LXCFSDIR}"
17 exit 1
18 fi
19
20 for c in memory freezer cpuset; do
21 [ ! -d /sys/fs/cgroup/${c} ] && exit 0
22 done
23
24 initcpuset=`awk -F: '/cpuset/ { print $3 }' /proc/1/cgroup`
25 initmemory=`awk -F: '/memory/ { print $3 }' /proc/1/cgroup`
26 initfreezer=`awk -F: '/freezer/ { print $3 }' /proc/1/cgroup`
27
28 cpupath=/sys/fs/cgroup/cpuset/${initcpuset}
29 mempath=/sys/fs/cgroup/memory/${initmemory}
30 frzpath=/sys/fs/cgroup/freezer/${initfreezer}
31
32 rmdir ${cpupath}/${UUID} || true
33 rmdir ${mempath}/${UUID} || true
34 rmdir ${frzpath}/${UUID} || true
35 mkdir ${cpupath}/${UUID}
36 mkdir ${mempath}/${UUID}
37 mkdir ${frzpath}/${UUID}
38
39 # Check that the fs is readable
40 for p in ${mempath} ${frzpath} ${cpupath}; do
41 find ${p} > /dev/null
42 echo 1 > ${p}/${UUID}/tasks
43 done
44
45 # set values though lxcfs
46 echo $((64*1024*1024)) > ${LXCFSDIR}/cgroup/memory/${initmemory}/${UUID}/memory.limit_in_bytes
47 echo 0 > ${LXCFSDIR}/cgroup/cpuset/${initcpuset}/${UUID}/cpuset.cpus
48
49 # and verify them through cgroupfs
50 v=`cat $mempath/${UUID}/memory.limit_in_bytes`
51 [ "$v" = "$((64*1024*1024))" ]
52 v=`cat ${cpupath}/${UUID}/cpuset.cpus`
53 [ "$v" = "0" ]
54
55 PASS=1
56 echo PASS