#!/bin/sh 
#BHEADER**********************************************************************
# Copyright (c) 2006   The Regents of the University of California.
# Produced at the Lawrence Livermore National Laboratory.
# Written by the HYPRE team. UCRL-CODE-222953.
# All rights reserved.
#
# This file is part of HYPRE (see http://www.llnl.gov/CASC/hypre/).
# Please see the COPYRIGHT_and_LICENSE file for the copyright notice, 
# disclaimer, contact information and the GNU Lesser General Public License.
#
# HYPRE is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License (as published by the Free Software 
# Foundation) version 2.1 dated February 1999.
#
# HYPRE is distributed in the hope that it will be useful, but WITHOUT ANY 
# WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS 
# FOR A PARTICULAR PURPOSE.  See the terms and conditions of the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Revision: 1.153 $
#EHEADER**********************************************************************

#=============================================================================
#    Initialize variables
#=============================================================================
initialize_variables ()
{
  seconds; TOTAL=$SECS
  OldMask=`umask`
  umask 002
  Hdr="autotest"
  HYPRE_BATCH_MODE="no"
  HYPRE_SEND_MAIL="no"
  TEST_CASES="TEST_ams/*.sh TEST_ij/*.sh TEST_fac/*.sh TEST_sstruct/*.sh TEST_struct/*.sh"
  EXAMPLES_TEST_CASES="TEST_examples/*.sh"
  TEST_DIRS="ams ij fac sstruct struct examples"
  STD_CONFIGOPTIONS="all++ all77 babel debug default docs insure no_mpi \
                     openmp strict_checking test_alpha test_beta test_general examples"
  STD_MAKEOPTIONS="all configure"
  DEBUG_MODE="no"
  Build=1
  Run=2
  if [ -z "$MAKE" -o "$MAKE" = "" ] ; then
    MAKE="make -i"
  fi

#
#    Set current directory if this script (autotest_test) is not being run by the 
#    autotest script, which will cd to the directory ${HYPRE_REMOTE_DIR}.  
#    This script can be run independently from a directory one level higher 
#    than "linear_solvers".
  if [ -z "${HYPRE_REMOTE_DIR}" -o "${HYPRE_REMOTE_DIR}" = "" ] ; then
     HYPRE_REMOTE_DIR=`pwd`
  else			# assume we're executing from autotest
     if [ ! -d ${HYPRE_REMOTE_DIR} ] ; then
        echo "HYPRE_REMOTE_DIR is not defined"
        exit 2
     fi
  fi
 
#
# Define directory that contains the source codes
  if [ -d ${HYPRE_REMOTE_DIR}/linear_solvers/test ] ; then
    SRC=linear_solvers
  fi

  if [ -d ${HYPRE_REMOTE_DIR}/src/test ] ; then
    SRC=src
  fi

#
# Set standard directories
  StdBuildDir=${HYPRE_REMOTE_DIR}/${SRC}
  StdTestDir=${HYPRE_REMOTE_DIR}/${SRC}/test

#
# Define architecture of current platform
  if [ -z "$HYPRE_ARCH" ]
  then
     if [ -f "/bin/uname" ] 
     then
        HYPRE_OS="`/bin/uname -s`"
     fi

     case "$HYPRE_OS" in
	OSF1)
	    HYPRE_ARCH="dec";;
	AIX)
	    HYPRE_ARCH="aix";;
	"TFLOPS O/S")
	    HYPRE_ARCH="red";;
	Linux)
	    HYPRE_ARCH="linux";;
	IRIX64)
	    HYPRE_ARCH="sgi";;
     esac
  fi

#
# Set some architecture specific configurations
  if [ -r $StdTestDir/AUTOTEST/env.${HYPRE_ARCH} ] ; then
     . $StdTestDir/AUTOTEST/env.${HYPRE_ARCH}
  elif [ -r ./env.${HYPRE_ARCH} ] ; then
     . ./env.${HYPRE_ARCH}
  fi

