#!/bin/sh
#
#       @(#)runtests.wrk	1.9 2003/12/30 Connectathon Testsuite
#	1.4 Lachman ONC Test Suite source
#
#  This script is intended to be invoked from 'runtests'
#  Don't run it manually

case x$1 in
    xFROM_RUNTESTS)
	;;
    *)
	echo "$0 must be run from 'runtests' - Don't run manually"
	exit 1
	;;
esac

errexit='cat $FILE; exit 1'

TIME=/usr/local/bin/time-tmp.sh
# if the default time command doesn't return the right format,
# you may have to use the following lines
#case `uname` in
#[lL]inux*)
#	TIME=/usr/bin/time
#	;;
#*)
#	TIME=/bin/time
#	;;
#esac
#if [ ! -f $TIME ]
#then
#	TIME=/usr/bin/time
#	if [ ! -f $TIME ]
#	then
#		echo "Where is the time command?"
#		exit 1
#	fi
#fi

chmod 777 large4.sh mkdummy rmdummy
umask 0

# Newer compilers tend to produce warning messages for the source code
# that is used for the general tests.  This confuses "stat".  There
# are a couple ways we could fix this (e.g., make "stat" ignore
# compiler warnings).  But since the general tests as a whole probably
# should be replaced by something that is less Unix-centric, we'll
# just hack around the problem by supressing compiler warnings.
CFLAGS="$CFLAGS -w"
export CFLAGS

echo ""
echo "Small Compile"
rm -f smcomp.time
FILE=smcomp.time
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
set -e
stat smcomp.time
set +e

echo ""
echo "Tbl"
rm -f tbl.time
$TIME tbl nroff.in > nroff.tbl 2>> tbl.time || cat tbl.time
$TIME tbl nroff.in > nroff.tbl 2>> tbl.time || cat tbl.time
$TIME tbl nroff.in > nroff.tbl 2>> tbl.time || cat tbl.time
$TIME tbl nroff.in > nroff.tbl 2>> tbl.time || cat tbl.time
$TIME tbl nroff.in > nroff.tbl 2>> tbl.time || cat tbl.time
set -e
# Filter excessive noise from GNU tbl.  Should be harmless for other
# versions of tbl.
stat tbl.time
set +e

echo ""
echo "Nroff"
rm -f nroff.time
$TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
$TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
$TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
$TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
$TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
rm nroff.out nroff.tbl
set -e
stat nroff.time
set +e

echo ""
echo "Large Compile"
rm -f lrgcomp.time
FILE=lrgcomp.time
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
rm large
set -e
stat lrgcomp.time
set +e

echo ""
echo "Four simultaneous large compiles"
rm -f 4lrg.time
FILE=4lrg.time
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
set -e
stat 4lrg.time
set +e

echo ""
echo "Makefile"
mkdummy
rm -f makefile.time
FILE=makefile.time
$TIME make -e -f makefile.tst > /dev/null 2>> makefile.time || eval $errexit
$TIME make -e -f makefile.tst > /dev/null 2>> makefile.time || eval $errexit
$TIME make -e -f makefile.tst > /dev/null 2>> makefile.time || eval $errexit
$TIME make -e -f makefile.tst > /dev/null 2>> makefile.time || eval $errexit
$TIME make -e -f makefile.tst > /dev/null 2>> makefile.time || eval $errexit
rmdummy
# Remove warnings (e.g., due to clock skew) that might confuse "stat".
grep -iv warning: makefile.time | grep -v 'make: ' > makefile.time2
mv makefile.time2 makefile.time
set -e
stat makefile.time
set +e

echo ""
echo "General tests complete"

exit 0
