#! /bin/sh

# May 17, 2007

# Portions of the script which must be customized are marked with "!!",
# below.

# The complete list of tests must be placed in "alltests", !!4, below.
# The test[s] for the SHORTTEST must be placed in "shortlist", !!5 below.

# pyregion.t (this file)
# driver script (unix sh) for myglue package testing

# test.py (external file)
# Python testing script to be activated by the driver above
#

# syntax:
# pyregion.t [<testid> ... ]

# interface between python and unix-sh (this file) is done through
# "export INFILE" and  "export OUTFILE", see !!6, !!7, !!8

# Test suite activation may be made through  setting and exporting
# INFILE, see !!7, !!8

# Developer's comments:
# Limited to ascii file output at the time being

######################################################################
# Initialization

# !!3
gluename="pyregion"

# set up list of tests
# !!4
alltests="test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 \
test11 test12 test13 test14 test15 test16 test17 test18 test19 test20 \
test21 test22 test23 test24 test25 test26 test27 test28 test29 test30 \
test31 test32 test33 test34 test35 test36 test37 test38 test39 test40 \
test41 test42 test43 test44 test45 test46 test47 test48 test49 test50 \
test51 test52 test53 test54 test55 test56 test57 test58 test59 test60 \
test61 test62"

# "short" test to run
# !!5
shortlist="test5 test26 test35 test36 test37 test38 test39"


# compute date string for log file
DT=`date +'%d%b%Y_%T'`


# convenience definitions
OUTDIR=$TESTOUT/$gluename
SAVDIR=$TESTSAV/$gluename
INDIR=$TESTIN/$gluename
LOGDIR=$TESTLOG/$gluename
THISDIR=`dirname $0`

# set up log file name
LOGFILE=$LOGDIR/${gluename}_log.$DT

#get rid of old logs
rm -f $LOGDIR/${gluename}_log.*

# Any tests specified on command line?
if test $# -gt 0; then
# yes, do those tests
testlist=$*
else
# No, see if we are to do "short" test
if test "x$SHORTTEST" = "x" ; then
# No, do everything
testlist=$alltests
else
# yes, do short test
testlist=$shortlist
fi
fi

# Make sure we have a log directory
if test -d $LOGDIR ; then
:
else
mkdir -p $LOGDIR
if test $? -ne 0 ; then
error_exit ""
fi
fi


# Make sure we have an output directory
if test -d $OUTDIR ; then
:
else
mkdir -p $OUTDIR >> $LOGFILE 2>&1
if test $? -ne 0 ; then
error_exit "can't create output directory $OUTDIR"
fi
fi

# check for directory environment variables
if test "x${TESTIN}" = "x" -o "x${TESTOUT}" = "x" -o "x${TESTSAV}" = "x" \
-o "x${TESTLOG}" = "x" ; then
error_exit "one or more of TESTIN/TESTOUT/TESTSAV/TESTLOG not defined"
fi

# announce ourselves
echo ""
echo "${gluename} regression" | tee $LOGFILE
echo ""

script_succeeded=0

######################################################################
# Begin per-test loop

for testid in $testlist
do

# delete old outputs
rm -f $OUTDIR/${testid}*


# Set up file names
outfile=$OUTDIR/${testid}.txt
savfile=$SAVDIR/${testid}.txt


# !!6
# export OUTFILE, INFILEs etc. as environmental variables
# which will be grabbed by python package called below
#
#
OUTFILE=$outfile;
export OUTFILE;
export INDIR;

echo "running $testid" >> $LOGFILE

####################################################################
# run the tool
case ${testid} in

test1) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test2) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test3) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test4) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test5) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test6) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test7) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test8) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test9) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test10) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test11) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test12) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test13) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test14) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test15) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test16) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test17) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test18) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test19) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test20) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test21) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test22) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test23) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test24) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test25) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test26) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test27) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test28) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test29) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test30) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test31) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test32) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test33) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test34) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test35) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test36) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test37) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test38) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test39) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
  TESTID=${testid};
  export TESTID;
  echo $command_str  | tee -a $LOGFILE
  eval $command_str  | tee -a $LOGFILE  2>&1
         ;;
test40) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test41) command_str="${THISDIR}/${gluename}/test.py &> /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test42) command_str="${THISDIR}/${gluename}/test.py &> /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test43) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test44) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test45) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test46) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test47) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test48) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test49) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
            ;;
test50) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test51) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test52) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test53) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test54) command_str="${THISDIR}/${gluename}/test.py &> /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test55) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test56) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test57) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test58) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test59) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test60) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
             ;;
test61) command_str="${THISDIR}/${gluename}/test.py > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
            ;;
test62) command_str="${THISDIR}/${gluename}/test.py 2> /dev/null  > /dev/null"
      TESTID=${testid};
      export TESTID;
      echo $command_str  | tee -a $LOGFILE
      eval $command_str  | tee -a $LOGFILE  2>&1
            ;;
   esac




  ####################################################################
  # check the outputs

  # Init per-test error flag
  mismatch=1

  # if different tests need different kinds of comparisons, use a
  #  case ${testid} in...  here

  ######################################################################
  # ascii files
  #
   diff $OUTDIR/${testid}.txt $SAVDIR/${testid}.txt_std >/dev/null 2>>$LOGFILE
   if  test $? -ne 0 ; then
     echo "ERROR: TEXT MISMATCH in $OUTDIR/${testid}.txt" >> $LOGFILE
     mismatch=0
   fi

  ####################################################################
  # Did we get an error?
  if test $mismatch -eq 0 ; then
    # Yes
    echo "${testid} NOT-OK"
    script_succeeded=1
  else
    # No
    echo "${testid} OK"
  fi

done
# end pre-test loop
######################################################################


######################################################################
# report results

# blank line
echo ""

if test $script_succeeded -eq 0; then
    echo "${gluename} : PASS" | tee -a $LOGFILE
else
    echo "${gluename} : FAIL" | tee -a $LOGFILE
fi

echo "log file in ${LOGFILE}"

exit $script_succeeded