#
# Need the nopoe script for AIX platforms to force single task
  if [ "$HYPRE_ARCH" = "aix" ] ; then
     CONFIGURE="nopoe ./configure"
  else
     CONFIGURE="./configure"
  fi
}

#=============================================================================
# Function for parsing of input arguments
#
# The getopts follows posix.2, if sh is a posix shell (as required by posix.2)
# then getopts is a built-in.
# If sh is a non posix.2 or a early Bourne shell (that probably implement the
# obsolete getopt) then getopts(1) will be used.
#=============================================================================
parse_arguments () 
{ 
  while getopts :Aa:Bb:cDdEe:fhi:l:mno:r:sv: arg
  do
    argcur=$arg
    case $arg in
      A) confbuildtest $Run    "--with-test-alpha"      "all"   " "     "test_alpha";;
      a) confbuildtest $OPTARG " "                      "all"   " "     "default";;
      B) confbuildtest $Run    "--with-test-beta"       "all"   " "     "test_beta";;
      b) confbuildtest $OPTARG "--with-babel"           "all"   " "     "babel";;
      c) confbuildtest $Build  " "                      "all++" "test"  "all++";;
      D) DEBUG_MODE="yes"; set -xv;;
      d) confbuildtest $Build  " "                      "all"   "docs"  "docs";;
      E) confbuildtest $Run    "--with-examples"        "all"   " "     "examples";;
      e) confbuildtest $OPTARG "--enable-debug"         "all"   " "     "debug";;
      f) confbuildtest $Build  " "                      "all77" "test"  "all77";;
      G) confbuildtest $Run    "--with-test-general"    "all"   " "     "test_general";;
      h) usage; exit 2;;
      i) confbuildtest $OPTARG "--with-insure"          "all"   " "     "insure";;
     +i) confbuildtest $OPTARG "--with-insure-to-file"  "all"   " "     "insure";;
      l) confbuildtest $OPTARG "--enable-shared"        "all"   " "     "shared";;
      m) HYPRE_SEND_MAIL="yes";;
      n) confbuildtest $Build  "--without-MPI"          "all"   " "     "no_mpi";;
      o) confbuildtest $OPTARG "--with-openmp"          "all"   " "     "openmp";;
      r) HYPRE_RUN_MACHINE=$OPTARG;;
      s) confbuildtest $Build  "--with-strict-checking" "all"   " "     "strict_checking";;
      v) HYPRE_MESSAGE=$OPTARG;;
      :) echo "$0: \"$argcur\" requires a value"; exit 2;;
     \?) echo "$0: INVALID option \"$argcur\" at $OPTIND"; exit 2;;
    esac
  done
  shift `expr $OPTIND - 1`
}

#=============================================================================
# Function for display of help/usage
#=============================================================================
usage () 
{
  printf "Usage: %s [-ABcDdEfGhmns] [-a opt] [-b opt] [-e opt]\n" $0
  printf "          [-i opt] [-o opt] [-r host] [-v text]\n"
  printf "\n"
  printf "All options are sequentially executed in left-to-right order as\n"
  printf "entered on the command line.\n"
  printf "\n"
  printf "Options for the "opt" argument are "1" or "2" where:\n"
  printf "  1=configure and make\n"
  printf "  2=configure, make and execute.\n"
  printf "\n"
  printf "%s\n" "-A       test-alpha; configure, build and run test codes with"
  printf "                current alpha release.\n"
  printf "%s\n" "-a opt   All; (default)."
  printf "%s\n" "-B       test-beta; configure, build and run test codes with"
  printf "                current beta release.\n"
  printf "%s\n" "-b opt   Babel; configure --with-babel."
  printf "%s\n" "-c       C++; make all++."
  printf "%s\n" "-D       Turn on debug messages."
  printf "%s\n" "-d       Docs; make the documentation directory."
  printf "%s\n" "-E       configure, build and run example codes.\n"
  printf "%s\n" "-e opt   Debug; configure --enable-debug."
  printf "%s\n" "-f       F77; make all77."
  printf "%s\n" "-h       Help; display this help message."
  printf "%s\n" "-i opt   Insure++; perform configure --with-insure. Output"
  printf "                is appended to a file called insure.log.\n"
  printf "%s\n" "-m       Mail; mail error summary to developers."
  printf "%s\n" "-n       NoMPI; configure --without-MPI."
  printf "%s\n" "-o opt   openMP; configure --with-openmp."
  printf "%s\n" "-r host  Remote; remote exection is performed on "host"."
  printf "%s\n" "-s       Strict; configure --with-strict-checking."
  printf "%s\n" "-v text  Additional text to prefix to email subject line."
}

