#! /usr/bin/ksh
#
# Function runRegSeq: run a regression test sequence. The sequence of files
# are the input parameters of this function. Depending on the value of
# RTSTEPEXIT, continue or terminate if any individual regression test
# fails.
#
# Author: Tim Unser
# Modified 10/28/93 rhp:  Added RTPATH to input file of regTest.
# Modified 11/9/93  rhp:  Added output of errors and success to summary file.
# Modified 12/3/93  tju:  change ERRORFILE to ERRFILROOT and add
#                         dynamic error file name generation to
#                         prevent duplicate names. Also, delete
#                         error file if sequence runs to completion
#                         SUCCESSFULLY.
# return error if ERRFILROOT is not defined

typeset bn=$(basename $0)
printf "%-16s[%3d]: Enter runRegSeq\n" $bn $LINENO
step_rc=0
if [ "${ERRFILROOT}" = "" ]; then
    printf "%-16s[%3d]: ERRFILROOT is undefined\n" $bn $LINENO
    exit 10
fi

export ERRBASENAME=`basename $ERRFILROOT`
export i

for i in $*; do
    # output status of servers
    ps -t ? | grep $SPOOLER
    [[ $? = 0 ]] && printf "%-16s[%3d]: Cannot locate spooler process\n"\
                            $bn $LINENO | tee -a $SUMMARY
    ps -t ? | grep $SUPERVR
    [[ $? = 0 ]] && printf "%-16s[%3d]: Cannot locate supervisor process\n"\
                            $bn $LINENO | tee -a $SUMMARY
    cnt=`ps -e | grep psmd`
    [[ $cnt > 1 ]] && printf "%-16s[%3d]: Multiple client daemons found\n"\
                      $bn $LINENO | tee -a $SUMMARY
    # run regression test using argument as name of test
    echo
    echo
    echo
    $RTPATH/bin/boxText "Starting $i"
    echo $i | grep '.*\.sh' >/dev/null
    if [ $? = 0 ]; then
    (
        LOC_ERROR=0
        function expect_rc
        {
            rc=$?
            if [ $rc != $1 ]; then
                reportError "Expected return code $1 - got $rc"
                # mark that we had an error
                LOC_ERROR=1
                # we should return only if step exit = true
                if [ "${RTSTEPEXIT}" = "true" ]; then
                    exit $LOC_ERROR
                fi
            fi
        }
        #set -x
        printf "%-16s[%3d]: Executing: . $STEPPATH/$i\n" $bn $LINENO
        . $STEPPATH/$i
        exit $LOC_ERROR
    )
    else
        printf "%-16s[%3d]: regTest $STEPPATH/$i\n" $bn $LINENO
        regTest "$STEPPATH/$i"
    fi
    ret_code=$?
    # if it returned 0, skip next section
    if [ $ret_code != 0 ]; then
        # we have had an error
        step_rc=1
        echo "$i:\t rc: $ret_code" | tee -a $SUMMARY
        # depending on value of RTSTEPEXIT, we will exit or continue
        [ "${RTSTEPEXIT}" = "true" ] && exit 1
    else
        # successful regression test
        echo "$i: \t rc: 0" | tee -a $SUMMARY 
    fi
done
printf "%-16s[%3d]: Exit  runRegSeq\n" $bn $LINENO
exit $step_rc 
#
#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ----------------------------
# V             03/03/94 16:50:44 longstaf New
# V1.1.1.2      06/29/94 10:47:42 nrjbehrs made regTest read cmd work
# V1.1.1.4      07/05/94 09:53:37 nrjbehrs changed logging
# V1.1.1.5      07/19/94 10:35:30 kok      update for IUT return codes
# V1.1.1.6      07/19/94 14:32:29 nrjbehrs IUT fixes
# V1.1.1.7      07/20/94 12:31:01 nrjbehrs IUT fixes
# V1.1.1.8      07/20/94 13:52:17 nrjbehrs IUT fixes
# V1.1.1.9      07/20/94 14:52:57 nrjbehrs bogus->nrjbehrs
# V1.1.1.10     07/21/94 17:23:35 nrjbehrs IUT cleanup
# V1.1.1.12     07/26/94 13:51:47 nrjbehrs IUT cleanup
# V1.1.1.13     07/29/94 12:49:03 nrjbehrs IUT cleanup
# V1.1.1.14     08/01/94 16:13:42 nrjbehrs IUT cleanup
# V1.1.1.15     08/15/94 15:00:29 nrjbehrs IUT cleanup
# V1.1.1.16     08/18/94 10:30:52 nrjbehrs IUT cleanup
# V1.1.1.17     09/09/94 15:00:24 kok      IUT Updates
# V1.1.1.18     01/11/95 14:24:10 kok      Updates for finding code files
# V1.1.1.19     01/13/95 16:20:54 kok      pd_test
