1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
#!/bin/sh
#
# Copyright (C) Cfengine AS
#
# This file is part of Cfengine 3 - written and maintained by Cfengine AS.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#
# To the extent this program is licensed as part of the Enterprise
# versions of Cfengine, the applicable Commerical Open Source License
# (COSL) may apply to this file if you as a licensee so wish it. See
# included file COSL.txt.
#
LOG=test.log
SUMMARY=summary.log
QUIET=
NOVA=
STAGING=
NETWORK=1
DEFAGENT=/var/cfengine/bin/cf-agent
AGENT=${DEFAGENT}
PASSED_TESTS=0
FAILED_TESTS=0
FAILED_TO_CRASH_TESTS=0
SKIPPED_TESTS=0
usage() {
echo "testall [-q] [--no-nova] [--staging] [--no-network] [--agent=<agent>] [<test> <test>...]"
echo
echo "If no test is given, all tests are run:"
echo " Tests with names of form NNN.cf are expected to run succesfully"
echo " Tests with names of form NNNx.cf are expected to crash"
echo " Tests with names of form NNNn.cf and NNNnx.cf are run only under Nova"
echo " (and may be disabled by --no-nova option)"
echo " Tests inside directories called 'staging' are not run"
echo " (unless --staging option is passed)"
echo " Tests inside directories called 'network' are not run"
echo " if --no-network option is passed"
echo
echo "If arguments are given, those are executed as tests"
echo
echo " -q makes script much quieter"
echo
echo " --agent provides a way to specify non-default cf-agent location,"
echo " and defaults to $DEFAGENT."
}
runtest() {
AGENT="$1"
TEST="$2"
if [ -z "$QUIET" ]; then
echo -n "$TEST "
fi
if echo "$TEST" | grep -q -F -e x.cf ; then
EXPECTED_CRASH=1
else
EXPECTED_CRASH=
fi
if [ -z "$NOVA" ] && echo "$TEST" | grep -q -e 'nx\?\.cf'; then
SKIP=1
SKIPREASON="Nova tests are disabled"
elif [ -z "$STAGING" ] && echo "$TEST" | grep -q -e 'staging'; then
SKIP=1
SKIPREASON="Staging tests are disabled"
elif [ -z "$NETWORK" ] && echo "$TEST" | grep -q -e 'network'; then
SKIP=1
SKIPREASON="Network-dependent tests are disabled"
else
SKIP=
SKIPREASON=
fi
( echo ----------------------------------------------------------------------
echo "$TEST"${EXPECTED_CRASH:+ \(expected to crash\)}${SKIPREASON:+ \($SKIPREASON\)}
echo ----------------------------------------------------------------------
) >> $LOG
if [ -z "$SKIP" ]; then
OUT=$(sudo $AGENT -Kf "$TEST" -D AUTO,DEBUG 2>&1)
RETVAL=$?
echo "$OUT" >> $LOG
echo >> $LOG
echo "Return code is $RETVAL." >> $LOG
if [ -z "$EXPECTED_CRASH" ]; then
if [ $RETVAL -eq 0 ] && echo "$OUT" | grep -q -F -e "R: $TEST Pass"; then
RESULT=Pass
else
RESULT=FAIL
fi
else
if [ $RETVAL -ne 0 ]; then
RESULT=Pass
else
RESULT="FAILed to crash"
fi
fi
FLATNAME=$(echo "$TEST" | sed 's,[./],_,g')
if [ "$RESULT" != Pass ] && [ -e .succeeded/"$FLATNAME" ]; then
echo $TEST $RESULT '(UNEXPECTED FAILURE)' >> $SUMMARY
else
echo $TEST $RESULT >> $SUMMARY
fi
if [ -z "$QUIET" ]; then
if [ "$RESULT" != Pass ] && [ -e .succeeded/"$FLATNAME" ]; then
echo $RESULT '(UNEXPECTED FAILURE)'
else
echo $RESULT
fi
else
if [ "$RESULT" = Pass ]; then
echo -n '.'
else
if [ -n "$EXPECTED_CRASH" ]; then
echo -n '!'
else
echo -n 'x'
fi
fi
fi
(
echo
echo ' ==>' $RESULT
echo
) >> $LOG
if [ "$RESULT" = Pass ]; then
PASSED_TESTS=$(($PASSED_TESTS + 1))
mkdir -p '.succeeded'
touch .succeeded/"$FLATNAME"
elif [ "$RESULT" = FAIL ]; then
FAILED_TESTS=$(($FAILED_TESTS + 1))
elif [ "$RESULT" = "FAILed to crash" ]; then
FAILED_TO_CRASH_TESTS=$(($FAILED_TO_CRASH_TESTS + 1))
fi
else
echo $TEST Skipped >> $SUMMARY
if [ -z "$QUIET" ]; then
echo Skipped
else
printf '-'
fi
SKIPPED_TESTS=$(($SKIPPED_TESTS + 1))
fi
}
while true; do
case "$1" in
--help)
usage
exit;;
-q)
QUIET=1;;
--no-nova)
NOVA=;;
--staging)
STAGING=1;;
--no-network)
NETWORK=;;
--agent=*)
AGENT=${1#--agent=};;
-*)
echo "Unknown option: $1"
exit 1;;
*)
break;;
esac
shift
done
if $AGENT -V | grep -q 'Nova'; then
NOVA=1
fi
if [ $# -gt 0 ]; then
for test in "$@"; do
if ! expr "$test" : '[/.]' >/dev/null; then
test="./$test"
fi
if [ -f $test ]; then
TESTS="$TESTS $test"
elif [ -d $test ]; then
ADDTESTS=$(find $test -name '[0-9][0-9][0-9]*.cf' | sort)
TESTS="$TESTS $ADDTESTS"
else
echo "Unable to open test file/directory: $test"
fi
done
else
TESTS=$(find $(dirname $0) -name '[0-9][0-9][0-9]*.cf' | sort)
fi
TESTS_COUNT=$(echo $TESTS | wc -w)
START_TIME=$(date +%s)
: > $SUMMARY
( echo ======================================================================
echo Testsuite started at $(date "+%F %T")
echo ----------------------------------------------------------------------
echo Total tests: $TESTS_COUNT
) > $LOG
for test in $TESTS; do
if [ -n "$USE_VALGRIND" ]; then
runtest "valgrind --leak-check=full --show-reachable=yes $AGENT" "$test"
else
runtest $AGENT "$test"
fi
done
END_TIME=$(date +%s)
( echo
echo ======================================================================
echo Testsuite finished at $(date "+%F %T") \($(($END_TIME - $START_TIME)) seconds\)
echo
echo Passed tests: $PASSED_TESTS
echo Failed tests: $FAILED_TESTS
echo Failed to crash tests: $FAILED_TO_CRASH_TESTS
echo Skipped tests: $SKIPPED_TESTS
) | tee -a $LOG
if [ "$FAILED_TESTS" -ne 0 ] || [ "$FAILED_TO_CRASH_TESTS" -ne 0 ]; then
exit 1
else
exit 0
fi
|