#!/bin/sh # Copyright (C) 2007 Dejan Muhamedagic # See COPYING for license information. rootdir="$(dirname "$0")" TESTDIR=${TESTDIR:-$rootdir/testcases} DFLT_TESTSET=basicset OUTDIR=${OUTDIR:-crmtestout} CRM_OUTF="$OUTDIR/crm.out" CRM_LOGF="$OUTDIR/crm.log" CRM_DEBUGF="$OUTDIR/crm.debug" OUTF="$OUTDIR/regression.out" DIFF_OPTS="--ignore-all-space -U 1" common_filter=$TESTDIR/common.filter common_exclf=$TESTDIR/common.excl export OUTDIR logmsg() { echo "$(date): $*" | tee -a "$CRM_DEBUGF" | tee -a "$CRM_LOGF" } abspath() { echo "$1" | grep -qs "^/" && echo "$1" || echo "$(pwd)/$1" } usage() { cat<"$OUTF" 2>&1 # Where to send user output # evaltest.sh also uses >&3 for printing progress dots case $output_mode in silent) exec 3>/dev/null;; buildbot) exec 3>"$CRM_OUTF";; *) exec 3>/dev/tty;; esac setenvironment() { filterf=$TESTDIR/$testcase.filter pref=$TESTDIR/$testcase.pre postf=$TESTDIR/$testcase.post exclf=$TESTDIR/$testcase.excl log_filter=$TESTDIR/$testcase.log_filter expf=$TESTDIR/$testcase.exp outf=$OUTDIR/$testcase.out difff=$OUTDIR/$testcase.diff } filter_output() { { [ -x $common_filter ] && $common_filter || cat;} | { [ -f $common_exclf ] && egrep -vf $common_exclf || cat;} | { [ -x $filterf ] && $filterf || cat;} | { [ -f $exclf ] && egrep -vf $exclf || cat;} } dumpcase() { cat</dev/null 2>&1 ) echo -n "$testcase" >&3 logmsg "BEGIN testcase $testcase" ( cd $rootdir ./evaltest.sh $testargs ) < $TESTDIR/$testcase > $outf 2>&1 perl -pi -e 's/\]*\>/\/g' $outf filter_output < $outf | if [ "$prepare" ]; then echo " saving to expect file" >&3 cat > $expf else ( cd $rootdir [ -x "$postf" ] && $postf >/dev/null 2>&1 ) echo -n " checking..." >&3 if head -2 $expf | grep -qs '^ $difff if [ $? -ne 0 ]; then echo " FAIL" >&3 cat $difff >&3 dumpcase return 1 else echo " PASS" >&3 rm -f $outf $difff fi fi sed -n "/BEGIN testcase $testcase/,\$p" $CRM_LOGF | { [ -x $log_filter ] && $log_filter || cat;} | egrep '(CRIT|ERROR):' logmsg "END testcase $testcase" } [ "$1" = prepare ] && { prepare=1; shift 1;} [ $# -eq 0 ] && set "set:$DFLT_TESTSET" testargs="" if [ -n "$do_profile" ]; then if echo $1 | grep -qs '^set:'; then echo you can profile just one test echo 'really!' exit 1 fi testargs="prof" fi for a; do if [ "$a" ] && [ -f "$TESTDIR/$a" ]; then testcase=$a runtestcase elif echo "$a" | grep -q "^set:"; then TESTSET="$TESTDIR/$(echo $a | sed 's/set://')" if [ -f "$TESTSET" ]; then while read -r testcase; do runtestcase done < "$TESTSET" else echo "testset $TESTSET does not exist" >&3 fi else echo "test $TESTDIR/$a does not exist" >&3 fi done res=`grep -E -wv '(BEGIN|END) testcase|warning: stray .* before' "$OUTF"` if [ -n "$res" ];then echo "The failed messages: $res" echo "seems like some tests failed or else something not expected" echo "check $OUTF and diff files in $OUTDIR" echo "in case you wonder what lrmd was doing, read $(abspath "$CRM_LOGF") and $(abspath "$CRM_DEBUGF")" exit 1 fi >&3