#! /usr/bin/ksh
#
# Function regTest: run the regression test step file
#
# This function reads a line of input from the step file
# and evals the statement. It then checks the return code
# for non zero exit (error). If the environment variable
# RTSSTEPEXIT is true, upon first error, the regression step
# execution will be terminated. Else, execution will continue
# and any non-zero return code will be returned at the end
# of the step file.
#
# Input Format:
#
# Author: Tim Unser

typeset bn=$(basename $0)

# initialize to no errors
LOC_ERROR=0
EXPECT_RC=0

if [ $# != 1 ]; then
    echo "%-16s[%3d]: Usage: $bn <step file>\n" $bn $LINENO
    exit 1
fi

# print test case name to error file
echo "Test case: "$i

# open the step file on fd 5
exec 5<$1
while read -u5 LINE; do
    # print out line to error file
    # LINEDATE= `date`
    # echo "$LINEDATE"
    echo "$LINE"
    erc=$EXPECT_RC
    EXPECT_RC=0

    if [ $erc != 0 ]; then
       echo "----- testing expected error condition -----"
    fi

    eval $LINE
    rc=$?
    if test -f $WORKDIR/$PREFIX/work/core; then
        echo `date` "<<<<SPOOLER CORE TAKEN ON THIS COMMAND>>>>" |\
            tee -a $SUMMARY
        mv $WORKDIR/$PREFIX/work/core $RESULTS_DIR/iutResults/$i.spooler.core
    fi
    if test -f $WORKDIR/$PREFIX/work/core; then
        COREDATE=`date`
        echo `date` "<<<<CLIENT CORE TAKEN ON THIS COMMAND>>>>" |\
            tee -a $SUMMARY
        mv $WORKDIR/$PREFIX/core $RESULTS_DIR/iutResults/$i.client.core
    fi
    if test -f $WORKDIR/$PREFIX/work/core; then
        echo `date` "<<<<SUPERVISOR CORE TAKEN ON THIS COMMAND>>>>" |\
            tee -a $SUMMARY
        mv $WORKDIR/$PREFIX/work/core $RESULTS_DIR/iutResults/$i.supervisor.core
    fi
    #
    # check return code of line - if 0 success
    #
    if [ $rc != $erc ]; then
        reportError "Expected return code $erc - got $rc"
        # mark the error
        LOC_ERROR=1
        # return only if step exit = true
        if [ "${RTSTEPEXIT}" = "true" ]; then
           exit $LOC_ERROR
        fi
    fi
done
[ $? != 0 ] && LOC_ERROR=1

exit $LOC_ERROR
#
#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ----------------------------
# V1.2          06/29/94 10:47:24 nrjbehrs made read cmd work
# V1.3          06/29/94 16:58:43 nrjbehrs add comments
# V1.4          07/05/94 09:53:32 nrjbehrs changed logging
# V1.5          07/19/94 16:25:31 nrjbehrs IUT fixes
# V1.6          07/28/94 16:11:14 nrjbehrs IUT cleanup
# V1.7          08/01/94 16:13:38 nrjbehrs IUT cleanup
# V1.8          08/24/94 13:42:26 nrjbehrs fixed ret_code
# V1.9          01/11/95 14:22:22 kok      Updates for finding code files
# V1.10         01/13/95 16:20:31 kok      pd_test