#=============================================================================
# Function for mailing error messages
#=============================================================================
mail_summary () 
{
  echo "Autotest mailing error summary"

  HYPRE_DEFAULT_EMAIL="rfalgout@llnl.gov"
  HYPRE_ALL_EMAIL="rfalgout@llnl.gov\
                   abaker@llnl.gov\
                   painter1@llnl.gov\
                   lee123@llnl.gov\
                   kolev1@llnl.gov\
                   yang11@llnl.gov\
                   chtong@llnl.gov\
                   vhenson@llnl.gov"

#
# Define mail program to be used
   if [ "$HYPRE_ARCH" = "linux" ] ; then
      [ -x /usr/bin/Mail ] && HYPRE_MAIL=/usr/bin/Mail
      [ -x /usr/bin/mhmail ] && HYPRE_MAIL=/usr/bin/mhmail
   else
      [ -x /usr/bin/Mail ] && HYPRE_MAIL=/usr/bin/Mail
      [ -x /usr/bin/mailx ] && HYPRE_MAIL=/usr/bin/mailx
      [ -x /usr/sbin/mailx ] && HYPRE_MAIL=/usr/sbin/mailx
   fi
#
#               mail summaries
  if [ "$AutotestFailureCount" = "0" ] ; then
    SUBJECT="Autotest NO Errors"
  else
    SUBJECT="Autotest $AutotestFailureCount Errors"
  fi

  if [ -n "${HYPRE_MESSAGE}" ] ; then
    SUBJECT="$HYPRE_MESSAGE $SUBJECT"
  fi

  if [ "$DEBUG_MODE" = "yes" ] ; then
     ${HYPRE_MAIL} -s "$SUBJECT" $HYPRE_DEFAULT_EMAIL < $SUMFILE 
  else
     ${HYPRE_MAIL} -s "$SUBJECT" $HYPRE_ALL_EMAIL < $SUMFILE 
  fi
  echo "Autotest mail sent"
}


#=============================================================================
# Functions for filtering misleading error messages
#    Removes specified messages from error files that do not reflect actual
#    errors
#=============================================================================
process_filter ()
{
  ErrorFile=$1
  shift
  if (egrep "$@" $ErrorFile >/dev/null) ; then
     mv $ErrorFile $ErrorFile.tmp
     egrep -v "$@" $ErrorFile.tmp > $ErrorFile
     echo "-- applied filter:$@" >> $ErrorFile.orig
     cat $ErrorFile.tmp >> $ErrorFile.orig
  fi
}


