changelog: * test moved to separate subdirectory tools changelog v2: * set the directory in makefile * add CONFIGDIR variable
This patch create general functions and variables (made by Jan Safranek): functions: die: # Print an error message and exit # Usage: # cgclear || die "cgclear failed" cleanup() # Clear everything that was created at loading this script, i.e. # remove the temporary directory # Usage: # cleanup prepare_config # Copies a file to $TMP and replaces all occurrences of TMP in the file with # value of $TMP. The function prints the name of the new file to its std. # output. # # Usage: # cgconfigparser -l `prepare_config config/sample.conf` variables: TMP # unique temporary dir TOOLSDIR # tools directory CONFIGDIR # config files directory Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com> --- configure.in | 1 + tests/tools/testenv.sh.in | 74 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-) create mode 100644 tests/tools/testenv.sh.in diff --git a/configure.in b/configure.in index 936f113..46e2701 100644 --- a/configure.in +++ b/configure.in @@ -177,6 +177,7 @@ fi AC_CONFIG_FILES([Makefile tests/Makefile + tests/tools/testenv.sh src/Makefile src/daemon/Makefile src/tools/Makefile diff --git a/tests/tools/testenv.sh.in b/tests/tools/testenv.sh.in new file mode 100644 index 0000000..464a440 --- /dev/null +++ b/tests/tools/testenv.sh.in @@ -0,0 +1,74 @@ +#!/bin/bash + +# Simple test framework for libcgroup. +# Upon loading it does following: +# - sets $TMP, where all temporary files should be stored. +# - backs-up /etc/cgrules.conf in the $TMP +# (so it does not interfere with tests) +# +# Function cleanup() or die() must be called to destroy this temporary +# directory and restore previous cgrules.conf! +# +# Usage: +# . ./testenv.sh +# <do some testing> +# cleanup +# exit 0 + +# Print an error message and exit +# Usage: +# cgclear || die "cgclear failed" +function die() +{ + echo $* + cgclear + mv $TMP/cgrules-backup.conf /etc/cgrules.conf &>/dev/null + rm -rf $TMP + unset TMP + exit 1 +} + +# Clear everything that was created at loading this script, i.e. +# remove the temporary directory +# In addition, check that nothing remained mounted. +# Usage: +# cleanup +function cleanup() +{ + RET=0 + grep -v systemd </proc/mounts >$TMP/mounts + if grep "^cgroup" $TMP/mounts &>/dev/null; then + echo "Error: cleanup has found mounted cgroup:" + grep cgroup /proc/mounts + RET=1 + cgclear + fi + mv $TMP/cgrules-backup.conf /etc/cgrules.conf &>/dev/null + rm -rf $TMP + unset TMP + [ -z $RET ] || exit $RET +} + +# Copies a file to $TMP and replaces all occurrences of TMP in the file with +# value of $TMP. The function prints the name of the new file to its std. +# output. +# Usage: +# cgconfigparser -l `prepare_config config/sample.conf` +function prepare_config() +{ + INPUT=$1 + OUTPUT=$TMP/`basename $INPUT` + # echo -n "m4_changequote()" | m4 -P -D "TMP=$TMP" - $FILE >$OUTPUT + sed -e "s!\bTMP\b!$TMP!g" <$INPUT >$OUTPUT || ( + echo "Error: prepare config failed!" >&2; exit 1 + ) + echo $OUTPUT +} + +export TMP=`mktemp --tmpdir -d libcgroup-tmp-XXXXXXX` +# store the rules on safe place, we don't want them to mess up the tests +mv /etc/cgrules.conf $TMP/cgrules-backup.conf &>/dev/null +# tools directory +export TOOLSDIR="@abs_top_srcdir@/libtool --mode=execute @abs_top_srcdir@/src/tools/" +# config files directory +export CONFIGDIR="@abs_top_srcdir@/samples" ------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel