]> git.proxmox.com Git - mirror_lxcfs.git/blob - tests/test_proc
tree-wide: align lxcfs and lxc licensing
[mirror_lxcfs.git] / tests / test_proc
1 #!/bin/sh -eux
2 # SPDX-License-Identifier: LGPL-2.1+
3
4 PASS=0
5
6 cleanup() {
7 [ "$PASS" = "1" ] || (echo FAIL && exit 1)
8 }
9
10 trap cleanup EXIT HUP INT TERM
11
12 LXCFSDIR=${LXCFSDIR:-/var/lib/lxcfs}
13
14 if ! mountpoint -q ${LXCFSDIR}; then
15 echo "lxcfs isn't mounted on ${LXCFSDIR}"
16 exit 1
17 fi
18
19 [ ! -d /sys/fs/cgroup/memory ] && exit 0
20 [ ! -d /sys/fs/cgroup/cpuset ] && exit 0
21
22 initcpuset=`awk -F: '/cpuset/ { print $3 }' /proc/1/cgroup`
23 initmemory=`awk -F: '/memory/ { print $3 }' /proc/1/cgroup`
24
25 cpupath=/sys/fs/cgroup/cpuset/${initcpuset}
26 mempath=/sys/fs/cgroup/memory/${initmemory}
27
28 rmdir ${cpupath}/lxcfs_test_proc || true
29 rmdir ${mempath}/lxcfs_test_proc || true
30 mkdir ${cpupath}/lxcfs_test_proc
31 mkdir ${mempath}/lxcfs_test_proc
32
33 echo 1 > ${cpupath}/lxcfs_test_proc/tasks
34 echo 1 > ${mempath}/lxcfs_test_proc/tasks
35
36 echo $((64*1024*1024)) > ${mempath}/lxcfs_test_proc/memory.limit_in_bytes
37 echo 0 > ${cpupath}/lxcfs_test_proc/cpuset.cpus
38
39 # Test uptime
40 [ "$(cat ${LXCFSDIR}/proc/uptime)" = "0.00 0.00" ]
41
42 # Test cpuinfo
43 [ "$(grep "^processor" ${LXCFSDIR}/proc/cpuinfo | wc -l)" = "1" ]
44 grep -q "^processor.*0$" ${LXCFSDIR}/proc/cpuinfo || grep -q "^processor 0:.*" ${LXCFSDIR}/proc/cpuinfo
45
46 # Test stat
47 [ "$(grep "^cpu" ${LXCFSDIR}/proc/stat | wc -l)" = "2" ]
48
49 # Test meminfo
50 grep -q "^MemTotal.*65536 kB$" ${LXCFSDIR}/proc/meminfo
51
52 PASS=1
53 echo PASS