]> git.proxmox.com Git - mirror_lxcfs.git/blame - tests/main.sh
Merge pull request #253 from brauner/2018-08-17/prevent_double_free
[mirror_lxcfs.git] / tests / main.sh
CommitLineData
1c511f26
SH
1#!/bin/bash
2
3set -ex
4
5[ $(id -u) -eq 0 ]
6
7# Run lxcfs testsuite
8export LXCFSDIR=$(mktemp -d)
e190ee91 9pidfile=$(mktemp)
1c511f26
SH
10
11cmdline=$(realpath $0)
12dirname=$(dirname ${cmdline})
13topdir=$(dirname ${dirname})
14
15p=-1
16FAILED=1
17cleanup() {
18 set +e
19 if [ $p -ne -1 ]; then
20 kill -9 $p
21 fi
bb682ba8
SH
22 if [ ${LXCFSDIR} != "/var/lib/lxcfs" ]; then
23 umount -l ${LXCFSDIR}
24 rmdir ${LXCFSDIR}
25 fi
e190ee91 26 rm -f ${pidfile}
1c511f26
SH
27 if [ ${FAILED} -eq 1 ]; then
28 echo "FAILED at $TESTCASE"
29 exit 1
30 fi
31 echo PASSED
32 exit 0
33}
34
35TESTCASE="setup"
36lxcfs=${topdir}/lxcfs
37
bb682ba8
SH
38if [ -x ${lxcfs} ]; then
39 echo "Running ${lxcfs} ${LXCFSDIR}"
e190ee91 40 ${lxcfs} -p ${pidfile} ${LXCFSDIR} &
bb682ba8
SH
41 p=$!
42else
43 pidof lxcfs
44 echo "Using host lxcfs"
45 rmdir $LXCFSDIR
46 export LXCFSDIR=/var/lib/lxcfs
47fi
1c511f26
SH
48
49trap cleanup EXIT SIGHUP SIGINT SIGTERM
50
51count=1
52while ! mountpoint -q $LXCFSDIR; do
53 sleep 1s
54 if [ $count -gt 5 ]; then
55 echo "lxcfs failed to start"
56 false
57 fi
58 count=$((count+1))
59done
60
754c2080
SH
61RUNTEST() {
62 unshare -fmp --mount-proc $*
63}
64
1c511f26 65TESTCASE="test_proc"
754c2080 66RUNTEST ${dirname}/test_proc
1c511f26 67TESTCASE="test_cgroup"
754c2080 68RUNTEST ${dirname}/test_cgroup
1c511f26 69TESTCASE="test_read_proc.sh"
754c2080 70RUNTEST ${dirname}/test_read_proc.sh
1c511f26 71TESTCASE="cpusetrange"
754c2080 72RUNTEST ${dirname}/cpusetrange
7bc95a75 73TESTCASE="meminfo hierarchy"
754c2080 74RUNTEST ${dirname}/test_meminfo_hierarchy.sh
237e200e
SH
75TESTCASE="liblxcfs reloading"
76${dirname}/test_reload.sh
1c511f26 77
a6c00375
SH
78# Check for any defunct processes - children we didn't reap
79n=`ps -ef | grep lxcfs | grep defunct | wc -l`
80[ $n = 0 ]
81
1c511f26 82FAILED=0