#!/bin/csh
#
# A regressions test for coral
#
# Set a few varibles
#
##
set coral = coral			# command to call coral
set rg = $cwd				# current working directory
set test = $rg/timesuite		# where testing files are 
set data = $rg/time_ans			# where benchmark files are.
set timings = $rg/timings               # where timings go
set timingstore = $rg/timing_store      # previous timings
set filter = "nawk -f $rg/strip.awk "	# filter out beginning and end messages
set argc = $#argv			# the number of args from command line

# if sysV sort is available, use it
set sort = sort                        # the sort routine to use
#
# if BSD sort is being used, some of the programs will produce output lines 
# that are too long for sort to handle.
#
#set sort = sort
#
# set up the single output files.
#
@ x = 0
foreach i ($argv)			# for each i in 
	@ x++
	switch($argv[$x])
	case "-h":
	case "-help":
		goto usage
		breaksw
	case "-s":
		if($argc == 1) goto usage
		@ y = $x + 1
		set sfiles = "$argv[${y}]"
		goto next
		breaksw
	default:
		echo Error in specifying command line options
		goto usage
		breaksw
	endsw
end

next:
#
# now, if sfiles has not been set, set it to the defaults
# NOTE: If you wish to add new files to be tested, add them to this list.
#
if($?sfiles == 0) then
set sfiles =   (ackermann algebra.opt algebra1 algebra2 anc1 anc2 anc3 anc4 \
		anc5 anc6 anc7 anc8 appendbig appendbigopt appendbigpipe avgs \
		bom1 bom2 bom3 cife even fac fib game grades join.gnd.bu \
		join.ng.bu join.gnd.pipe join.ng.pipe knap knap2 lcs mcp \
		model msort nldcg nodups nqueens nqueens.pipe nrev palin \
		parse peaks qsort run sg shortestpath tak volatility)
endif

onintr end 				# exit gracefully on end
echo " "
echo "Cleaning up old files."
echo " "
/bin/rm -rf $data >& /dev/null
/bin/rm -rf $timings >& /dev/null

#
#
# If the data directory has not been written, create it and put all the output into the
# data directory.
#
#
if(!(-e $data)) then
	mkdir $data
	echo " "
	echo "Creating the time_ans directory."
	echo " "
	set createoutput
endif

if(!(-e $timings)) then
	mkdir $timings
	echo "Creating the timings directory."
endif

if(!(-e $timingstore)) then
	mkdir $timingstore
	echo "Creating the timingstore directory."
endif

####
#
#
#
# This will run a set of files to make sure that they are giving the right answers.
#
####
initial:
foreach i ($sfiles)
	echo -n "Testing the " $i " program..."
	$coral -q < $test/${i}.X |& $filter | $sort >& $data/${i}.out
	echo "done."
	grep -si error $data/${i}.out
	@ s = $status
	if ($s == 0) echo "*** Errors occurred creating" $data/${i}.out 
end

########
#
# Clean up.
#
#######
end:
echo " "
echo End of tests.
set day = `date | cut -f3 -d' '` ; echo Day $day	# current day
set month = `date | cut -f2 -d' '` ; echo Month $month	# current month
set year = `date | cut -f6 -d' '` ; echo Year $year	# current year
set time = `date | cut -f4 -d' '` ; echo Time $time	# current time
mv $timings $timingstore/timings.$day.$month.$year.$time
exit 0

usage:

echo Usage: test_suite \[-help\] \[-s \"list of files to test\"\]
exit 1
