#! /bin/sh
#
# Run some of the tests.  If any arguments are provided, pass them to the
# test programs.
#
# -mvhome is needed for the ANL SP, and is ignored by others
args=
device=
top_srcdir=..
srcdir=../topol
MPICH_VERSION=
STOPFILE=${MPITEST_STOPTEST:-"$HOME/.stopmpichtests"}
mpirun=${MPIRUN:-"mpirun"}
MAKE="make"
#
# Load basic procedures
. ${top_srcdir}/runbase
#
# Set mpirun to the name/path of the mpirun program
FindMPIRUN
#
#
# If the programs are not available, run make.
#
runtests=1
makeeach=0
writesummaryfile=no
quiet=0
MAKE="make"
for arg in "$@" ; do
    case $arg in 
	-checkonly )
	runtests=0
	;;
        -margs=*)
	margs=`echo $arg | sed 's/-margs=//'`
	args="$args $margs"
	;;
	-summaryfile=*)
	writesummaryfile=yes
	summaryfile=`echo A$arg | sed 's/A-summaryfile=//'`
	;;
	-small)
	makeeach=1
	;;
	-quiet)
	shift
	quiet=1
	;;
	-help|-u)
	echo "runtests [-checkonly] [-margs='...'] [-small]"
	echo "run tests in this directory.  If -checkonly set, just run"
	echo "the differences check (do NO rerun the test programs)."
	echo "If -margs is used, these options are passed to mpirun."
	echo "If -small is used, the examples are built, run, and deleted."
	exit 1
	;;
	*)
	if test -n "$arg" ; then
   	    echo "runtests: Unknown argument ($arg)"
	    exit 1
        fi
	;;
    esac
done

if [ ! -x cart -a $makeeach = 0 -a $runtests = 1 ] ; then
    $MAKE default
fi

testfiles=""
if [ $runtests = 1 ] ; then

RunTest dims 1 "**** Testing MPI_Dims_create ****"

RunTest cart 4 "**** Testing MPI_Cart_create etc ****"

RunTest cart2 4 "**** Testing MPI_Cart_coords etc ****"

RunTest cartmap 4 "**** Testing MPI_Cart_map etc ****"

RunTest cartorder 4 "**** Testing MPI_Cart_create etc (2) ****"

RunTest graphtest 4 "**** Testing MPI_Graph_create etc ****"
#
# Run Fortran tests ONLY if Fortran available
if [ 0 = 1 ] ; then 
    echo "FORTRAN TESTS"

    RunTest cartf 4 "*** Testing cart from Fortran ***"

    RunTest cart1f 4 "*** Testing cart1 from Fortran ***"

    RunTest cart2f 4 "*** Testing cart2 from Fortran ***"

    RunTest twod 2 "*** Testing twod from Fortran ***"
fi
else
    # Just run checks
    testfiles=*.out
fi
#
echo '*** Checking for differences from expected output ***'
CheckAllOutput topol.diff
exit 0
