#! /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="-pg -mvhome"
#
# Some people don't include "." in their path (! in case an ls trojan horse,
# I guess - if someone does that to you, you have bigger problems).  This
# code tests to see if you have a path to mpirun; if not, it tries ./mpirun.
IFS="${IFS= 	}"; saveifs="$IFS"; IFS="${IFS}:"
for dir in $PATH ; do 
    if [ -x $dir/mpirun ] ; then
        mpirun="mpirun"
        break
    fi
done
IFS="$saveifs"
if [ -z "$mpirun" -a -x "./mpirun" ] ; then
    mpirun=./mpirun
fi
if [ -z "$mpirun" ] ; then
    echo "No mpirun in path.  Testing can not proceed."
    exit 1
fi
#
# If the programs are not available, run make.
runtests=1
makeeach=0
check_at_once=1
quiet=0
MAKE="make"
# Using shifts should  remove args from the list.
for arg in "$@" ; do
    case $arg in 
	-checkonly)
	shift
	runtests=0
	;;
        -margs=*)
	shift
	margs=`echo $arg | sed 's/-margs=//'`
	args="$args $margs"
	;;
	-echo)
	shift
	set -x
	;;
	-quiet)
	shift
	quiet=1
	;;
	-small)
	shift
	makeeach=1
	;;
	-atend)
	shift
	check_at_once=0
	;;
	-help|-u)
	shift
	echo "runtests [-checkonly] [-margs='...'] [-atend]"
	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."
	echo "If -atend is used, the success of the tests is checked only"
	echo "at the end of the test rather than also after each test."
	exit 1
	;;
	*)
	if test -n "$arg" ; then
	    echo "Passing remaining arguments to programs ($*)"
	    break
        fi
	;;
    esac
done

# MakeExe program-name
MakeExe() {
    if [ ! -x $1 ] ; then
	$MAKE $1
        if [ ! -x $1 ] ; then 
	    echo "Could not build executable $1; aborting tests"
	    exit 1
        fi
    fi
}
# CleanExe program-name
CleanExe() {
    if [ $makeeach = 1 ] ; then
	/bin/rm -f $1 $1.o
    fi
}
# Output marker
OutTime() {
    if [ $quiet = 0 ] ; then
	if [ -z "$hostname" ] ; then
	    hostname=`hostname`
	fi
	d=`date`
	echo "$hostname : $d"
    fi
}

# Do an "on the fly" check for problems.
CheckOutput() {
  if [ $check_at_once = 1 ] ; then
    stdfile=$1.std
    if [ ! -s $1.out ] ; then
        echo "No output file $1.out!"
    elif [ -s $stdfile ] ; then
        stdfile2=${stdfile}2
        if diff -b $1.out $stdfile > /dev/null ; then
	    true
	elif [ -s $stdfile2 ] ; then 
	    # check for alternate in case configuration has fewer datatypes
	    if diff -b $1.out $stdfile2 > /dev/null ; then
	        true
            else
	        echo "Differences in $1.out"
	        diff -b $1.out $stdfile
	        nodiff=0
	    fi
        else
	    echo "Differences in $1.out"
	    diff -b $1.out $stdfile
	fi
    else
        echo "Can not find file $stdfile to compare against for test $1"
    fi
  fi
}
## RunTest program-name marker-text outputfile programargs
#RunTest() {
#    testfiles="$testfiles $3"
#    /bin/rm -f $3
#    MakeExe $1
#    echo "$2"
#    echo "$2" >> $3
#    $mpirun $args -np 2 $1 "$4" >> $3 2>&1
#    echo "$2" >> $3
#    CleanExe $1
#}   

# If the programs are not available, run make.
if [ ! -x sendrecv -a $makeeach = 0 ] ; then
    $MAKE default
fi

testfiles=""
if [ $runtests = 1 ] ; then
echo '**** Testing MPI Point-to-point routines ****'