apply_error_filters ()
{
  ErrorFile=$1
  if [ -s "${ErrorFile}" ] ; then
    HOST=`hostname`
    case $HOST in
      up*)
        for ii in \
          '===\ End\ of\ Compilation'\
          'cpu\ clock'\
          'wall\ clock'\
          'Compilation\ successful'\
          '^\ Guide\ \ \ '\
          ':\ 0\ errors\ in\ file'\
          'autoconf\ has\ been\ disabled'\
          'automake\ has\ been\ disabled'\
          'autoheader\ has\ been\ disabled'\
          'ltdl.c:'\
          'sidl'\
          '1501-050:\ \(I\)'\
          '1500-010:\ \(W\)'\
          'babel_config.h.in:\ No\ such\ file\ or\ directory'\
          'configure:\ WARNING:\ '
        do process_filter $ErrorFile "${ii}"
        done
        ;;
      alc* | mcr* | peng*)
        for ii in \
          '[A-Za-z0-9_]*\.[cCf]$'\
          '[A-Za-z0-9_]*\.cxx$'\
          '^[ \t]*$'\
          '^[0-9]*\ Lines\ Compiled$'\
          'autoconf\ has\ been\ disabled'\
          'automake\ has\ been\ disabled'\
          'autoheader\ has\ been\ disabled'\
          'ltdl.c:'\
          'sidl'\
          'cpu\ clock'\
          'wall\ clock'\
          'queued'\
          'allocated'\
          '\ remark:\ '
        do process_filter $ErrorFile "${ii}"
        done
        ;;
      *bgl*)
        for ii in \
          'readonly\ variable'\
          'BE_MPI'\
          'FE_MPI\ '
        do process_filter $ErrorFile "${ii}"
        done
        ;;
      thun*)
        for ii in \
          'queued'\
          'allocated'
        do process_filter $ErrorFile "${ii}"
        done
        ;;
      tux*)
        for ii in \
          'autoconf\ has\ been\ disabled'\
          'automake\ has\ been\ disabled'\
          'autoheader\ has\ been\ disabled'\
          'configure:\ WARNING:\ Configuration\ for'\
          'configure:\ WARNING:\ Skipping\ Java'\
          'cpu\ clock'\
          'wall\ clock'\
          'Error:\ PDF'\
          'babel_config.h.in:\ No\ such\ file\ or\ directory'\
          '../../../babel/runtime'\
          'ltdl.c:'\
          'sidl'\
          'Insure\ messages\ will\ be\ written\ to'\
          'Timeout\ in\ waiting\ for\ processes\ to'\
          'rsh\ program'\
          'problem'\
          'This\ is\ not\ a\ problem'\
          'environment'\
          'process\ termination'\
          'TCA\ log\ data\ will\ be\ merged\ with\ tca'\
          'PGC/x86\ Linux/x86\ 3.3-1:\ compilation\ completed\ with\ warnings'\
          'sed:\ Couldn.t\ close\ '
        do process_filter $ErrorFile "${ii}"
        done
        ;;
    esac
  fi
}



