changelog: * test moved to separate subdirectory tools 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 Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com> --- tests/tools/testenv.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) create mode 100644 tests/tools/testenv.sh diff --git a/tests/tools/testenv.sh b/tests/tools/testenv.sh new file mode 100644 index 0000000..4fa49c6 --- /dev/null +++ b/tests/tools/testenv.sh @@ -0,0 +1,73 @@ +#!/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="../../libtool --mode=execute ../../src/tools/" + ------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel