#!/bin/sh
# Copyright 1999-2002 Carnegie Mellon University.  
# Portions Copyright 2002 Sun Microsystems, Inc.  
# Portions Copyright 2002 Mitsubishi ElectricResearch Laboratories.
# All Rights Reserved.  Use is subject to license terms.
# 
# See the file "license.terms" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL 
# WARRANTIES.
#
# This script archives files generated during the regression tests, so
# that failed tests can be more easily verified.
#
# This script should be run from the regression test directory
#
# usage: archiveTestResults [testType]
#
# Only the first argument is considered, the remaining are ignored.
#
# where testType is either:
#
# 	standard
#	quick
#  	an4
#       an4_full
#       an4_plus
#       an4_spelling
#       an4_words
#       rm1
#       ti46
#       tidigits
#
# more tests can be added by adding a script called runTests_XXX to
# the regression test directory, where XXX is the name of the new test.
#


regressionDir=`pwd`

errorLog=$1
testType=${2:-standard}

echo archiveTestResults $testType

testDir=../

#############################
# Define file names
#############################

cd $regressionDir
machine=`./getHostname`
archiveDir=/lab/speech/sphinx4/regressionArchive/
archiveBasename=${testType}.${machine}.zip
archiveFile=${archiveDir}/${archiveBasename}

###########################
# Then we build the archive
###########################
cd $testDir

if [ ! -d $archiveDir ]; then
   mkdir $archiveDir
fi
/bin/rm -f $archiveBasename
find . -name '*.out' -mtime -7 -print | zip $archiveBasename -@
find . -name 'hs*.log' -print | zip $archiveBasename -@
find . -name 'gc.txt' -print | zip $archiveBasename -@

srsync  htdocs/sphinx4/regressionArchive/ $archiveBasename
mv -f $archiveBasename $archiveFile

####################
# Create error log
####################
echo "Log files archived in $archiveBasename at http://cmusphinx.sourceforge.net/sphinx4/regressionArchive" > $errorLog
echo "" >> $errorLog
echo "Errors found:" >> $errorLog
echo "" >> $errorLog
find . -name '*.out' -mtime -7 -print | xargs egrep '(error|Exception)' | egrep -v "(REF:|HYP:)" >> $errorLog
find . -name 'hs*.log' -print | xargs egrep '(error|Exception)' >> $errorLog
find . -name 'gc.txt' -print | xargs egrep '(error|Exception)' >> $errorLog