OutTime
testfiles="$testfiles sendrecv.out"
/bin/rm -f sendrecv.out
MakeExe sendrecv
echo '**** Testing MPI_Send and MPI_Recv ****' >> sendrecv.out
echo '**** Testing MPI_Send and MPI_Recv ****' 
/bin/rm -f sendrecv-[012].out
$mpirun $args -np 2 -mvback "sendrecv-0.out sendrecv-1.out" sendrecv "$@" >> sendrecv-2.out 2>&1
cat sendrecv-[012].out >> sendrecv.out
/bin/rm -f sendrecv-[012].out
echo '**** Testing MPI_Send and MPI_Recv ****' >> sendrecv.out
CheckOutput sendrecv
CleanExe sendrecv
#
OutTime
testfiles="$testfiles sendrecv2.out"
/bin/rm -f sendrecv2.out
MakeExe sendrecv2
echo '**** Testing MPI_Send and MPI_Recv (2) ****' >> sendrecv2.out
echo '**** Testing MPI_Send and MPI_Recv (2) ****' 
$mpirun $args -np 2 sendrecv2 "$@" >> sendrecv2.out 2>&1
echo '**** Testing MPI_Send and MPI_Recv (2) ****' >> sendrecv2.out
CheckOutput sendrecv2
CleanExe sendrecv2
#
OutTime
testfiles="$testfiles sendrecv3.out"
/bin/rm -f sendrecv3.out
MakeExe sendrecv3
echo '**** Testing MPI_Send and MPI_Recv (3) ****' >> sendrecv3.out
echo '**** Testing MPI_Send and MPI_Recv (3) ****' 
$mpirun $args -np 2 sendrecv3 "$@" >> sendrecv3.out 2>&1
echo '**** Testing MPI_Send and MPI_Recv (3) ****' >> sendrecv3.out
CheckOutput sendrecv3
CleanExe sendrecv3
#
OutTime
testfiles="$testfiles sendrecv4.out"
/bin/rm -f sendrecv4.out
MakeExe sendrecv4
echo '**** Testing MPI_Send and MPI_Recv (4) ****' >> sendrecv4.out
echo '**** Testing MPI_Send and MPI_Recv (4) ****' 
$mpirun $args -np 2 sendrecv4 "$@" >> sendrecv4.out 2>&1
echo '**** Testing MPI_Send and MPI_Recv (4) ****' >> sendrecv4.out
CheckOutput sendrecv4
CleanExe sendrecv4
#
OutTime
testfiles="$testfiles bsendtest.out"
/bin/rm -f bsendtest.out
MakeExe bsendtest
echo '**** Testing MPI_Bsend and MPI_Recv (4) ****' >> bsendtest.out
echo '**** Testing MPI_Bsend and MPI_Recv (4) ****' 
$mpirun $args -np 2 -mvback "bsendtest-0.out bsendtest-1.out" bsendtest "$@" >> bsendtest.out 2>&1
echo '**** Testing MPI_Bsend and MPI_Recv (4) ****' >> bsendtest.out
CheckOutput bsendtest
CleanExe bsendtest
#
OutTime
testfiles="$testfiles isndrcv.out"
/bin/rm -f isndrcv.out
MakeExe isndrcv
echo '**** Testing MPI_Isend and MPI_Irecv ****'
echo '**** Testing MPI_Isend and MPI_Irecv ****' >> isndrcv.out
/bin/rm -f isndrcv-[012].out
$mpirun $args -np 2 -mvback "isndrcv-0.out isndrcv-1.out" isndrcv "$@" > isndrcv-2.out 2>&1 
cat isndrcv-[012].out >> isndrcv.out
/bin/rm -f isndrcv-[012].out
echo '**** Testing MPI_Isend and MPI_Irecv ****' >> isndrcv.out
CheckOutput isndrcv
CleanExe isndrcv
#
OutTime
testfiles="$testfiles irsend.out"
/bin/rm -f irsend.out
MakeExe irsend
echo '**** Testing MPI_Irsend ****' >> irsend.out
echo '**** Testing MPI_Irsend ****' 
$mpirun $args -np 2 irsend "$@" >> irsend.out 2>&1
echo '**** Testing MPI_Irsend ****' >> irsend.out
CheckOutput irsend
CleanExe irsend
#
OutTime
testfiles="$testfiles irsendinit.out"
/bin/rm -f irsendinit.out
MakeExe irsendinit
echo '**** Testing MPI_Rsend_init ****' >> irsendinit.out
echo '**** Testing MPI_Rsend_init ****' 
$mpirun $args -np 2 irsendinit "$@" >> irsendinit.out 2>&1
echo '**** Testing MPI_Rsend_init ****' >> irsendinit.out
CheckOutput irsendinit
CleanExe irsendinit
#
OutTime
testfiles="$testfiles testsome.out"
/bin/rm -f testsome.out
MakeExe testsome
echo '**** Testing MPI_Testsome/Testany/Waitsome ****' >> testsome.out
echo '**** Testing MPI_Testsome/Testany/Waitsome ****' 
$mpirun $args -np 2 testsome "$@" >> testsome.out 2>&1
echo '**** Testing MPI_Testsome/Testany/Waitsome ****' >> testsome.out
CheckOutput testsome
CleanExe testsome
#
OutTime
testfiles="$testfiles testall.out"
/bin/rm -f testall.out
MakeExe testall
echo '**** Testing MPI_Testall ****' >> testall.out
echo '**** Testing MPI_Testall ****' 
$mpirun $args -np 2 testall "$@" >> testall.out 2>&1
echo '**** Testing MPI_Testall ****' >> testall.out
CheckOutput testall
CleanExe testall
#
OutTime
testfiles="$testfiles cancel.out"
/bin/rm -f cancel.out
MakeExe cancel
echo '**** Checking MPI_Cancel ****'
echo '**** Checking MPI_Cancel ****' >> cancel.out
$mpirun $args -np 2 cancel "$@" >> cancel.out 2>&1
echo '**** Checking MPI_Cancel ****' >> cancel.out
CheckOutput cancel
CleanExe cancel
#
OutTime
testfiles="$testfiles sndrcv.out"
/bin/rm -f sndrcv.out
MakeExe sndrcv
echo '**** Testing MPI_Sendrecv ****' >> sndrcv.out
echo '**** Testing MPI_Sendrecv ****' 
$mpirun $args -np 2 sndrcv "$@" >> sndrcv.out 2>&1
echo '**** Testing MPI_Sendrecv ****' >> sndrcv.out
CheckOutput sndrcv
CleanExe sndrcv
#
OutTime
testfiles="$testfiles sndrcvrep.out"
/bin/rm -f sndrcvrep.out
MakeExe sndrcvrep
echo '**** Testing MPI_Sendrecv_replace ****' >> sndrcvrep.out
echo '**** Testing MPI_Sendrecv_replace ****' 
$mpirun $args -np 2 sndrcvrep "$@" >> sndrcvrep.out 2>&1
echo '**** Testing MPI_Sendrecv_replace ****' >> sndrcvrep.out
CheckOutput sndrcvrep
CleanExe sndrcvrep
#
OutTime
testfiles="$testfiles getelm.out"
/bin/rm -f getelm.out
MakeExe getelm
echo '**** Testing MPI_Get_elements ****' >> getelm.out
echo '**** Testing MPI_Get_elements ****' 
$mpirun $args -np 2 getelm "$@" >> getelm.out 2>&1
echo '**** Testing MPI_Get_elements ****' >> getelm.out
CheckOutput getelm
CleanExe getelm
#
OutTime
testfiles="$testfiles overtake.out"
/bin/rm -f overtake.out
MakeExe overtake
echo '**** Verifying that messages are non-overtaking ****'
echo '**** Verifying that messages are non-overtaking ****' >> overtake.out
/bin/rm -f overtake-[01].out
$mpirun $args -np 2 -mvback "overtake-0.out overtake-1.out" overtake "$@" >> overtake.out 2>&1
cat overtake-[01].out >> overtake.out
/bin/rm -f overtake-[01].out
echo '**** Verifying that messages are non-overtaking ****' >> overtake.out
CheckOutput overtake
CleanExe overtake
#
OutTime
testfiles="$testfiles ssendtest.out"
/bin/rm -f ssendtest.out
MakeExe ssendtest
echo '**** Verifying ssend ****'
echo '**** Verifying ssend ****' >> ssendtest.out
$mpirun $args -np 2 -mvback "ssendtest-1.out" ssendtest "$@" >> ssendtest.out 2>&1
echo '**** Verifying ssend ****' >> ssendtest.out
CheckOutput ssendtest
CleanExe ssendtest
#
OutTime
testfiles="$testfiles ssendtest2.out"
/bin/rm -f ssendtest2.out
MakeExe ssendtest2
echo '**** Verifying ssend (2) ****'
echo '**** Verifying ssend (2) ****' >> ssendtest2.out
$mpirun $args -np 2 -mvback "ssendtest2-1.out" ssendtest2 "$@" >> ssendtest2.out 2>&1
echo '**** Verifying ssend (2) ****' >> ssendtest2.out
CheckOutput ssendtest2
CleanExe ssendtest2
#
OutTime
testfiles="$testfiles issendtest.out"
/bin/rm -f issendtest.out
MakeExe issendtest
echo '**** Verifying Issend ****'
echo '**** Verifying Issend ****' >> issendtest.out
$mpirun $args -np 2 -mvback "issendtest-1.out" issendtest "$@" >> issendtest.out 2>&1
echo '**** Verifying Issend ****' >> issendtest.out
CheckOutput issendtest
CleanExe issendtest
#
OutTime
testfiles="$testfiles reqcreate.out"
/bin/rm -f reqcreate.out
MakeExe reqcreate
echo '**** Checking the request creation routines ****'
echo '**** Checking the request creation routines ****' >> reqcreate.out
$mpirun $args -np 1 reqcreate "$@" >> reqcreate.out 2>&1
echo '**** Checking the request creation routines ****' >> reqcreate.out
CheckOutput reqcreate
CleanExe reqcreate
#
OutTime
testfiles="$testfiles typebase.out"
/bin/rm -f typebase.out
MakeExe typebase
echo '**** Checking the type (sizes) routines ****'
echo '**** Checking the type (sizes) routines ****' >> typebase.out
$mpirun $args -np 1 typebase "$@" >> typebase.out 2>&1
echo '**** Checking the type (sizes) routines ****' >> typebase.out
CheckOutput typebase
CleanExe typebase
#
OutTime
testfiles="$testfiles typecreate.out"
/bin/rm -f typecreate.out
MakeExe typecreate
echo '**** Checking the type creation routines ****'
echo '**** Checking the type creation routines ****' >> typecreate.out
$mpirun $args -np 1 typecreate "$@" >> typecreate.out 2>&1
echo '**** Checking the type creation routines ****' >> typecreate.out
CheckOutput typecreate
CleanExe typecreate
#
OutTime
testfiles="$testfiles typetest.out"
/bin/rm -f typetest.out
MakeExe typetest
echo '**** Checking the type routines ****'
echo '**** Checking the type routines ****' >> typetest.out
/bin/rm -f typetest-[01].out
$mpirun $args -np 2 -mvback "typetest-0.out typetest-1.out" typetest "$@" >> typetest.out 2>&1
if [ -s typetest-0.out ] ; then
    cat typetest-0.out >> typetest.out
