#!/usr/bin/ksh
#CheckIUT     - execute the integrated unit tests

Usage="Usage: $0 dir-name notification wait-flag wait-time"
if test "$1" = "?"
then
  echo
  echo $Usage
  echo "   dir-name:"
  echo "         dir-name is the name of a Palladium root directory that"
  echo "         contains the source code to be built. (default:  /pd_dev)."
  echo
  echo "   notification:   should the developers be notified of the result"
  echo "                   - 'yes'"
  echo "                   - 'no'"
  echo "                  (default: no )"
  echo
  echo "   wait-flag"
  echo "         'yes' - indicates that this script should wait "
  echo "                 for the file: dir-name/utils/BuildAllexe.complete"
  echo "                 to exist before this script runs the test cases"
  echo "                 ( default no wait)"
  echo
  echo "   wait-time"
  echo "               - if wait-flag = 'yes'  this indicates the total"
  echo "                 time in minutes this script should wait for the the"
  echo "                 the file to exist"
  echo "                ( default 120 minutes)"
  echo
  echo " "
  exit 1
fi

if test "$1" = ""
then
  PDDIR=/pd_dev
else
  PDDIR=$1
fi

if [[ ( $2 = "yes") || ( $2 = "no" )  ]]
then
  NOTIFY=$2
else
  NOTIFY='no'
fi


if test "$3" = "yes"
then

   if test "$4" = ""
   then
     wttime=120
   else
     wttime=$4
   fi

  integer wait=`expr $4 / 5 `

  integer i=0
  while ((i < wait))
  do
     echo "Wait time:" $wttime  "Wait Count:" $i
     ((i+=1))

     if test -f $PDDIR/utils/BuildAllexe.Complete
     then
        ((i+=wait))
     else
        sleep 300
     fi
  done
  if test -f $PDDIR/utils/BuildAllexe.Complete
  then
      echo "Flag file exists"
      wall "Starting the integrated unit test scripts for: " $PDDIR
      rm $PDDIR/utils/BuildAllexe.Complete
  else
      echo "Flag file does NOT EXIST"
     exit
  fi
fi


cd $PDDIR/pdtest
rm $PDDIR/pdtest/ef:*
rm $PDDIR/pdtest/SUMM*
rm $PDDIR/pdtest/REG*

echo "Starting the integrated unit test scripts for: " $PDDIR  $PDREL
date
dce_login cell_admin pass -e $PDDIR/pdtest/run_all_iut
date


if [[ $NOTIFY = "yes" ]]
then
   DATE=`date`
   msg="IUT script Results - Dir:$PDDIR  Date:$DATE"
   $PDDIR/utils/NotifyDev "$msg"  $PDDIR/pdtest/REGRESS.LOG
fi

exit
#
#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ----------------------------
# V1.2          01/15/94 14:47:18 bilan    corrected #!/bin/ksh
# V1.3          01/17/94 05:03:25 bilan    removed utstat file reference
# V1.4          01/26/94 16:30:51 bilan    Fixed logic for wait file - exit if not found