#=============================================================================
# Function for creating error message summary file
#=============================================================================
create_summary_files () 
{
  echo "Autotest creating error summary file"
  CTOTCNT=0
  CLOGCNT=0
  CERRCNT=0
  AutotestFailureCount=0
  CLIST=""; ELIST=""
  DWRNCNT=0; DERRCNT=0
  cd $HYPRE_REMOTE_DIR
  SUMFILE="autotest.$HYPRE_ARCH.`date '+%Y%m%d'`.html"

  if [ -z "$HYPRE_COMPILE_MACHINE" -o "$HYPRE_COMPILE_MACHINE" = "" ] ; then
     HYPRE_COMPILE_MACHINE=`hostname`
  fi

  printf "<html>\n" > $SUMFILE
  printf "<head></head>\n" >> $SUMFILE
  printf "<PRE>\n" >> $SUMFILE
  printf "<body>\n" >> $SUMFILE
  printf "%s<br>\n" "--------------------------------------------" >> $SUMFILE
  printf "Autotest error summary for `date`<br>\n" >> $SUMFILE
  printf "Target architecure: %s<br>\n" $HYPRE_ARCH >> $SUMFILE
  printf "Compile machine:    %s<br>\n" $HYPRE_COMPILE_MACHINE >> $SUMFILE
  printf "Execute machine:    %s<br>\n" $HYPRE_RUN_MACHINE  >> $SUMFILE
  printf "Operating system:   `uname -a`<br>\n" >> $SUMFILE
  printf "Directory:          %s<br>\n" $HYPRE_REMOTE_DIR >> $SUMFILE
  printf "%s<br>\n" "--------------------------------------------" >> $SUMFILE
  printf "Compile summary: Status: Warnings: Errors<br>\n" >> $SUMFILE
#
#               check all configure options
  for ConfOpt in ${STD_CONFIGOPTIONS}
  do
     printf "%-15s: " $ConfOpt >> $SUMFILE
     TestCaseSuccessCount=0; TestCaseFailedCount=0;
     DWRNCNT=0; DERRCNT=0;
#
#               check all make options
     for MakeOpt in ${STD_MAKEOPTIONS}
     do
        FILE=autotest.$ConfOpt.$MakeOpt
        EFILE=`echo $FILE`.err
        for i in $EFILE ${SRC}/${EFILE} \
                 ${SRC}/docs/${EFILE} ${SRC}/test/${EFILE} 
        do
           if [ -r "${i}" ] ; then
              CTOTCNT=`expr $CTOTCNT + 1`
              apply_error_filters ${i}
              if [ -s "${i}" ] ; then
                 errinfo="<a href=\""${HYPRE_REMOTE_DIR}/${i}"\">"${EFILE}"</a><br>"
                 AutotestFailureCount=`expr $AutotestFailureCount + 1`
                 CERRCNT=`expr $CERRCNT + 1`
                 TestCaseFailedCount=`expr $TestCaseFailedCount + 1`
                 CLIST="${CLIST}${errinfo}\n"
                 DWRNNUM=0; DERRNUM=0;
                 DWRNNUM=`grep -i warning ${i}|wc -l`
                 DERRNUM=`grep -i error ${i}|wc -l`
                 DWRNCNT=`expr $DWRNCNT + $DWRNNUM`
                 DERRCNT=`expr $DERRCNT + $DERRNUM`
              else
                 CLOGCNT=`expr $CLOGCNT + 1`
                 TestCaseSuccessCount=`expr $TestCaseSuccessCount + 1`
              fi
           fi
        done
     done
#               end of MakeOpt loop
     if [ "$TestCaseFailedCount" != "0" ] ; then
        printf "Failed:    %2d   :   %2d<br>\n" $DWRNCNT $DERRCNT >> $SUMFILE
     elif [ "$TestCaseSuccessCount" != "0" ] ; then
        printf "Passed<br>\n" >> $SUMFILE
     else
        printf "N/A<br>\n" >> $SUMFILE
     fi
  done
#               end of ConfOpt loop

  if [ "$DEBUG_MODE" = "yes" ] ; then
     printf "%2d test failed<br>\n" $CERRCNT
     printf "%2d test succeeded<br>\n" $CLOGCNT
     printf "%2d test total<br>\n" $CTOTCNT
  fi

  printf "<br>\n" >> $SUMFILE
  printf "%2d test failed<br>\n" $CERRCNT  >> $SUMFILE
  printf "%2d test succeeded<br>\n" $CLOGCNT >> $SUMFILE
  printf "%2d test total<br>\n" $CTOTCNT >> $SUMFILE
  printf "<br>\n" >> $SUMFILE

  if [ "$CLIST" != "" ] ; then
     printf "non zero error log file(s):<br>\n" >> $SUMFILE
     printf "${CLIST}" >> $SUMFILE
  fi
  printf "%s<br>\n" "--------------------------------------------" >> $SUMFILE
#
#   check all test execution output files for errors
#   currently only the last test run with opt=2 (configure, make, and run)
#   is processed as earlier information gets overwritten.

  printf "\nExecute summary:<br>\n" >> $SUMFILE
  TotalTestCount=0
  TotalSuccessCount=0
  TotalFailureCount=0
#
#               check each TEST_* directory
  for i in ${TEST_DIRS} 
  do
     printf "%-15s: " ${i} >> $SUMFILE
     TestCaseSuccessCount=0; TestCaseFailedCount=0; TestCaseFailedFlag=0
#
#               check each test case in the given directory
#               define error file name
#               remove non-essential information from file
#               increment error counts if resulting file has non-zero length
     for j in ${SRC}/test/TEST_${i}/*.sh
     do
        TotalTestCount=`expr $TotalTestCount + 1`
        TestCaseFailedFlag=0
        ErrFile=`echo $j | sed -e 's/\.sh$/.err/'`
        for k in "${ErrFile}.[0-9]+"; do
           apply_error_filters ${k}
           if [ -s "${k}" ] ; then
              if [ "$DEBUG_MODE" = "yes" ] ; then
                 printf "nonzero .err file = ${ErrFile}\n"
              fi
              errinfo="<a href=\""${HYPRE_REMOTE_DIR}/${k}"\">"${k}"</a><br>"
              AutotestFailureCount=`expr $AutotestFailureCount + 1`
              TotalFailureCount=`expr $TotalFailureCount + 1`
              TestCaseFailedCount=`expr $TestCaseFailedCount + 1`
              ELIST="${ELIST}${errinfo}\n"
              TestCaseFailedFlag=1
              break
            fi
        done
#               end of k-loop
#
#               check for non-zero error file without numerical suffix; which
#               typically contains errors from insure runs
        apply_error_filters ${ErrFile}
        if [ -s "${ErrFile}" ] ; then
           if [ "$DEBUG_MODE" = "yes" ] ; then
              printf "nonzero .err file = ${ErrFile}\n"
           fi
           errinfo="<a href=\""${HYPRE_REMOTE_DIR}/${ErrFile}"\">"${ErrFile}"</a><br>"
           AutotestFailureCount=`expr $AutotestFailureCount + 1`
           TotalFailureCount=`expr $TotalFailureCount + 1`
           TestCaseFailedCount=`expr $TestCaseFailedCount + 1`
           ELIST="${ELIST}${errinfo}\n"
           TestCaseFailedFlag=1
        fi

        if [ "$TestCaseFailedFlag" = "0" ] ; then
           TotalSuccessCount=`expr $TotalSuccessCount + 1`
           TestCaseSuccessCount=`expr $TestCaseSuccessCount + 1`
        fi
     done
#               end of j-loop
#
#               print execution success/fail numbers for given directory
     if [ "$TestCaseFailedCount" != "0" ] ; then
        printf "Passed:    %2d  Failed:   %2d<br>\n" $TestCaseSuccessCount $TestCaseFailedCount >> $SUMFILE
     elif [ "$TestCaseSuccessCount" != "0" ] ; then
        printf "Passed:    %2d<br>\n" $TestCaseSuccessCount >> $SUMFILE
     else
        printf "N/A<br>\n" >> $SUMFILE
     fi
  done
#               end of i-loop
  if [ "$DEBUG_MODE" = "yes" ] ; then
     printf "%2d test failed<br>\n" $TotalFailureCount
     printf "%2d test succeeded<br>\n" $TotalSuccessCount
     printf "%2d test total<br>\n" $TotalTestCount
  fi
#
#              print summary success/fail numbers and list of non-zero
#              error files, if any exist
  printf "\n" >> $SUMFILE
  printf "%2d test failed<br>\n" $TotalFailureCount >> $SUMFILE
  printf "%2d test succeeded<br>\n" $TotalSuccessCount >> $SUMFILE
  printf "%2d test total<br>\n" $TotalTestCount >> $SUMFILE

  if [ "$ELIST" != "" ] ; then
     printf "non zero error log file(s):<br>\n" >> $SUMFILE
     printf "${ELIST}" >> $SUMFILE
  fi

  printf "%s<br>\n" "--------------------------------------------" >> $SUMFILE
  printf "</body>\n" >> $SUMFILE
  printf "</PRE>\n" >> $SUMFILE
  printf "</html>\n" >> $SUMFILE

  chgrp hypre $SUMFILE
}


cleanup () { 
  umask $OldMask
  seconds; TOTAL=`expr $SECS - $TOTAL`
  echo "Autotest finished leaving $* after $TOTAL seconds"
}


#=============================================================================
# General purpose function for configure, make and execute
#=============================================================================

confbuildtest () 
{
   TestOpt=$1  ConfigOpt=$2  MakeOpt=$3  MakeDir=$4  MessageStr=$5

#
# Configure Section
   seconds; TIME=$SECS
   echo "Autotest starting configure of $MessageStr"

   cd $StdBuildDir
   [ -f config.status ] && rm config.status

   if [ "$ConfigOpt" = " " ]
   then
      $CONFIGURE 1> ${Hdr}.${MessageStr}.configure.log \
                 2> ${Hdr}.${MessageStr}.configure.err
   else
      $CONFIGURE "$ConfigOpt" 1> ${Hdr}.${MessageStr}.configure.log \
                              2> ${Hdr}.${MessageStr}.configure.err
   fi

#
# Make Section
# Remove all *.o files before building for current options unless testing
# public versions
   if [ "${MessageStr}" != "test_alpha" -a "${MessageStr}" != "test_beta"  -a \
        "${MessageStr}" != "test_general" ]
   then
      echo "Autotest starting make of $MessageStr"
      if [ "${MakeDir}" != "" -a "${MakeDir}" != " " ]
      then
         cd $MakeDir
      fi
      $MAKE clean
      $MAKE ${MakeOpt} 1>> ${Hdr}.${MessageStr}.all.log \
                       2>> ${Hdr}.${MessageStr}.all.err
   fi

#
# Run Section
#    If the run option is set; cd to the test sub-directory; build the driver codes
#    then execute the test cases on the specified platform
   if [ ${TestOpt} -eq $Run ]
   then
      echo "Autotest starting execution of $MessageStr"
      cd $StdTestDir

      if [ "${HYPRE_RUN_MACHINE}" = "" -o "${HYPRE_RUN_MACHINE}" = " " ]
      then
         HYPRE_RUN_MACHINE=$HOSTNAME
      fi
#
#               if examples/ex1 is executable then examples codes are being 
#               tested and other test cases do not have to be built
      if [ -x ${StdBuildDir}/examples/ex1 ] 
      then
         STD_TEST_CASES="${EXAMPLES_TEST_CASES}"
      else
         STD_TEST_CASES="${TEST_CASES}"
         $MAKE all 1>> ${Hdr}.${MessageStr}.all.log \
                   2>> ${Hdr}.${MessageStr}.all.err
      fi

      if [ "${HYPRE_RUN_MACHINE}" = "tux136" ]
      then
         if [ "$DEBUG_MODE" = "yes" ]
         then
            ./runtest.sh -trace $HYPRE_RUNTEST_OPTS $STD_TEST_CASES
         else
            ./runtest.sh $HYPRE_RUNTEST_OPTS $STD_TEST_CASES
         fi
      else
         ssh ${HYPRE_RUN_MACHINE} "\
         (\
          cd $StdTestDir;\
          [ -r ./AUTOTEST/env.${HYPRE_ARCH} ] && . ./AUTOTEST/env.${HYPRE_ARCH};\
          ./runtest.sh $HYPRE_RUNTEST_OPTS $STD_TEST_CASES \
         )"
      fi
   fi
   seconds; TIME=`expr $SECS - $TIME`
   echo "Autotest finished $MessageStr taking $TIME seconds"
}


#==============================================================================
# return the seconds since midnight in the variable SECS
#==============================================================================
seconds ()
{
   HOUR=`date '+%H'`
   HOUR=`expr $HOUR \* 3600`
   MINS=`date '+%M'`
   MINS=`expr $MINS \* 60`
   SECS=`date '+%S'`
   SECS=`expr $SECS + $MINS`
   SECS=`expr $SECS + $HOUR`
}


#==============================================================================
# This script is the implementation script used to regression test hypre.
#==============================================================================
initialize_variables
parse_arguments $*
create_summary_files
if [ "$HYPRE_SEND_MAIL" = "yes" ]
then
   mail_summary
fi
cleanup $*