fi
/bin/rm -f typetest-[01].out
echo '**** Checking the type routines ****' >> typetest.out
CheckOutput typetest
CleanExe typetest
#
OutTime
testfiles="$testfiles typeub.out"
/bin/rm -f typeub.out
MakeExe typeub
echo '**** Checking the type routines: MPI_UB ****'
echo '**** Checking the type routines: MPI_UB ****' >> typeub.out
$mpirun $args -np 2 typeub "$@" >> typeub.out 2>&1
echo '**** Checking the type routines: MPI_UB ****' >> typeub.out
CheckOutput typeub
CleanExe typeub
#
OutTime
testfiles="$testfiles typeub2.out"
/bin/rm -f typeub2.out
MakeExe typeub2
echo '**** Checking the type routines: MPI_UB(2) ****'
echo '**** Checking the type routines: MPI_UB(2) ****' >> typeub2.out
$mpirun $args -np 1 typeub2 "$@" >> typeub2.out 2>&1
echo '**** Checking the type routines: MPI_UB(2) ****' >> typeub2.out
CheckOutput typeub2
CleanExe typeub2
#
OutTime
testfiles="$testfiles typeub3.out"
/bin/rm -f typeub3.out
MakeExe typeub3
echo '**** Checking the type routines: MPI_UB(3) ****'
echo '**** Checking the type routines: MPI_UB(3) ****' >> typeub3.out
$mpirun $args -np 1 typeub3 "$@" >> typeub3.out 2>&1
echo '**** Checking the type routines: MPI_UB(3) ****' >> typeub3.out
CheckOutput typeub3
CleanExe typeub3
#
OutTime
testfiles="$testfiles dtypelife.out"
/bin/rm -f dtypelife.out
MakeExe dtypelife
echo '**** Checking the type routines: MPI_Type_free ****'
echo '**** Checking the type routines: MPI_Type_free ****' >> dtypelife.out
$mpirun $args -np 2 dtypelife "$@" >> dtypelife.out 2>&1
echo '**** Checking the type routines: MPI_Type_free ****' >> dtypelife.out
CheckOutput dtypelife
CleanExe dtypelife
#
OutTime
testfiles="$testfiles commit.out"
/bin/rm -f commit.out
MakeExe commit
echo '**** Checking the type routines: MPI_Type_commit ****'
echo '**** Checking the type routines: MPI_Type_commit ****' >> commit.out
$mpirun $args -np 1 commit "$@" >> commit.out 2>&1
echo '**** Checking the type routines: MPI_Type_commit ****' >> commit.out
CheckOutput commit
CleanExe commit
#
OutTime
testfiles="$testfiles third.out"
/bin/rm -f third.out
MakeExe third
echo '*** Testing Unexpected messages ***'
echo '*** Testing Unexpected messages ***' >> third.out
$mpirun $args -np 2 third "$@" >> pt2pt.out >> third.out 2>&1
echo '*** Testing Unexpected messages ***' >> third.out
CheckOutput third
CleanExe third
#
OutTime
testfiles="$testfiles fourth.out"
/bin/rm -f fourth.out
MakeExe fourth
echo '*** Testing Irecv/Isend/Wait ***'
echo '*** Testing Irecv/Isend/Wait ***' >> fourth.out
$mpirun $args -np 4 fourth "$@" >> fourth.out 2>&1
echo '*** Testing Irecv/Isend/Wait ***' >> fourth.out
CheckOutput fourth
CleanExe fourth
#
OutTime
testfiles="$testfiles fifth.out"
/bin/rm -f fifth.out
MakeExe fifth
echo '*** Testing Irecv/Isend/Waitall ***'
echo '*** Testing Irecv/Isend/Waitall ***' >> fifth.out
$mpirun $args -np 4 fifth "$@" >> fifth.out 2>&1
echo '*** Testing Irecv/Isend/Waitall ***' >> fifth.out
CheckOutput fifth
CleanExe fifth
#
OutTime
testfiles="$testfiles sixth.out"
/bin/rm -f sixth.out
MakeExe sixth
echo '*** Testing attribute manipulation ***'
echo '*** Testing attribute manipulation ***' >> sixth.out
$mpirun $args -np 2 sixth "$@" >> sixth.out 2>&1
echo '*** Testing attribute manipulation ***' >> sixth.out
CheckOutput sixth
CleanExe sixth
#
OutTime
testfiles="$testfiles nblock.out"
/bin/rm -f nblock.out
MakeExe nblock
echo '*** Testing Isend/Irecv (large numbers) ***'
echo '*** Testing Isend/Irecv (large numbers) ***' >> nblock.out
$mpirun $args -np 4 nblock "$@" >> nblock.out 2>&1
echo '*** Testing Isend/Irecv (large numbers) ***' >> nblock.out
CheckOutput nblock
CleanExe nblock
#
OutTime
testfiles="$testfiles nbtest.out"
/bin/rm -f nbtest.out
MakeExe nbtest
echo '*** Testing Isend/Probe/Recv (large numbers) ***'
echo '*** Testing Isend/Probe/Recv (large numbers) ***' >> nbtest.out
$mpirun $args -np 4 nbtest "$@" >> nbtest.out 2>&1
echo '*** Testing Isend/Probe/Recv (large numbers) ***' >> nbtest.out
CheckOutput nbtest
CleanExe nbtest
#
OutTime
testfiles="$testfiles sendmany.out"
/bin/rm -f sendmany.out
MakeExe sendmany
echo '*** Testing Send (many procs) ***'
echo '*** Testing Send (many procs) ***' >> sendmany.out
$mpirun $args -np 8 sendmany "$@" >> sendmany.out 2>&1
echo '*** Testing Send (many procs) ***' >> sendmany.out
CheckOutput sendmany
CleanExe sendmany
#
OutTime
testfiles="$testfiles order.out"
/bin/rm -f order.out
MakeExe order
echo '*** Testing Recv ordering ***'
echo '*** Testing Recv ordering ***' >> order.out
$mpirun $args -np 2 order "$@" >> order.out 2>&1
echo '*** Testing Recv ordering ***' >> order.out
CheckOutput order
CleanExe order
#
OutTime
testfiles="$testfiles trunc.out"
/bin/rm -f trunc.out
MakeExe trunc
echo '*** Testing Message trunction ***'
echo '*** Testing Message trunction ***' >> trunc.out
$mpirun $args -np 2 trunc "$@" >> trunc.out 2>&1
echo '*** Testing Message trunction ***' >> trunc.out
CheckOutput trunc
CleanExe trunc
#
OutTime
testfiles="$testfiles nullproc.out"
/bin/rm -f nullproc.out
MakeExe nullproc
echo '*** Testing handling of MPI_PROC_NULL ***'
echo '*** Testing handling of MPI_PROC_NULL ***' >> nullproc.out
$mpirun $args -np 2 nullproc "$@" >> nullproc.out 2>&1
echo '*** Testing handling of MPI_PROC_NULL ***' >> nullproc.out
CheckOutput nullproc
CleanExe nullproc
#
OutTime
testfiles="$testfiles relrank.out"
/bin/rm -f relrank.out
MakeExe relrank
echo '*** Testing handling of relative rank ***'
echo '*** Testing handling of relative rank ***' >> relrank.out
$mpirun $args -np 2 relrank "$@" >> relrank.out 2>&1
echo '*** Testing handling of relative rank ***' >> relrank.out
CheckOutput relrank
CleanExe relrank
#
OutTime
testfiles="$testfiles hvectest.out"
/bin/rm -f hvectest.out
MakeExe hvectest
echo '*** Testing Vector type ***'
echo '*** Testing Vector type ***' >> hvectest.out
$mpirun $args -np 2 hvectest "$@" >> hvectest.out 2>&1
echo '*** Testing Vector type ***' >> hvectest.out
CheckOutput hvectest
CleanExe hvectest
#
OutTime
testfiles="$testfiles hvectest2.out"
/bin/rm -f hvectest2.out
MakeExe hvectest2
echo '*** Testing struct type for vectors (MPI_UB) ***'
echo '*** Testing struct type for vectors (MPI_UB) ***' >> hvectest2.out
$mpirun $args -np 2 hvectest2 "$@" >> hvectest2.out 2>&1
echo '*** Testing struct type for vectors (MPI_UB) ***' >> hvectest2.out
CheckOutput hvectest2
CleanExe hvectest2
#
OutTime
testfiles="$testfiles hvec.out"
/bin/rm -f hvec.out
MakeExe hvec
echo '*** Testing Type_Hvector ***'
echo '*** Testing Type_Hvector ***' >> hvec.out
$mpirun $args -np 2 hvec "$@" >> hvec.out 2>&1
echo '*** Testing Type_Hvector ***' >> hvec.out
CheckOutput hvec
CleanExe hvec
#
OutTime
testfiles="$testfiles hindexed.out"
/bin/rm -f hindexed.out
MakeExe hindexed
echo '*** Testing Type_Hindexed ***'
echo '*** Testing Type_Hindexed ***' >> hindexed.out
$mpirun $args -np 1 hindexed "$@" >> hindexed.out 2>&1
echo '*** Testing Type_Hindexed ***' >> hindexed.out
CheckOutput hindexed
CleanExe hindexed
#
OutTime
testfiles="$testfiles probe.out"
/bin/rm -f probe.out
MakeExe probe
echo '*** Testing Probe and Get_count ***'
echo '*** Testing Probe and Get_count ***' >> probe.out
$mpirun $args -np 2 probe "$@" >> probe.out 2>&1
echo '*** Testing Probe and Get_count ***' >> probe.out
CheckOutput probe
CleanExe probe
#
OutTime
testfiles="$testfiles probe1.out"
/bin/rm -f probe1.out
MakeExe probe1
echo '*** Testing Iprobe and Get_count ***'
echo '*** Testing Iprobe and Get_count ***' >> probe1.out
$mpirun $args -np 2 probe1 "$@" >> probe1.out 2>&1
echo '*** Testing Iprobe and Get_count ***' >> probe1.out
CheckOutput probe1
CleanExe probe1
#
OutTime
testfiles="$testfiles self.out"
/bin/rm -f self.out
MakeExe self
echo '*** Testing send to self ***' 
echo '*** Testing send to self ***' >> self.out
$mpirun $args -np 1 self "$@" >> self.out 2>&1
echo '*** Testing send to self  ***' >> self.out
CheckOutput self
CleanExe self
#
#
OutTime
testfiles="$testfiles testtest1.out"
/bin/rm -f testtest1.out
MakeExe testtest1
echo '*** Testing MPI_Test ***' 
echo '*** Testing MPI_Test ***' >> testtest1.out
$mpirun $args -np 2 testtest1 "$@" >> testtest1.out 2>&1
echo '*** Testing MPI_Test ***' >> testtest1.out
CheckOutput testtest1
CleanExe testtest1
#
OutTime
testfiles="$testfiles persistent.out"
/bin/rm -f persistent.out
MakeExe persistent
echo '*** Testing MPI_Recv_init ***' 
echo '*** Testing MPI_Recv_init ***' >> persistent.out
$mpirun $args -np 4 persistent "$@" >> persistent.out 2>&1
echo '*** Testing MPI_Recv_init ***' >> persistent.out
CheckOutput persistent
CleanExe persistent
#
OutTime
testfiles="$testfiles persist.out"
/bin/rm -f persist.out
MakeExe persist
echo '*** Testing MPI_Startall/Request_free ***' 
echo '*** Testing MPI_Startall/Request_free ***' >> persist.out
$mpirun $args -np 4 persist "$@" >> persist.out 2>&1
echo '*** Testing MPI_Startall/Request_free ***' >> persist.out
CheckOutput persist
CleanExe persist
#
OutTime
testfiles="$testfiles waitall.out"
/bin/rm -f waitall.out
MakeExe waitall
echo '*** Testing MPI_Waitall ***' 
echo '*** Testing MPI_Waitall ***' >> waitall.out
$mpirun $args -np 4 waitall "$@" >> waitall.out 2>&1
echo '*** Testing MPI_Waitall ***' >> waitall.out
CheckOutput waitall
CleanExe waitall
#
OutTime
testfiles="$testfiles pack.out"
/bin/rm -f pack.out
MakeExe pack
echo '*** Testing MPI_Pack ***' 
echo '*** Testing MPI_Pack ***' >> pack.out
$mpirun $args -np 2 pack "$@" >> pack.out 2>&1
echo '*** Testing MPI_Pack ***' >> pack.out
CheckOutput pack
CleanExe pack
#
OutTime
testfiles="$testfiles flood.out"
/bin/rm -f flood.out
MakeExe flood
echo '**** Testing large messages ****' >> flood.out
echo '**** Testing large messages ****' 
$mpirun $args -np 2 flood "$@" >> flood.out 2>&1
echo '**** Testing large messages ****' >> flood.out
CheckOutput flood
CleanExe flood
#
#OutTime
#testfiles="$testfiles flood2.out"
#/bin/rm -f flood2.out
#MakeExe flood2
#echo '**** Testing large numbers of messages ****' >> flood2.out
#echo '**** Testing large numbers of messages ****' 
#$mpirun $args -np 2 flood2 "$@" >> flood2.out 2>&1
#echo '**** Testing large numbers of messages ****' >> flood2.out
#CheckOutput flood2
#CleanExe flood2
#
# Run Fortran tests ONLY if Fortran available
if [ 1 = 1 ] ; then 
    echo "FORTRAN TESTS"
    #
    #echo "*** secondf ***" >> pt2pt.out
    #$mpirun $args -np 2 secondf "$@" >> pt2pt.out 2>&1
    #
    OutTime
    testfiles="$testfiles allpair.out"
    /bin/rm -f allpair.out
    MakeExe allpair
    echo '*** Testing pt-2-pt from Fortran ***'
    echo '*** Testing pt-2-pt from Fortran ***' >> allpair.out
    $mpirun $args -np 2 allpair "$@" >> allpair.out 2>&1
    echo '*** Testing pt-2-pt from Fortran ***' >> allpair.out
    CheckOutput allpair
    CleanExe allpair
    #
    OutTime
    testfiles="$testfiles allpair2.out"
    /bin/rm -f allpair2.out
    MakeExe allpair2
    echo '*** Testing pt-2-pt from Fortran (many calls) ***'
    echo '*** Testing pt-2-pt from Fortran  (many calls) ***' >> allpair2.out
    $mpirun $args -np 2 allpair2 "$@" >> allpair2.out 2>&1
    echo '*** Testing pt-2-pt from Fortran  (many calls) ***' >> allpair2.out
    CheckOutput allpair2
    CleanExe allpair2
    #
    OutTime
    testfiles="$testfiles structf.out"
    /bin/rm -f structf.out
    MakeExe structf
    echo '*** Testing Type_struct from Fortran ***'
    echo '*** Testing Type_struct from Fortran ***' >> structf.out
    # This is tricky.  Because of a bug in IRIX64, we need to direct 
    # input from /dev/null (so that we can know that we need a new process
    # group).  This should be ok for everyone, but SunOS 4.1.4 tends to
    # panic (!!) in this case.  Since both behaviors represent broken
    # operating systems, we test for ARCH=IRIX64 
    if [ "sun4" = "IRIX64" ] ; then 
      $mpirun $args -np 2 structf "$@" >> structf.out 2>&1 < /dev/null
    else
      $mpirun $args -np 2 structf "$@" >> structf.out 2>&1
    fi
    echo '*** Testing Type_struct from Fortran ***' >> structf.out
    CheckOutput structf
    CleanExe structf
    #
    OutTime
    testfiles="$testfiles send1.out"
    /bin/rm -f send1.out
    MakeExe send1
    echo '*** Testing pt-2-pt from Fortran (2) ***'
    echo '*** Testing pt-2-pt from Fortran (2) ***' >> send1.out
    $mpirun $args -np 2 send1 "$@" >> send1.out 2>&1
    echo '*** Testing pt-2-pt from Fortran (2) ***' >> send1.out
    CheckOutput send1
    CleanExe send1
    #
