#!/bin/sh # # RUNTESTS [-h]... # # RETURNS: Number of failed tests. # # CALLS: eval_oneprogram.sh [-h][-lk] # # SOURCES: TESTCONF.sh # # USAGE_LONG=' # # HOW TO ENTER A NEW TEST # # Copy the template file (T2.sh) XXX to the tests directory, and have # the file begin with a 'T'. All files in the tests directory # begining with a 'T' are assumed to be a test. See the file for # further instructions # # HOW TESTS ARE RUN AND EVALUATED # # ... # ' # # Suggested improvement(s): # Run a given test against a running agent. # Display errors # interactively pick tests to run. # options arguments to pick tests to run. # # # Variables: (* = exported) # *SNMP_BASEDIR: the source base directory for tests # *SNMP_UPDIR: directory above where the test binaries live (-D option) # *SNMP_PATH ## yes, PATH is already setup # *SNMP_VERBOSE ## 0=silent, 1=warnings, 2=more # Usage mess. (No, it works.) # USAGE="Usage: `basename $0` [-h] [-i] [-v] [-V] [-s] [-T TESTNUMS] [-D bindir] [-S seconds]" usage() { echo; echo $USAGE; #cat < /dev/null 2>&1 if [ $? -ne 0 ] ; then WHICH=type fi for needed in snmpd snmpget snmpgetnext; do $WHICH $needed > /dev/null 2>&1 if [ $? -ne 0 ] ; then echo "No $needed found. Exiting" exit 1 fi done # # Distinguished expectations. # if [ $SNMP_VERBOSE -gt 0 ]; then echo ${SNMP_UPDIR}/testing echo path is $PATH echo top of build is $SNMP_UPDIR echo source testing is $SNMP_BASEDIR $WHICH snmpusm fi # # Source the testing configuration file # . TESTCONF.sh # Hack: the above created a directory, now we have to nuke it and # forget about it... All for the convenience of the test writer. rmdir $SNMP_TMPDIR unset SNMP_TMPDIR export SNMP_TMPDIR # # Switch to the testing directory, for ease of the client test packages. # cd ./tests #------------------------------------ -o- # Globals. # PROGRAM= ARGUMENTS="$*" TMPFILE=$SNMP_TMPDIR/eval_suite.sh$$ testname= success_count=0 failed_count=0 if [ "x$do_tests" = "x" ]; then # # List the tests in question # num=0 for testfile in T*; do case $testfile in # Skip backup files, and the like. *~) ;; *.bak) ;; *.orig) ;; *.rej) ;; # Do the rest *) num=`expr $num + 1` if [ "x$interactive" != "xyes" -a "x$test_nums" = "x" ]; then eval_onescript.sh $testfile $num "yes" fi all_tests="$all_tests $num" all_files="$all_files $testfile" ;; esac done # # TODO: allow user to interactively pick the list of tests to run. # if [ "x$interactive" != "xyes" ]; then if [ "x$test_nums" = "x" ]; then ECHO "Enter test numbers [all]: " read inp else if [ "x$test_nums" = "xall" ]; then inp="" else inp="$test_nums" fi fi if [ "x$inp" = "x" ]; then do_tests="$all_files" else a=1 set $all_files while [ $a -le $num ]; do if echo " $inp " | grep " $a " > /dev/null; then do_tests="$do_tests $1" if [ "x$test_nums" = "x" ] ; then # actually broken. sets only the first num correctly. test_nums=$a fi fi shift a=`expr $a + 1` done fi fi #echo Starting: Running tests $do_tests fi # # Run the tests # if [ "x$test_nums" = "xall" -o "x$test_nums" = "x" ] ; then num=1 else num="$test_nums" fi for testfile in $do_tests; do dothisone="yes"; if [ "x$interactive" = "xyes" ]; then if [ $SH_DEBUG = 1 ] ; then sh -x eval_onescript.sh $testfile $num "yes" else eval_onescript.sh $testfile $num "yes" fi ECHO " Run test #$num (y/n) [y]? " read inp if [ "x$inp" = "xn" ]; then dothisone=no fi fi if [ "x$dothisone" = "xyes" ]; then if [ $SH_DEBUG = 1 ] ; then sh -x eval_onescript.sh $testfile $num "no" else eval_onescript.sh $testfile $num "no" fi if [ $? = 0 ]; then success_count=`expr $success_count + 1` else failed_count=`expr $failed_count + 1` fi fi num=`expr $num + 1` done echo Summary: $success_count / `expr $failed_count + $success_count` succeeded. exit $failed_count