#! /usr/bin/ksh
############################################################################
# script name: runAlliut
#
# This script runs integrated unit tests.
#
# 1.    Set the environment variable TESTSCRIPTS to run scripts that
#               use the default environment (scripts with the .tc suffix).
#
# 2.    Set the environment variable TCTESTSCRIPTS to run scripts
#               without a default environment (scripts with the .TC suffix).
#               You should provide a script to initialize the spooler and
#               supervisor (e.g. setUpEnv.TC) as well as a script to tear
#               it down (tearDownEnv.TC).
#
# 3.    Use the command line to run tests.  These tests are run
#               as in item #2.
#
# For convenience, you can run item #1 and #2 tests using:
#
#               dce_login cell_admin pass -e /pd_dev/pdtest/runAlliut
#
###########################################################################
typeset bn=$( basename $0 )
# set up the environment for the integrated unit test cases
PD_DEV=${PD_DEV:=/pd_dev}        # version of executables to run
WORKDIR=${WORKDIR:=$PD_DEV/pdtest}     # where to create directory tree work
RESULTS_DIR=${RESULTS_DIR:=$WORKDIR/iutResults}
PREFIX=${PREFIX:=`hostname`-$LOGNAME-iut}  # prefix of the palladium objects created
LASTACCESSOR=${LASTACCESSOR:=`whoami`@`hostname`.bpc.boulder.ibm.com}
[ $(uname) = HP-UX ] && LASTACCESSOR=$(whoami)@`hostname`.cup.hp.com
PDCLIENTD=${PDCLIENTD:=false}    # recreate the pdcliend daemon
PD_CONFIRM_DELETE=${PD_CONFIRM_DELETE:=no}

if [ "$PD_TIMEOUT" = "" ]; then # HP,jbralley,21Sep95
     PD_TIMEOUT=
else PD_TIMEOUT=${PD_TIMEOUT:=160}
fi

integer socket=`id -u $LOGNAME` #HP: Unique socket per user even if root.
                                # Run this script by `.do RunIUT'. JJB,22Aug95.
for i in $TESTSCRIPTS; do
 if [[ "$i" = "enq_gateway.TC" ]]; then
 PD_SOCKET=`grep ^pdclient /etc/services| awk '{ print $2 }' | awk -F/ '{ print $1 }'`
 export PD_SOCKET
 echo " PD_SOCKET  is now set to $PD_SOCKET"
 fi
done



socket=socket+9000
PD_SOCKET=${PD_SOCKET:=$socket}

PATH=$PD_PATH:$PATH
# Ensure logs go to cerr also (required by some testcases)
export PD_SERVER_LOG_CERR=yes

export RESULTS_DIR
export PD_TIMEOUT LASTACCESSOR
export PD_DEV WORKDIR PREFIX PDCLIENTD TESTSCRIPTS PD_CONFIRM_DELETE PD_SOCKET PATH

for i in $TESTSCRIPTS; do
  printf "%-16s[%3d]: PD_SOCKET = %d\n" $bn $LINENO $PD_SOCKET

  TCTESTSCRIPTS=$TCTESTSCRIPTS"
  setUpBasicEnv.TC $i tearDownDefaultEnv.TC
	"
done

for i in $*; do
        TCTESTSCRIPTS=$TCTESTSCRIPTS" $i"
done

if [ "$TCTESTSCRIPTS" != "" ]; then
#----------------------------------------------------------------------------
# run integrated unit tests
#
TESTSCRIPTS=$TCTESTSCRIPTS
$RTPATH/bin/boxText "run integrated unit tests"
$RTPATH/bin/runIUTman
rc=$?

if [ $rc = 0 ]; then
     echo "All IUT tests completed with SUCCESS."
else echo "One or more IUT tests FAILED."
fi

#----------------------------------------------------------------------------
# kill client daemon
#
if [[ $PDCLIENTD = "false" ]]
then
        ENAME=`id -un`
    ps -fu$ENAME | grep $ClientDaemonName | grep $PD_SOCKET | awk '{ print $2 }' | xargs -n1 kill -9
    ps -ef | grep 'basicdsd' | grep -v grep | awk '{ print $2 }' | xargs -n1 kill -9
fi

unset PD_SOCKET
exit $rc

fi

exit 0

#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ------------------------------

# V1.2          07/20/94 13:52:22 nrjbehrs IUT fixes
# V1.3          07/21/94 17:23:39 nrjbehrs IUT cleanup
# V1.4          07/25/94 12:32:55 nrjbehrs IUT cleanup
# V1.5          07/26/94 11:01:46 nrjbehrs IUT cleanup
# V1.6          07/26/94 15:55:14 nrjbehrs IUT cleanup
# V1.7          07/28/94 16:11:18 nrjbehrs IUT cleanup
# V1.8          08/01/94 07:51:33 kok      update IUT
# V1.10         08/12/94 11:11:21 nrjbehrs restart pdclientd
# V1.11         08/15/94 15:00:33 nrjbehrs IUT cleanup
# V1.12         08/18/94 10:30:56 nrjbehrs IUT cleanup
# V1.13         08/30/94 16:41:24 nrjbehrs iut updates
# V1.14         09/19/94 14:42:06 kok      updated with PATH
# V1.15         09/21/94 06:22:39 hlava    Fixup PATH setting
# V1.16         09/21/94 11:53:45 hlava    Eliminate hardcoded output text
