#!/bin/sh
# ---------------------------------------------------------------------------
# JOnAS: Java(TM) Open Application Server
# Copyright (C) 1999 Bull S.A.
# Contact: jonas-team@objectweb.org
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA
#
# ---------------------------------------------------------------------------
# $Id$ 
# ---------------------------------------------------------------------------

#
# Usage:	junitime.sh  dir-name  suite-name  perfs 
#
# This script allows to run  a sub-set of the conformance tests resumed in a perfs method:
#
# for the moment only some final suites(F_) are updated in session and entity directory
#
# call: junitime.sh session F_ClientViewNoTxSL perfs
#
# it logs the results in a file LOGPATH/SUITE_$$
#
# use of awk to format output
# 
# awkcat concatenes on the same line the informations of one test and removes all dots and Failures

awkcat()
{
awk '/^Running.*/ {
		n=split($0,a,"\t") # to get the name
		s = a[1]
		}

/^Time:/	{s= s"|"$0}

/^OK/{	s= s"|"$0;printf("%s\n",s); s=""}
	
/^FAILURES/{printf("%s|FAILURES\n",a[1]); s=""}

/^--/{print $0}

{next}
'
}
# to get unit times per function and keep them
awkunit()
{
awk '
BEGIN 	{printf ("function \t\t\t\t iterations \t unit time \n")
		printf ("------------------------------------------------------------\n")
		}
/^--.*/{ print $0;next}
	{
	k=split($0,a,"|")
	n=split (a[1],b," ")#a[1]= running names
	nom=b[n]#b[n]=function name
	nomclass=b[n-1]#b[n-1]= class name
	n=split(a[2],c," ")#time part
	temps=c[n]#time value
	split(a[3],d,"(")#OK (nb tests)
	split(d[2],e," ")
	nb=e[1]
	if ( a[k]=="FAILURES") {temps =" NOK"}	else	{temps=temps/nb}
	printf ("%s %s	%s	%s\n",nomclass,nom,nb,temps)
	}
'
}

TYPE=conf
PACK=org.objectweb.jonas.jtests.clients
DIR=suite
SUITE=P_suite
TEST=
CLASS=

# You must put here the directory where the jonas tests are
# TEST_BASE=$PROJ_BASE/jonas_tests
TEST_BASE=$PROJ_BASE/tests

TEST_CLASSES=$TEST_BASE/conformance/classes
LOGPATH=$TEST_BASE/conformance/log
PROPS=


if [ $# -gt 0 ]
then
	DIR=$1
	SUITE=P_$DIR
	shift
fi

if [ $# -gt 0 ]
then
	SUITE=$1
	TEST="-n perfs"
	shift
fi


# update classpath for junit tests
# update the following lines depending on your own environment
for CLS in \
$ANT_HOME/lib/junit.jar \
$TEST_CLASSES
do
    echo $CLASSPATH | grep $CLS >/dev/null || CLASSPATH=$CLASSPATH:$CLS
done

# important to be seen in jclient script
export CLASSPATH


echo "Running junit tests for time : $TYPE $DIR/$SUITE $TEST"


#jclient $PROPS $PACK.$DIR.$SUITE $TEST

jclient $PROPS $PACK.$DIR.$SUITE $TEST|awkcat|awkunit|tee $LOGPATH/${SUITE}_$$ 


