5 # RETURNS: Number of failed tests.
7 # CALLS: eval_oneprogram.sh [-h][-lk] <program>
15 # HOW TO ENTER A NEW TEST
17 # Copy the template file (T2.sh) XXX to the tests directory, and have
18 # the file begin with a 'T'. All files in the tests directory
19 # begining with a 'T' are assumed to be a test. See the file for
20 # further instructions
22 # HOW TESTS ARE RUN AND EVALUATED
29 # Suggested improvement(s):
30 # Run a given test against a running agent.
32 # interactively pick tests to run.
33 # options arguments to pick tests to run.
36 # Variables: (* = exported)
37 # *SNMP_BASEDIR: the source base directory for tests
38 # *SNMP_UPDIR: directory above where the test binaries live (-D option)
39 # *SNMP_PATH ## yes, PATH is already setup
40 # *SNMP_VERBOSE ## 0=silent, 1=warnings, 2=more
42 # Usage mess. (No, it works.)
44 USAGE="Usage: `basename $0` [-h] [-i] [-v] [-V] [-s] [-T TESTNUMS] [-D bindir] [-S seconds]"
49 #cat <<BLIK | sed 's/^#//' | sed '1d' | $PAGER
55 trap "exit 1;" 1 2 3 9 13 15 17
57 SNMP_BASEDIR=`dirname $0`
59 ### Check for the configuration script.
60 ##if [ ! -s "${SNMP_BASEDIR}/TESTCONF.sh" ] ; then
61 ## echo "No TESTCONF.sh in \"$SNMP_BASEDIR\" ; exiting"
65 ORIGDIR=`pwd` ## this script may be invoked with relative path
66 SNMP_UPDIR=.. ## building from the source tree
69 SNMP_SLEEP=${SNMP_SLEEP:=1} ## default seconds to sleep
89 SNMP_SAVE_TMPDIR="yes"
90 export SNMP_SAVE_TMPDIR
125 # Find executables in source first, then build, then existing PATH.
126 ## Add to PATH if a binary is found.
131 if [ -f "$bf" ] ; then
132 PATH=$SNMP_UPDIR:$PATH
135 if [ -f "$bf" ] ; then
136 PATH=$SNMP_UPDIR/apps:$PATH
140 if [ -f "$bf" ] ; then
141 PATH=$SNMP_UPDIR/agent:$PATH
144 bf=include/net-snmp/net-snmp-config.h
145 if [ ! -s "$bf" ] ; then
146 echo "No \"$bf\" in $SNMP_UPDIR . Some tests will be skipped"
150 # Run from the test scripts directory.
151 cd $ORIGDIR ; cd ${SNMP_BASEDIR}
154 # Setup for the next test run.
155 rm -f core tests/core
157 PATH=${SNMP_BASEDIR}:$PATH
167 $WHICH $0 > /dev/null 2>&1
168 if [ $? -ne 0 ] ; then
172 for needed in snmpd snmpget snmpgetnext; do
173 $WHICH $needed > /dev/null 2>&1
174 if [ $? -ne 0 ] ; then
175 echo "No $needed found. Exiting"
181 # Distinguished expectations.
183 if [ $SNMP_VERBOSE -gt 0 ]; then
184 echo ${SNMP_UPDIR}/testing
186 echo top of build is $SNMP_UPDIR
187 echo source testing is $SNMP_BASEDIR
192 # Source the testing configuration file
197 # Hack: the above created a directory, now we have to nuke it and
198 # forget about it... All for the convenience of the test writer.
204 # Switch to the testing directory, for ease of the client test packages.
208 #------------------------------------ -o-
214 TMPFILE=$SNMP_TMPDIR/eval_suite.sh$$
221 if [ "x$do_tests" = "x" ]; then
223 # List the tests in question
226 for testfile in T*; do
228 # Skip backup files, and the like.
237 if [ "x$interactive" != "xyes" -a "x$test_nums" = "x" ]; then
238 eval_onescript.sh $testfile $num "yes"
240 all_tests="$all_tests $num"
241 all_files="$all_files $testfile"
247 # TODO: allow user to interactively pick the list of tests to run.
250 if [ "x$interactive" != "xyes" ]; then
251 if [ "x$test_nums" = "x" ]; then
252 ECHO "Enter test numbers [all]: "
255 if [ "x$test_nums" = "xall" ]; then
261 if [ "x$inp" = "x" ]; then
262 do_tests="$all_files"
266 while [ $a -le $num ]; do
267 if echo " $inp " | grep " $a " > /dev/null; then
268 do_tests="$do_tests $1"
269 if [ "x$test_nums" = "x" ] ; then
270 # actually broken. sets only the first num correctly.
280 #echo Starting: Running tests $do_tests
286 if [ "x$test_nums" = "xall" -o "x$test_nums" = "x" ] ; then
291 for testfile in $do_tests; do
293 if [ "x$interactive" = "xyes" ]; then
295 if [ $SH_DEBUG = 1 ] ; then
296 sh -x eval_onescript.sh $testfile $num "yes"
298 eval_onescript.sh $testfile $num "yes"
301 ECHO " Run test #$num (y/n) [y]? "
303 if [ "x$inp" = "xn" ]; then
308 if [ "x$dothisone" = "xyes" ]; then
309 if [ $SH_DEBUG = 1 ] ; then
310 sh -x eval_onescript.sh $testfile $num "no"
312 eval_onescript.sh $testfile $num "no"
315 success_count=`expr $success_count + 1`
317 failed_count=`expr $failed_count + 1`
323 echo Summary: $success_count / `expr $failed_count + $success_count` succeeded.