#! /bin/sh
# This script is generated by configure for the purpose of reporting on
# the port of MPICH to a new architecture.  This runs ONLY the test programs
#
# To simplify testing and a few special cases, this script takes a few options
# -author="name"        Use instead of 'whoami'
# -nomake               Do not run make
# -noperf               Do not run performance tests
# -file=name            Output LaTeX file (default is doc/doc1.tex)
author="$LOGNAME"
nomake=0
noperf=0
filename="doc/doc1test.tex"
# This is the only portable way to get \b... into a file
write_beginex() {
    cat <<. >>$filename
\begin{example}
.
}
#
for arg in "$@" ; do
    case $arg in 
	-author=* )
	author="`echo $arg|sed -e 's/-author=//' -e 's/_/ /'`"
	;;
	-file=* )
	filebase=`echo $arg|sed 's/-file=//'`
        filename="${filebase}test.tex"
	;;
 	-nomake )
	nomake=1
	;;
 	-noperf )
	noperf=1
	;;
	-testsdone)
	testfile="done"
	;;
	-echo)
	set -x
	;;
	-help)
	echo "doc/porttest [ -testsdone ]"
	echo "Create the tests part of the port document.  If -testsdone"
	echo "is given, then"
	echo "   make testing_save > test.log 2>&1"
	echo "has been run in examples/test."
	echo "This script should be run from the MPICH root directory."
	exit 1
	;;
	*)
	if test -n "$arg" ; then 
	    echo "porttest: Unknown argument ($arg)"
	    exit 1
	fi
	;;
    esac
done
#
# Remove the old filename
/bin/rm -f $filename
#
############################################################################
# Some initial comments...
# sh is not reliable about processing redirects of stdin within if...else..fi
# For such cases, we place the output text within a routine, defined
# outside of the if..else..fi, and called conditionally.
############################################################################
cat <<. >> $filename 
\section{Test results}
MPICH comes with a collection of test programs in \file{examples/test}.  This
build of the MPICH MPI implementation ran the test programs.  The results
are given below.
.
#examples/test/coll/coll.diff, context/context.diff, env/env.diff, 
#pt2pt/pt2pt.diff
############################################################################
# Run the tests if necessary.
############################################################################
if test -z "$testfile" ; then
    (cd examples/test ; make testing_save TESTARGS=-small > test.log 2>&1 ) 
fi
if test ! -s examples/test/test.log ; then
    echo "No testing file!  Tests must not have run." >>$filename
    exit 0
else 
    echo " " >>$filename
fi
############################################################################
# Check the output...
############################################################################
if test -s examples/test/pt2pt.diff ; then
    echo "Errors detected in the point-to-point tests:" >> $filename
    write_beginex
    cat examples/test/pt2pt.diff >> $filename
    echo "\\end{example}" >> $filename
else
    echo "No problems detected in the point-to-point tests." >> $filename
fi
echo  " " >>$filename
if test -s examples/test/coll.diff ; then
    echo "Errors detected in the collective tests:" >> $filename
    write_beginex
    cat examples/test/coll.diff >> $filename
    echo "\\end{example}" >> $filename
else
    echo "No problems detected in the collective tests." >> $filename
fi
echo  " " >>$filename
if test -s examples/test/context.diff ; then
    echo "Errors detected in the context/communicator tests:" >> $filename
    write_beginex
    cat examples/test/context.diff >> $filename
    echo "\\end{example}" >> $filename
else
    echo "No problems detected in the context tests." >> $filename
fi
echo  " " >>$filename
if test -s examples/test/env.diff ; then
    echo "Errors detected in the environment tests:" >> $filename
    write_beginex
    cat examples/test/env.diff >> $filename
    echo "\\end{example}" >> $filename
else
    echo "No problems detected in the environment tests." >> $filename
fi
echo  " " >>$filename
if test -s examples/test/topol.diff ; then
    echo "Errors detected in the topology tests:" >> $filename
    write_beginex
    cat examples/test/topol.diff >> $filename
    echo "\\end{example}" >> $filename
else
    echo "No problems detected in the topology tests." >> $filename
fi
echo  " " >>$filename
