From 1c511f260dad3b61791483f93de56879f72c5a17 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Fri, 30 Oct 2015 12:58:12 -0500 Subject: [PATCH] support running tests from travis Add a main.sh which can run a self-confined testsuite. Note that without having lxcfs_mkdir installed, we cannot mkdir as non-root user. Update the test scripts to support using a lxcfs mountpoint other than /var/lib/lxcfs Signed-off-by: Serge Hallyn --- tests/main.sh | 59 +++++++++++++++++++++++++++++++++++++++++ tests/test_cgroup | 18 +++++++------ tests/test_proc | 18 +++++++------ tests/test_read_proc.sh | 8 +++--- 4 files changed, 83 insertions(+), 20 deletions(-) create mode 100755 tests/main.sh diff --git a/tests/main.sh b/tests/main.sh new file mode 100755 index 0000000..f736e23 --- /dev/null +++ b/tests/main.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -ex + +[ $(id -u) -eq 0 ] + +# Run lxcfs testsuite +export LXCFSDIR=$(mktemp -d) + +cmdline=$(realpath $0) +dirname=$(dirname ${cmdline}) +topdir=$(dirname ${dirname}) + +p=-1 +FAILED=1 +cleanup() { + set +e + if [ $p -ne -1 ]; then + kill -9 $p + fi + umount -l ${LXCFSDIR} + rmdir ${LXCFSDIR} + if [ ${FAILED} -eq 1 ]; then + echo "FAILED at $TESTCASE" + exit 1 + fi + echo PASSED + exit 0 +} + +TESTCASE="setup" +lxcfs=${topdir}/lxcfs + +echo "Running ${lxcfs} ${LXCFSDIR}" +${lxcfs} ${LXCFSDIR} & +p=$! + +trap cleanup EXIT SIGHUP SIGINT SIGTERM + +count=1 +while ! mountpoint -q $LXCFSDIR; do + sleep 1s + if [ $count -gt 5 ]; then + echo "lxcfs failed to start" + false + fi + count=$((count+1)) +done + +TESTCASE="test_proc" +${dirname}/test_proc +TESTCASE="test_cgroup" +${dirname}/test_cgroup +TESTCASE="test_read_proc.sh" +${dirname}/test_read_proc.sh +TESTCASE="cpusetrange" +${dirname}/cpusetrange + +FAILED=0 diff --git a/tests/test_cgroup b/tests/test_cgroup index d5ad7a4..13bfb8f 100755 --- a/tests/test_cgroup +++ b/tests/test_cgroup @@ -1,4 +1,4 @@ -#!/bin/sh -eu +#!/bin/sh -eux PASS=0 @@ -6,10 +6,12 @@ cleanup() { [ "$PASS" = "1" ] || (echo FAIL && exit 1) } +LXCFSDIR=${LXCFSDIR:-/var/lib/lxcfs} + trap cleanup EXIT HUP INT TERM -if ! mountpoint -q /var/lib/lxcfs; then - echo "lxcfs isn't mounted on /var/lib/lxcfs" +if ! mountpoint -q ${LXCFSDIR}; then + echo "lxcfs isn't mounted on ${LXCFSDIR}" exit 1 fi @@ -18,7 +20,7 @@ cgm remove freezer lxcfs_test_cgroup/sub >/dev/null 2>&1 || true cgm remove all lxcfs_test_cgroup >/dev/null 2>&1 || true # Check that the fs is readable -find /var/lib/lxcfs/cgroup/ >/dev/null +find ${LXCFSDIR}/cgroup/ >/dev/null # Do some fs checks cgm create all lxcfs_test_cgroup @@ -28,15 +30,15 @@ cgm movepid all lxcfs_test_cgroup $$ CGPATH=$(cgm getpidcgroupabs freezer $$) echo $((1024*1024)) > \ - /var/lib/lxcfs/cgroup/memory/$CGPATH/memory.limit_in_bytes + ${LXCFSDIR}/cgroup/memory/$CGPATH/memory.limit_in_bytes echo 0 > \ - /var/lib/lxcfs/cgroup/cpuset/$CGPATH/cpuset.cpus + ${LXCFSDIR}/cgroup/cpuset/$CGPATH/cpuset.cpus [ "$(cgm getvalue memory $CGPATH memory.limit_in_bytes)" = "$((1024*1024))" ] [ "$(cgm getvalue cpuset $CGPATH cpuset.cpus)" = "0" ] -mkdir /var/lib/lxcfs/cgroup/freezer/$CGPATH/sub -echo $$ > /var/lib/lxcfs/cgroup/freezer/$CGPATH/sub/tasks +mkdir ${LXCFSDIR}/cgroup/freezer/$CGPATH/sub +echo $$ > ${LXCFSDIR}/cgroup/freezer/$CGPATH/sub/tasks [ "$(cgm getpidcgroupabs freezer $$)" = "$CGPATH/sub" ] diff --git a/tests/test_proc b/tests/test_proc index 9549503..b08efae 100755 --- a/tests/test_proc +++ b/tests/test_proc @@ -1,4 +1,4 @@ -#!/bin/sh -eu +#!/bin/sh -eux PASS=0 @@ -8,8 +8,10 @@ cleanup() { trap cleanup EXIT HUP INT TERM -if ! mountpoint -q /var/lib/lxcfs; then - echo "lxcfs isn't mounted on /var/lib/lxcfs" +LXCFSDIR=${LXCFSDIR:-/var/lib/lxcfs} + +if ! mountpoint -q ${LXCFSDIR}; then + echo "lxcfs isn't mounted on ${LXCFSDIR}" exit 1 fi @@ -24,18 +26,18 @@ cgm setvalue cpuset $(cgm getpidcgroupabs cpuset $$) \ cpuset.cpus 0 # Test cpuinfo -[ "$(grep "^processor" /var/lib/lxcfs/proc/cpuinfo | wc -l)" = "1" ] -grep -q "^processor.*0$" /var/lib/lxcfs/proc/cpuinfo +[ "$(grep "^processor" ${LXCFSDIR}/proc/cpuinfo | wc -l)" = "1" ] +grep -q "^processor.*0$" ${LXCFSDIR}/proc/cpuinfo # Test stat -[ "$(grep "^cpu" /var/lib/lxcfs/proc/stat | wc -l)" = "2" ] +[ "$(grep "^cpu" ${LXCFSDIR}/proc/stat | wc -l)" = "2" ] # Test meminfo -grep -q "^MemTotal.*1024 kB$" /var/lib/lxcfs/proc/meminfo +grep -q "^MemTotal.*1024 kB$" ${LXCFSDIR}/proc/meminfo # Test uptime if [ -e /proc/self/ns/user ]; then - [ "$(lxc-unshare -s 'USER|PID' cat /var/lib/lxcfs/proc/uptime)" = "0.0 0.0" ] + [ "$(lxc-unshare -s 'USER|PID' cat ${LXCFSDIR}/proc/uptime)" = "0.0 0.0" ] fi PASS=1 diff --git a/tests/test_read_proc.sh b/tests/test_read_proc.sh index de95c1e..8e3b418 100755 --- a/tests/test_read_proc.sh +++ b/tests/test_read_proc.sh @@ -1,13 +1,13 @@ -#/bin/bash -#./lxcfs -s -f -d -o allow_other -o direct_io /var/lib/lxcfs +#/bin/bash -eux +#./lxcfs -s -f -d -o allow_other -o direct_io ${DIR} red_c() { echo -e $2 "\e[31;1m${1}\e[0m" } -DIR=/var/lib/lxcfs +DIR=${LXCFSDIR:-/var/lib/lxcfs} if ! mountpoint -q $DIR; then - echo "lxcfs isn't mounted on /var/lib/lxcfs" + echo "lxcfs isn't mounted on ${DIR}" exit 1 fi -- 2.39.2