#! /usr/bin/ksh
#CheckUTBld - execute the unit test cases

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 code to be tested. (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/BuildAllut.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
  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/BuildAllut.Complete
     then
        ((i+=wait))
     else
        sleep 300
     fi
  done
  if test -f $PDDIR/utils/BuildAllut.Complete
  then
      echo "Flag file exists"
      wall "Starting the unit test cases for: " $PDDIR
      rm $PDDIR/utils/BuildAllut.Complete
  else
      echo "Flag file does NOT EXIST"
     exit
  fi
fi

(
date
maxutrc=0
if klist
then
    echo "you are logged into DCE"
else
    echo "... You are NOT logged into DCE  ... "
    dce_login cell_admin pass
fi

df .
echo "ͻ"
echo "                                                "
echo "     Executing the Palladium unit test cases    "
echo "                                                "
echo "ͼ"

export PATH=$PDDIR/bin:$PDDIR/utils:$PATH
export NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/prime/%N

export PDBASE=$PDDIR/unittest
rm -rf $PDBASE
mkdir $PDBASE
mkdir $PDBASE/oids
cd $PDBASE/oids
ln -s /pd_dev/oids/*.db .
cd $PDBASE
echo "PDBASE = $PDBASE"
echo "------------------------------------------------------------------------"
echo "*** Test alarm_u "
$PDDIR/bin/alarm_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "alarm_u success               rc: " $rc
else
  print "alarm_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
echo "*** Test as_u "
$PDDIR/bin/as_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "as_u success                  rc: " $rc
else
  print "as_u error                    rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asas_u "
$PDDIR/bin/asas_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asas_u success                rc: " $rc
else
  print "asas_u error                  rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asatt_u "
$PDDIR/bin/asatt_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asatt_u success               rc: " $rc
else
  print "asatt_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asvbjs_u "
$PDDIR/bin/asvbjs_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asvbjs_u success               rc: " $rc
else
  print "asvbjs_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asmars_u "
$PDDIR/bin/asmars_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asmars_u success              rc: " $rc
else
  print "asmars_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asvnum_u"
$PDDIR/bin/asvnum_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asvnum_u success              rc: " $rc
else
  print "asvnum_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asvoid_u "
$PDDIR/bin/asvoid_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asvoid_u success              rc: " $rc
else
  print "asvoid_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asvoth_u "
$PDDIR/bin/asvoth_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asvoth_u success              rc: " $rc
else
  print "asvoth_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test asvstr_u "
$PDDIR/bin/asvstr_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "asvstr_u success              rc: " $rc
else
  print "asvstr_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test gettim_u "
$PDDIR/bin/gettim_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "gettim_u success              rc: " $rc
else
  print "gettim_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test msg_u "
$PDDIR/bin/msg_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "msg_u success                 rc: " $rc
else
  print "msg_u error                   rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test msigc_u "
$PDDIR/bin/msigc_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "msigc_u success               rc: " $rc
else
  print "msigc_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test notifs_u "
dce_login cell_admin pass -e $PDDIR/bin/notifs_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "notifs_u success               rc: " $rc
else
  print "notifs_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test notifv_u "
dce_login cell_admin pass -e $PDDIR/bin/notifv_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "notifv_u success               rc: " $rc
else
  print "notifv_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test sc_u  "
$PDDIR/bin/sc_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "sc_u success                  rc: " $rc
else
  print "sc_u error                    rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test str_u "
$PDDIR/bin/str_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "str_u success                 rc: " $rc
else
  print "str_u error                   rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test iostr_u "
$PDDIR/bin/iostr_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "iostr_u success               rc: " $rc
else
  print "iostr_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
cp $PDDIR/src/eh/syslog.cfg $PDDIR/unittest/syslog.cfg
echo "*** Test syslog_u "
$PDDIR/bin/syslog_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "syslog_u success              rc: " $rc
else
  print "syslog_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test thread_u "
$PDDIR/bin/thread_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "thread_u success              rc: " $rc
else
  print "thread_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test time_u "
$PDDIR/bin/time_u  10/22/93 17:00:00
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "time_u success                rc: " $rc
else
  print "time_u error                  rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test trc_u "
cp $PDDIR/src/common/trace.cfg $PDDIR/unittest/trace.cfg
$PDDIR/bin/trc_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "trc_u success                 rc: " $rc
else
  print "trc_u error                   rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test trc2_u "
$PDDIR/bin/trc2_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "trc2_u success                rc: " $rc
else
  print "trc2_u error                  rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test trcmul_u "
$PDDIR/bin/trcmul_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "trcmul_u success              rc: " $rc
else
  print "trcmul_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test trcprf_u "
$PDDIR/bin/trcprf_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "trcprf_u success              rc: " $rc
else
  print "trcprf_u error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test trcthr_u "
$PDDIR/bin/trcthr_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "trcthr_u success              rc: " $rc
else
  print "trcthr_u error                rc: " $rc
fi

#######################################################################
# The following if/fi statement contains existing UTs which do not
# currently work.  As they are fixed, move them above this if/fi so
# that they'll get executed after builds.
#######################################################################
if [[ 0 -eq 1 ]] ; then

echo "------------------------------------------------------------------------"
#
echo "*** Remove JeanLucPicard from name space."
echo "*** This should already have been done from previous run."
echo "*** Ignore any errors from cdscp delete object"
cdscp delete object /.:/subsys/pd/servers/spooler/JeanLucPicard
echo "*** Start DPO server_u and wait for it to get ready"
server_u JeanLucPicard&
sleep 60
echo "*** Test DPO client_u -- server and client output will be mixed "
$PDDIR/bin/client_u JeanLucPicard
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "client_u success              rc: " $rc
else
  print "client_u error                rc: " $rc
fi
#
echo "------------------------------------------------------------------------"
#
echo "*** Test dir_u    "
dce_login cell_admin pass -e $PDDIR/bin/dir_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "dir_u    success              rc: " $rc
else
  print "dir_u    error                rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test ocont_u "
$PDDIR/bin/ocont_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "ocont_u success               rc: " $rc
else
  print "ocont_u error                 rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test oid_u "
$PDDIR/bin/oid_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "oid_u success                 rc: " $rc
else
  print "oid_u error                   rc: " $rc
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test pdloc_u"
$PDDIR/bin/pdloc_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pdloc_u   success              rc: " $rc
else
  print "pdloc_u error                  rc: " $rc            "must run on arcturus for successful result"
fi
echo "------------------------------------------------------------------------"
#
echo "*** Test trcsev_u "
$PDDIR/bin/trcsev_u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "trcsev_u success              rc: " $rc
else
  print "trcsev_u error                rc: " $rc
fi

echo "------------------------------------------------------------------------"
#
echo "*** run the test PDB code"
echo "*************************** Running ObjectReference test"
$PDDIR/bin/pb_u o
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pb_u o   success              rc: " $rc
else
  print "pb_u o   error                rc: " $rc
fi

echo "*************************** Running UsageLock test"
$PDDIR/bin/pb_u u
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pb_u u   success              rc: " $rc
else
  print "pb_u u   error                rc: " $rc
fi

echo "*************************** Running save test"
$PDDIR/bin/pb_u s
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pb_u s   success              rc: " $rc
else
  print "pb_u s   error                rc: " $rc
fi

echo "*************************** Running restore test"
$PDDIR/bin/pb_u r
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pb_u r   success              rc: " $rc
else
  print "pb_u r   error                rc: " $rc
fi

echo "*************************** Running mem mgmt test"
$PDDIR/bin/pb_u m
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pb_u m   success              rc: " $rc
else
  print "pb_u m   error                rc: " $rc
fi

echo "*************************** Running Supervisor save test"
$PDDIR/bin/pbsuv_u S
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pbsuv_u S   success              rc: " $rc
else
  print "pbsuv_u S   error                rc: " $rc
fi

echo "*************************** Running Supervisor restore test"
$PDDIR/bin/pbsuv_u R
rc=$?
if [[ $rc > $maxutrc ]] then maxutrc=$rc ; fi;
if [[ $rc = 0 ]] then
  print "pbsuv_u R   success              rc: " $rc
else
  print "pbsuv_u R   error                rc: " $rc
fi

fi
################# end currently broken UTs ############################

echo "------------------------------------------------------------------------"

echo ""
echo "ͻ"
echo "                                                "
echo "       Palladium unit test case Complete        "
echo "   Maximum Return Code:  $maxutrc                     "
echo "                                                "
echo "                                                "
echo "ͼ"

df .
date
) 2>&1 | tee $PDDIR/utils/CheckUTBld.out


if [[ $NOTIFY = "yes" ]]
then
   rm $PDDIR/utils/utstat.out
   DATE=`date`
   grep 'rc:' $PDDIR/utils/CheckUTBld.out > $PDDIR/utils/utstat.out
   msg="Unit Test Results - Dir:$PDDIR  Date:$DATE"
   $PDDIR/utils/NotifyDev "$msg"  $PDDIR/utils/utstat.out
fi


exit
#
#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ----------------------------
# V1.2          01/17/94 05:03:54 bilan    changed ...out file name
# V1.3          01/19/94 17:18:20 nrbschwa Changed name of pb_u unittest for options S and R.
# V1.4          01/26/94 16:32:34 bilan    Fixed logic for wait file - exit if not found
# V1.5          01/27/94 09:15:09 nrbschwa Modified path to include utils directory.
# V1.6          02/02/94 08:39:20 bilan    eliminated PD_OIDS_PATH - added PD_DIR
# V1.7          03/03/94 15:32:42 jsewell  Added notif_u testcase
# V1.8          03/04/94 08:58:42 jsewell  Environment variable chgs
# V1.8.1.1      03/15/94 08:52:39 jsewell  notif_u invocation change
# V1.8.1.2      04/01/94 09:49:30 hlava    Added msigw_u
# V1.8.1.3      04/04/94 07:03:06 hlava    Renamed class
# V1.8.1.4      04/17/94 14:29:45 sandra   Fixed run of notification UTs...
# V1.8.1.5      04/18/94 09:40:01 nrbschwa Added asvbjs_u test.
# V1.8.1.6      04/25/94 08:59:54 nrbschwa Corrected name of test file.
# V1.8.1.7      06/06/94 13:30:48 hlava    Added iostr_u
# V1.8.1.8      07/22/94 15:05:24 dennison Add DPO UT to nightly build
# V1.8.1.9      08/04/94 08:58:42 dennison delete JeanLucPicard from name space before starting server_u
# V1.8.1.10     02/22/95 12:45:32 hlava    Misc UT fixes
# V1.8.1.11     03/02/95 05:51:34 hlava    Added setting of PDBASE before start
# V1.8.1.12     03/06/95 06:40:04 hlava    Fix to set up oids directory
# V1.8.1.13     03/06/95 11:42:34 hlava    Fixed alarm_u
# V1.8.1.14     03/06/95 12:31:04 hlava    Fixed msgic_u