#    testfiles="$testfiles pingpong.out"
#    /bin/rm -f pingpong.out
#    MakeExe pingpong
#    echo '*** Testing pt-2-pt from Fortran (3) ***'
#    echo '*** Testing pt-2-pt from Fortran (3) ***' >> pingpong.out
#    $mpirun $args -np 2 pingpong "$@" >> pingpong.out 2>&1
#    echo '*** Testing pt-2-pt from Fortran (3) ***' >> pingpong.out
#    CheckOutput pingpong
#    CleanExe pingpong
    #
    echo "END OF FORTRAN TESTS"
fi
#
else
    # Just run checks
    testfiles=`echo *.out`
    if test "$testfiles" = "*.out" ; then
	echo "No output files remain from previous test!"
	exit 1
    fi
fi
#
echo '*** Checking for differences from expected output ***'
/bin/rm -f pt2pt.diff
nodiff=1
for file in $testfiles ; do
    stdfile=`basename $file .out`.std
    # if basename is sendrecv or isndrcv, then we may want to test 
    # with .std2 as well.  We should really separate out the long double
    # tests ...
    if [ -s $stdfile ] ; then
	stdfile2=${stdfile}2
        if diff -b $file $stdfile > /dev/null ; then
	    true
	elif [ -s $stdfile2 ] ; then 
	    # check for alternate in case configuration has fewer datatypes
	    if diff -b $file $stdfile2 > /dev/null ; then
	        true
            else
	        echo "Differences in `basename $file .out`" >> pt2pt.diff
	        diff -b $file $stdfile >> pt2pt.diff
	        nodiff=0
	    fi
        else
	    echo "Differences in `basename $file .out`" >> pt2pt.diff
	    diff -b $file $stdfile >> pt2pt.diff
	    nodiff=0
	fi
    else
        echo "Can not find file $stdfile to compare against for test `basename $file .out`"
	nodiff=0
    fi
done
if [ -s pt2pt.diff ] ; then
   cat pt2pt.diff
elif [ $nodiff = 1 ] ; then
   echo "-- No differences found; test successful"
fi
exit 0

