summaryrefslogtreecommitdiff
path: root/cleopatre/application/spidnetsnmp/testing/eval_oneprogram.sh
blob: 45edfc0a673d8b8aaf530ce9fd1cef3e0383b60d (plain)
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
#!/bin/sh
#
# eval_oneprogram.sh [-h][-lk] <program> [<program_args>]
#
# CALLED BY: eval_suite.sh
#
#
# Runs <program> and reports how many instances of the strings SUCCESS
# or FAILED occur.
#
#
# FIX	Output from $PROGRAM on stderr is separated out and comes first.
#
#
USAGE_LONG='
#
# -h	Help.
# -k	Save the program output in "__<program_args>__<pid>o".
# -l	Long form.  (Short form by default.)
#
# <program> is the executable to run and collect the output of.
'

USAGE="Usage: `basename $0` [-h][-lk] <program>"




#------------------------------------ -o- 
# Globals.
#
AWKFILE="_`basename $0`$$.awk"
SCRIPTFILE=

dolongform=0
dokeepoutput=

TOTALFAILED=0



#------------------------------------ -o- 
# Parse & setup.
#
while [ -n "$1" ]; do
	case "$1" in
	-k)	dokeepoutput=true
		;;
	-l)	dolongform=1
		;;
	-h)	echo $USAGE
		cat <<BLIK | sed 's/^#//' | sed '1d'    1>&2
$USAGE_LONG
BLIK
		exit 0
		;;
	*)	PROGRAM="$*"
		shift `expr $# - 1`
		;;
	esac

	shift
done

[ -z "$PROGRAM" ] && echo $USAGE && exit 1


SCRIPTFILE="__`echo \`basename $PROGRAM\` | sed 's/ /_/g'`__$$o"



#------------------------------------ -o- 
# Create awk script.
#

cat <<GRONK >$AWKFILE

BEGIN {
	pass = 0
	passlist[0] = ""

	fail = 0
	faillist[0] = ""

	longform = $dolongform + 0
}

/SUCCESS/	{
	passlist[pass] = \$0
	pass += 1
}

/FAILED/	{
	faillist[fail] = \$0
	fail += 1
}

END {
	printf "$PROGRAM SUCCESS: %d\n", pass
	printf "$PROGRAM FAILED: %d\n", fail

	if (longform) {
		printf "\n"
		for (i=0; i<pass; i++)
			print passlist[i]

		for (i=0; i<fail; i++)
			print faillist[i]
	}

	exit fail
}
GRONK




#------------------------------------ -o- 
# Get and print results.
#

{ $PROGRAM $* 2>&1 ; } >$SCRIPTFILE

awk -f $AWKFILE $SCRIPTFILE
TOTALFAILED=$?

rm -f $AWKFILE
[ -z "$dokeepoutput" ] && rm -f $SCRIPTFILE




#------------------------------------ -o- 
# Exit, cleanup.
#
exit $TOTALFAILED