xref: /illumos-gate/usr/src/contrib/ast/src/cmd/INIT/rt.sh (revision b30d1939)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1994-2011 AT&T Intellectual Property          #
5#                      and is licensed under the                       #
6#                 Eclipse Public License, Version 1.0                  #
7#                    by AT&T Intellectual Property                     #
8#                                                                      #
9#                A copy of the License is available at                 #
10#          http://www.eclipse.org/org/documents/epl-v10.html           #
11#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                 Glenn Fowler <gsf@research.att.com>                  #
18#                                                                      #
19########################################################################
20: rt - nmake test output filter
21
22command=rt
23flags='--silent --keepgoing'
24failed=0
25heading=1
26verbose=0
27
28case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
290123)	ARGV0="-a $command"
30	USAGE=$'
31[-?
32@(#)$Id: rt (AT&T Research) 2010-07-27 $
33]
34'$USAGE_LICENSE$'
35[+NAME?rt - run "nmake test" and filter output]
36[+DESCRIPTION?\brt\b runs \vnmake test\v and filters the regression
37	test output to contain only test summary lines. If no \atest\a
38	operands are specified then \btest\b is assumed. If \b-\b is
39	specified then the \afile\a operands, or the standard input
40	if no \afile\a operands are specified, are filtered instead
41	of the output from \bnmake\b.]
42[f:failed?Only list failed test results.]
43[h!:heading?Enable per-file heading when more than one \afile\a operand
44	follows \b-\b.]
45[v:verbose?Run with \vREGRESSFLAGS=-v\v.]
46
47[ test ... | - [ file ... ] ]
48
49[+SEE ALSO?\bnmake\b(1), \bregress\b(1)]
50[+CAVEATS?\brt\b guesses the regression test output style. Garbled
51	output indicates a bad guess.]
52'
53	;;
54*)	ARGV0=""
55	USAGE="fhv"
56	;;
57esac
58
59function usage
60{
61	OPTIND=0
62	getopts $ARGV0 "$USAGE" OPT '-?'
63	exit 2
64}
65
66while	getopts $ARGV0 "$USAGE" OPT
67do	case $OPT in
68	f)	failed=1 ;;
69	h)	heading=0 ;;
70	v)	(( verbose=$OPTARG )) && flags="$flags REGRESSFLAGS=-v" ;;
71	esac
72done
73shift `expr $OPTIND - 1`
74
75ifs=${IFS:-$' \t\n'}
76set -o noglob
77component=
78dots='............................................'
79bad=' ***'
80style=unknown
81integer tests errors signals lineno=0 skip=0
82typeset -l lower
83
84function results # tests errors signals
85{
86	integer t=$1 e=$2 s=$3
87	typeset label note
88	if	[[ $style != unknown ]] && (( errors >= 0 ))
89	then	style=unknown
90		if	(( !failed || errors ))
91		then	if	(( failed ))
92			then	print -r -n -- "$unit"
93			fi
94			if	(( t >= 0 ))
95			then	if	(( t == 1))
96				then	label="test "
97				else	label=tests
98				fi
99				printf $'%s%5d %s' "$prefix" "$t" "$label"
100				prefix=
101			else	prefix="$prefix..........."
102			fi
103			if	(( s ))
104			then	label=signal
105				(( e=s ))
106			else	label=error
107			fi
108			if	(( e != 1))
109			then	label=${label}s
110			fi
111			if	(( e == 1 ))
112			then	note=" $bad"
113			elif	(( e > 1 ))
114			then	note=$bad
115			fi
116			printf $'%s%5d %s%s\n' "$prefix" "$e" "$label" "$note"
117		fi
118	fi
119}
120
121function unit
122{
123	typeset x
124	if	[[ $component ]]
125	then	x=${component##*/}
126		if	[[ " $x " != *' '$unit' '* && " $unit " != *' '$x' '* ]]
127		then	if	[[ $component == cmd/?*lib/* ]]
128			then	unit="$unit $x"
129			else	unit="$x $unit"
130			fi
131		fi
132	fi
133	unit="$unit ${dots:1:${#dots}-${#unit}}"
134	if	[[ $1 ]]
135	then	unit="$unit..........."
136	fi
137	if	(( ! failed ))
138	then	print -r -n -- "$unit"
139	fi
140}
141
142if	[[ $1 == - ]]
143then	shift
144	if	(( $# <= 1 ))
145	then	heading=0
146	fi
147	if	(( heading ))
148	then	for i
149		do	print test heading $i
150			cat -- "$i"
151		done
152	else	cat "$@"
153	fi
154else	if	[[ $1 == *=* ]]
155	then	set test "$@"
156	elif	(( ! $# ))
157	then	set test
158	fi
159	nmake "$@" $flags 2>&1
160fi |
161while	read -r line
162do	set '' $line
163	shift
164	case $line in
165	TEST[' 	']*', '*' error'*)
166		IFS=${IFS}","
167		set '' $line
168		IFS=$ifs
169		set '' $*
170		while	:
171		do	case $2 in
172			'')	break
173				;;
174			error|errors)
175				errors=$1
176				break
177				;;
178			test|tests)
179				tests=$1
180				;;
181			esac
182			shift
183		done
184		results $tests $errors
185		continue
186		;;
187	TEST[' 	']*)
188		results $tests $errors
189		IFS=${IFS}","
190		set '' $line
191		IFS=$ifs
192		set '' $*
193		unit=${3##*/}
194		case $4 in
195		[a-zA-Z]*)	unit="$unit $4" ;;
196		esac
197		unit
198		prefix=
199		errors=0
200		signals=0
201		style=regress
202		continue
203		;;
204	'pathname and options of item under test')
205		read -r line || break
206		results $tests $errors $signals
207		set '' $line
208		unit=${2##*/}
209		unit
210		tests=0
211		errors=0
212		signals=0
213		style=script
214		continue
215		;;
216	'test heading '*)
217		if	(( heading ))
218		then	if	(( heading > 1 ))
219			then	print
220			else	heading=2
221			fi
222			set '' $line
223			shift 3
224			print -r -- "==> $* <=="
225		fi
226		continue
227		;;
228	'test '*' begins at '????-??-??+??:??:??|'test '*' begins at '*' '*' '*' '*' '*)
229		results $tests $errors $signals
230		unit=${2##*/}
231		unit=${unit%.sh}
232		unit
233		prefix=
234		tests=-1
235		errors=0
236		signals=0
237		style=shell
238		continue
239		;;
240	'test '*' at '????-??-??+??:??:??' [ '*' ]'|'test '*' at '*' '*' '*' '*' '*)
241		case $line in
242		*' [ '*test*error*' ]')
243			while	:
244			do	case $1 in
245				'[')	tests=$2
246					errors=$4
247					if	(( errors > 256 ))
248					then	(( signals++ ))
249					fi
250					break
251					;;
252				esac
253				shift
254			done
255			;;
256		*' [ '*test*signal*' ]')
257			while	:
258			do	case $1 in
259				'[')	tests=$2
260					signals=$4
261					if	(( signals ))
262					then	(( errors++ ))
263					fi
264					break
265					;;
266				esac
267				shift
268			done
269			;;
270		*)	if	[[ $3 != passed ]]
271			then	(( errors )) || (( errors++ ))
272			fi
273			;;
274		esac
275		results $tests $errors $signals
276		continue
277		;;
278	'## ---'*(-)'--- ##')
279		(( ++lineno > skip )) || continue
280		read -r line || break
281		lower=$line
282		set '' $lower
283		case $lower in
284		'##'*'test suite:'*'##')
285			results $tests $errors $signals
286			set -- ${lower//*suite:}
287			set -- ${*//[.#]/}
288			unit=$*
289			if	[[ $unit == *' tests' ]]
290			then	unit=${unit/' tests'/}
291			fi
292			main=$unit
293			prefix=
294			tests=0
295			errors=0
296			signals=0
297			category=
298			style=autotest
299			(( skip = lineno + 1 ))
300			unit
301			continue
302			;;
303		esac
304		;;
305	+(-))	case $style in
306		regress)	continue ;;
307		esac
308		(( ++lineno > skip )) || continue
309		read -r line || break
310		set '' $line
311		case $line in
312		'Running tests for '*)
313			results $tests $errors $signals
314			shift 4
315			unit=
316			while	(( $# ))
317			do	if	[[ $1 == on ]]
318				then	break
319				fi
320				if	[[ $unit ]]
321				then	unit="$unit "
322				fi
323				unit=$unit${1##*/}
324				shift
325			done
326			main=$unit
327			prefix=
328			tests=-1
329			errors=-1
330			category=
331			style=perl
332			(( skip = lineno + 1 ))
333			continue
334			;;
335		*' : '*)results $tests $errors $signals
336			unit=${2##*/}
337			unit=${unit%.sh}
338			unit
339			prefix=
340			tests=0
341			errors=0
342			signals=0
343			style=timing
344			(( skip = lineno + 1 ))
345			continue
346			;;
347		esac
348		;;
349	+([0-9])*([a-zA-Z0-9])' '*)
350		case $style in
351		script)	case $line in
352			*FAILED*|*failed*)
353				(( errors++ ))
354				;;
355			*)	(( tests++ ))
356				;;
357			esac
358			;;
359		esac
360		;;
361	make:*|'make ['*']:'*)
362		case $line in
363		*': warning:'*|*'making test'*|*'action'?(s)' failed'*|*': *** '*)
364			;;
365		*)	results $tests $errors $signals
366			print -r -u2 -- "$line"
367			;;
368		esac
369		continue
370		;;
371	+([/a-zA-Z_0-9]):)
372		component=${line%:}
373		;;
374	'')	continue
375		;;
376	esac
377	case $style in
378	autotest)
379		case $line in
380		+([0-9]):*ok)
381			(( tests++ ))
382			;;
383		+([0-9]):*FAILED*)
384			(( tests++ ))
385			(( errors++ ))
386			if	(( $verbose ))
387			then	if	[[ ! $prefix ]]
388				then	prefix=$unit
389					print
390				fi
391				print -r -- "	${line//*'FAILED '/}"
392			fi
393			;;
394		esac
395		continue
396		;;
397	perl)	case $line in
398		*'........ '*)
399			if	[[ $1 == */* ]]
400			then	cat=${1%%/*}
401				if	[[ $cat != $category ]]
402				then	results $tests $errors $signals
403					category=$cat
404					unit="$main $category"
405					unit
406					prefix=
407					tests=0
408					errors=0
409					signals=0
410				fi
411				(( tests++ ))
412				case $line in
413				*' ok')	;;
414				*)	(( errors++ ))
415					if	(( $verbose ))
416					then	if	[[ ! $prefix ]]
417						then	prefix=$unit
418							print
419						fi
420						print -r -- "$line"
421					fi
422					;;
423				esac
424			else	results $tests $errors $signals
425				case $line in
426				*' ok')	errors=0 ;;
427				*)	errors=1 ;;
428				esac
429				unit="$main $1"
430				unit
431				if	(( $verbose && errors ))
432				then	prefix=$unit
433					print
434					shift 2
435					print -r -- "$@"
436				else	prefix=
437				fi
438				results $tests $errors $signals
439				tests=-1
440				errors=-1
441				category=
442			fi
443			style=perl
444			;;
445		esac
446		continue
447		;;
448	esac
449	case $line in
450	*FAILED*|*failed*)
451		(( errors++ ))
452		;;
453	*)	case $style in
454		regress)case $line in
455			['<>']*);;
456			*)	continue ;;
457			esac
458			;;
459		script)	continue
460			;;
461		shell)	((errors++ ))
462			;;
463		timing)	(( tests++ ))
464			continue
465			;;
466		unknown)continue
467			;;
468		esac
469		;;
470	esac
471	if	(( $verbose ))
472	then	if	[[ ! $prefix ]]
473		then	prefix=$unit
474			print
475		fi
476		print -r -- "$line"
477	fi
478done
479results $tests $errors $signals
480