Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / testing / eval_oneprogram.sh
1 #!/bin/sh
2 #
3 # eval_oneprogram.sh [-h][-lk] <program> [<program_args>]
4 #
5 # CALLED BY: eval_suite.sh
6 #
7 #
8 # Runs <program> and reports how many instances of the strings SUCCESS
9 # or FAILED occur.
10 #
11 #
12 # FIX   Output from $PROGRAM on stderr is separated out and comes first.
13 #
14 #
15 USAGE_LONG='
16 #
17 # -h    Help.
18 # -k    Save the program output in "__<program_args>__<pid>o".
19 # -l    Long form.  (Short form by default.)
20 #
21 # <program> is the executable to run and collect the output of.
22 '
23
24 USAGE="Usage: `basename $0` [-h][-lk] <program>"
25
26
27
28
29 #------------------------------------ -o- 
30 # Globals.
31 #
32 AWKFILE="_`basename $0`$$.awk"
33 SCRIPTFILE=
34
35 dolongform=0
36 dokeepoutput=
37
38 TOTALFAILED=0
39
40
41
42 #------------------------------------ -o- 
43 # Parse & setup.
44 #
45 while [ -n "$1" ]; do
46         case "$1" in
47         -k)     dokeepoutput=true
48                 ;;
49         -l)     dolongform=1
50                 ;;
51         -h)     echo $USAGE
52                 cat <<BLIK | sed 's/^#//' | sed '1d'    1>&2
53 $USAGE_LONG
54 BLIK
55                 exit 0
56                 ;;
57         *)      PROGRAM="$*"
58                 shift `expr $# - 1`
59                 ;;
60         esac
61
62         shift
63 done
64
65 [ -z "$PROGRAM" ] && echo $USAGE && exit 1
66
67
68 SCRIPTFILE="__`echo \`basename $PROGRAM\` | sed 's/ /_/g'`__$$o"
69
70
71
72 #------------------------------------ -o- 
73 # Create awk script.
74 #
75
76 cat <<GRONK >$AWKFILE
77
78 BEGIN {
79         pass = 0
80         passlist[0] = ""
81
82         fail = 0
83         faillist[0] = ""
84
85         longform = $dolongform + 0
86 }
87
88 /SUCCESS/       {
89         passlist[pass] = \$0
90         pass += 1
91 }
92
93 /FAILED/        {
94         faillist[fail] = \$0
95         fail += 1
96 }
97
98 END {
99         printf "$PROGRAM SUCCESS: %d\n", pass
100         printf "$PROGRAM FAILED: %d\n", fail
101
102         if (longform) {
103                 printf "\n"
104                 for (i=0; i<pass; i++)
105                         print passlist[i]
106
107                 for (i=0; i<fail; i++)
108                         print faillist[i]
109         }
110
111         exit fail
112 }
113 GRONK
114
115
116
117
118 #------------------------------------ -o- 
119 # Get and print results.
120 #
121
122 { $PROGRAM $* 2>&1 ; } >$SCRIPTFILE
123
124 awk -f $AWKFILE $SCRIPTFILE
125 TOTALFAILED=$?
126
127 rm -f $AWKFILE
128 [ -z "$dokeepoutput" ] && rm -f $SCRIPTFILE
129
130
131
132
133 #------------------------------------ -o- 
134 # Exit, cleanup.
135 #
136 exit $TOTALFAILED
137
138