and added files
[bcm963xx.git] / userapps / opensource / net-snmp / testing / eval_suite.sh
1 #!/bin/sh
2 #
3 # eval_suite.sh [-h][<args_passed_to_getresults>]
4 #
5 # CALLS: eval_oneprogram.sh [-h][-lk] <program>
6 #
7 # RETURNS:      Number of failed tests, regardless of how that failure occured
8 #               or how many failures there were in a given test.
9 #
10 #
11
12
13                                                                 USAGE_LONG='
14 #
15 # HOW TO ENTER A NEW TEST
16 #
17 # To add a test to the testlist, add a line to the TESTLISTFILE (eval_testlist)
18 # using the following format:
19 #
20 #       <#_of_expected_successes> [#]<program> <args>
21 #
22 # Any white space may be used as separator.  If <program> is immediately
23 # preceeded by a pound sign (#) that test will be skipped.  (No white space
24 # allowed after the pound.  Eg, "#<program>".)
25 #
26 #
27 # HOW TESTS ARE RUN AND EVALUATED
28 #
29 # The harness for individual tests is the script "eval_oneprogram.sh".
30 # It expects that the test print FAILED when something fails, and SUCCESS
31 # when something succeeds.  If a test executes properly there should be
32 # some SUCCESS strings and NO FAILED strings.  If the reason for the
33 # success or failure of the test should be printed on the SAME line as the
34 # SUCCESS/FAILED string to allow the dianostic to be easilly grepped from
35 # the its output.
36 #
37 # The long form of the output (-l flag) will capture that output which may
38 # help to diagnosis the problem.  For more information:
39 #
40 #       % eval_oneprogram.sh -h
41 #
42
43 # MISSING TESTS ARE NOTED
44 #
45 # If an executable is found MISSING, a note is printed to that effect
46 # and TESTFAILURE is incremented by 1.
47 #
48 '
49
50 #
51 # Suggested improvement(s):
52 #       Have two (or more?) arbitrary script(s) that may be associated
53 #       with a given test.  One could prepare the environment, the other
54 #       could clean up the environment after running the test.  This could
55 #       help when testing large subsystems that might require legitimately
56 #       building or changing things such that the testable item may be 
57 #       accessed in the first place (eg). ...
58 #
59
60
61 #------------------------------------ -o- 
62 # Usage mess.  (No, it works.)
63 #
64 USAGE="Usage: `basename $0` [-h][<args_for_getresults>]"
65
66 usage() { echo; echo $USAGE; cat <<BLIK | sed 's/^#//' | sed '1d' | $PAGER
67 $USAGE_LONG
68 BLIK
69 exit 0
70 }
71
72 [ "x$1" = "x-h" ] && usage
73
74
75
76 #------------------------------------ -o- 
77 # Globals.
78 #
79 PROGRAM=
80 ARGUMENTS="$*"
81
82 TMPFILE=/tmp/eval_suite.sh$$
83
84 TESTLISTFILE=eval_testlist
85
86 EXPECTEDSUCCESSES=
87 TESTFAILURE=0
88
89 testname=
90
91 success_count=
92 failed_count=
93
94 #
95 # TESTLISTFILE format:
96 #       <expected_successes>    <program> <arg(s)> ...
97 #       <expected_successes>    <program> <arg(s)> ...
98 #       ...
99 #
100 TESTLIST="`cat $TESTLISTFILE | sed 's/$/   ===/'`"
101
102
103
104
105
106 #------------------------------------ -o- 
107 # Run all tests in the testlist.  For each test do the following:
108 #
109 #       1) Note whether the test is SKIPPED or MISSING.
110 #
111 #       2) Run the test; collect the number of FAILED strings from the
112 #               return value of eval_oneprogram.sh.
113 #
114 #       3) Count the number of SUCCESSes from the test output.
115 #
116 #       4) Print the results.  If there were no FAILED strings *and* the
117 #               number of SUCCESS strings is what we expect, simply
118 #               note that the test passed.  Otherwise, cat the output
119 #               generated by eval_oneprogram.sh and (possibly)
120 #               print other details.
121 #
122 set x $TESTLIST
123 shift
124
125 while [ -n "$1" ] ; do
126         #
127         # Parse agument stream...
128         #
129         EXPECTEDSUCCESSES=$1
130         shift
131
132         PROGRAM=
133         while [ "$1" != "===" ] ; do { PROGRAM="$PROGRAM $1" ; shift ; } done
134         shift
135
136         testname="`echo $PROGRAM | grep '^#' | sed 's/^#//'`"
137
138         echo '+==================================-o-===+'
139         echo
140
141
142
143         #
144         # Decide whether to skip the test, if it's mising, else run it.
145         #
146         [ -n "$testname" ] && {                                 # Skip the test?
147                 echo "SKIPPING test for \"$testname\"."
148                 echo
149                 continue
150         }
151         [ ! -e "`echo $PROGRAM | awk '{ print $1 }'`" ] && {    # Missing test?
152                 TESTFAILURE=`expr $TESTFAILURE + 1`
153
154                 echo "MISSING test for \"$PROGRAM\"."
155                 echo
156                 continue
157         }
158
159         echo "TESTING \"$PROGRAM\"..."                          # Announce test!
160
161
162
163         #
164         # Run the test and collect the failed_count and success_count.
165         #
166         eval_oneprogram.sh $ARGUMENTS $PROGRAM >$TMPFILE
167         failed_count=$?
168
169         success_count=`awk '$(NF-1) == "SUCCESS:" { print $NF; exit }' $TMPFILE`
170         [ -z "$success_count" ] && success_count=0
171
172
173         
174         #
175         # Output best-effort results of the test  -OR-  a fully successful run.
176         #
177         [ "$failed_count" -eq 0 -a \
178                         "$success_count" -eq "$EXPECTEDSUCCESSES" ] &&
179         {
180                 echo
181                 echo $PROGRAM PASSED            # Successful, fully, completed
182                 echo
183                 
184                 true
185         } || {
186                 TESTFAILURE=`expr $TESTFAILURE + 1`
187
188                 echo
189                 cat $TMPFILE
190                 echo
191
192                 [ "$success_count" -ne $EXPECTEDSUCCESSES ] && {
193                         echo "Got $success_count SUCCESSes"\
194                                                 "out of $EXPECTEDSUCCESSES."
195                         echo
196                 }
197                 true
198         }  # end -- evaluation of and output based upon test success.
199 done  # endwhile
200
201
202
203
204 #------------------------------------ -o- 
205 # Cleanup, exit.
206 #
207 rm -f $TMPFILE
208
209 exit $TESTFAILURE
210
211
212