#!/bin/sh
#
# This script runs the nightly bootstrap tests.
# It is invoked directly from cron, so it runs
# without a proper environment (PATH, etc.) set up.
#
# NB. Although this file is under CVS control,
# the copy that is used by cron does not get
# automatically updated from the CVS repository.
# After any modifications, the master copy
# in /home/mercury/public/test_mercury/scripts
# should be updated manually.

#-----------------------------------------------------------------------------#

tm_dir=/home/mercury/public/test_mercury

#-----------------------------------------------------------------------------#

ulimit -c 0

case $# in
	1)	HOST=$1 ;;
	*)	echo "Usage: $0 host" 1>&2; exit 1 ;;
esac

case $HOST in
	munta) 		ARCH=sgi	FULLARCH=mips-sgi-irix5.3 ;;
	muse) 		ARCH=sgi	FULLARCH=mips-sgi-irix5.3 ;;
	kryten) 	ARCH=sparc	FULLARCH=sparc-sun-solaris2.5 ;;
	murlibobo) 	ARCH=alpha	FULLARCH=alpha-dec-osf3.2 ;;
	mundook) 	ARCH=alpha	FULLARCH=alpha-dec-osf3.2 ;;
	mercury) 	ARCH=i586	FULLARCH=i586-unknown-linux ;;
	*)		echo "$0: unknown HOST $HOST" 1>&2; exit 1 ;;
esac

case $HOST in
	kryten) 	mail="rsh munta /bin/mail" ;;
	*)		mail=/bin/mail ;;
esac

#-----------------------------------------------------------------------------#

PATH="$HOME/bin/$ARCH`awk '/^[^#]/{printf ":%s",$0;}' /home/pgrad/fjh/.path`"
PATH="/home/mercury/public/mercury-0.5/$FULLARCH/bin:$PATH"
PATH="/home/mercury/public/mercury-0.6/$FULLARCH/bin:$PATH"
PATH="/home/mercury/public/mercury-latest/$FULLARCH/bin:$PATH"
PATH="/home/mercury/public/nuprolog/$FULLARCH/bin:$PATH"
PATH="/home/mercury/public/gcc-2.7.2/$FULLARCH/bin:$PATH"
PATH="/home/mercury/public/autoconf-2.4/$FULLARCH/bin:$PATH"
PATH="/home/mercury/public/$HOST:$PATH"
export PATH

CVSROOT=/home/staff/zs/imp
export CVSROOT

cd /home/mercury/public/test_mercury/scripts;
cvs checkout mercury/tools/test_mercury
cp mercury/tools/test_mercury /tmp/test_mercury$$

#-----------------------------------------------------------------------------#

echo run_test $HOST

mv -f $tm_dir/logs/test_mercury_$HOST.out $tm_dir/logs/old 2>/dev/null

tmpfile=/tmp/run_test$$
trap 'rm -f $tmpfile; exit 1' 1 2 3 13 15
{
echo Subject: Mercury auto-test on $HOST
echo
logfile=$tm_dir/logs/test_mercury_$HOST.out

if /bin/nice -5 sh /tmp/test_mercury$$ $HOST $ARCH $FULLARCH \
		> $logfile 2>&1
then
	echo test passed
	echo
	echo last 10 lines of log file:
	tail -10 $logfile
	echo
	cd /home/mercury/public/mercury-latest/$FULLARCH/lib/mercury/bin/$FULLARCH
	ls -l mercury_compile
	size mercury_compile
	{
		echo $FULLARCH
		ls -l mercury_compile
		size mercury_compile
		echo
	} >> $tm_dir/logs/sizes
else
	echo test FAILED
	echo log file in $tm_dir/logs/test_mercury_$HOST.out
	echo
	echo last 10 lines of log file:
	tail -10 $logfile
fi
} > $tmpfile 2>&1
# NB we can't just pipe into $mail, because $mail times out while
# waiting for the message.  So we need to use a temp file.
$mail fjh,conway < $tmpfile
rm -f $tmpfile

#-----------------------------------------------------------------------------#
