#
# Non-regression tests.
# Stephane Genaud, mer nov  2 18:26:35 CET 2005
#

#!/bin/bash 

LOGFILE="$0.log"
MPIRUN="p2pmpirun"
TEMPOUT=".tmpstdout"
TEMPERR=".tmpstderr"

. ./common

date > $LOGFILE
# init check
check_mpiboot

# source file to test :
SRC="../Pi/Pi.java"
compile ${SRC}
PROG=`basename ${SRC} .java`

# without replicas
procs=(1 2)
for i in ${procs[*]}; do
		printf "** Running $MPIRUN -n ${i} ${PROG} ... " | tee -a $LOGFILE
		($MPIRUN -n ${i} $PROG | tee -a $LOGFILE) > $TEMPOUT  2>$TEMPERR
            #-- does stderr collect file exist and has size > 0
		if [ -s $TEMPERR ]; then
			echo "**[ Error ] some errors occured. See $0.log for details."
			cat $TEMPERR | tee -a $LOGFILE
			rm -f $TEMPERR $TEMPOUT
                  exit 1
		else
            	grep "Pi is approximately 3.14" $TEMPOUT | tee -a $LOGFILE
		fi
done

# with replicas
procs=(2 3)
replicas=(2)
for i in ${procs[*]}; do
	for j in ${replicas[*]}; do
		printf "** Running $MPIRUN -n ${i} -r ${j} ${PROG} ... " | tee -a $LOGFILE
		($MPIRUN -n ${i} -r ${j} $PROG | tee -a $LOGFILE) > $TEMPOUT  2>$TEMPERR
	      #-- does stderr collect file exist and has size > 0
		if [ -s $TEMPERR ]; then
			echo "**[ Error ] some errors occured. See $0.log for details."
			cat $TEMPERR | tee -a $LOGFILE
			rm -f $TEMPERR $TEMPOUT
                  exit 1
		else
            	grep "Pi is approximately 3.14" $TEMPOUT | tee -a $LOGFILE
		fi
	done
done

date >> $LOGFILE
rm -f $TEMPERR $TEMPOUT
