#!/bin/sh

#  Copyright(C) 1996, 1997 Network Flight Recorder, Inc.
#  All rights reserved.
#
#  Use and distribution of this software and its source code
#  are governed by the terms and conditions of the
#  Network Flight Recorder Software License ("LICENSE.TXT")

#
# There are three groups of tests.
# x*.sh tests. -- The first tests are intended to test some of the syntax
#	and semantics of the parser.  
# y*.sh tests.  The second set of tests perform operations which require
#	sniffed input to exercise features in protocol stacks, and other
#	components of the engine.  A test versio of the engine is run.
# z*.sh tests.  These tests require a recorder running connected to the
#	engine.  They may or may not require sniffed input to complete
#	the test.


good=0
bad=0


#
# iterate across all the X tests....
#

if [ "`echo x*.nfr`" != 'x*.nfr' ] ; then
    for i in x*.nfr ; do
	echo "`date '+[%D %T]'` regress: $i: `head -1 $i | sed "s/#//" ` "
	result=`../test-nfrd $i`
	code=$?
	if [ $code -gt 0 ] ; then
	    bad=`expr $bad + 1 `
	    echo "`date '+[%D %T]'` regress: $i failure: Code $code result: $result"
	else
	    if [ "$result" = "success" ] ; then
		echo "`date '+[%D %T]'` regress: $i success: Code $code result: $result"
		good=`expr $good + 1`
	    else 
		echo "`date '+[%D %T]'` regress: $i failure: Code $code result: $result"
		bad=`expr $bad + 1 `
	    fi
	fi
    done
fi

#
# iterate across all the Y tests....
#

if [ "`echo y*.sh`" != 'y*.sh' ] ; then
    for i in y*.sh ; do
	echo "`date '+[%D %T]' ` regress: $i: `head -1 $i | sed "s/#//" ` "
	sh ./$i > ./$i.log
	code=$?
	echo "`date '+[%D %T]'` regress: $i: Code $code"
	if [ $code -gt 0 ] ; then
	    echo "`date '+[%D %T]'` regress: $i failure: Code $code"
	    bad=`expr $bad + 1 `
	else
	    echo "`date '+[%D %T]'` regress: $i success: Code $code"
	    good=`expr $good + 1`
	fi
    done
fi


#
# iterate across all the Z tests....
#

if [ "`echo z*.sh`" != 'z*.nfr' ] ; then
    for i in z*.sh ; do
	echo "`date '+[%D %T]' ` regress: $i: `head -1 $i | sed "s/#//" ` "
	sh ./$i > ./$i.log
	code=$?
	echo "`date '+[%D %T]'` regress: $i: Code $code"
	if [ $code -gt 0 ] ; then
	    echo "`date '+[%D %T]'` regress: $i failure: Code $code"
	    bad=`expr $bad + 1 `
	else
	    echo "`date '+[%D %T]'` regress: $i success: Code $code"
	    good=`expr $good + 1`
	fi
    done
fi


echo "`date '+[%D %T]'` regress: good: $good bad: $bad total: `expr $good + $bad `"
