#!/bin/bash

. buildsys/functions

ProcessArgs $*
Assert LoadConfigs
Assert SetupLogDir
Assert SetupResFile

cd ../../..

SetState Testing
ArchiveLogs

if [ "$DEP" != "none" ]
then
    pathcheck readlink
    if [ $? = 0 ]
    then
        OSPL_HOME=`readlink -f "$DEPWORKDIR"`
    else
        OSPL_HOME=`FakeReadlink "$DEPWORKDIR"`
    fi
    export OSPL_HOME
fi

SPLICE_PLATFORM=$SETUP_TYPE
export SPLICE_PLATFORM
. ./configure -full

echo "RUN_RBT/$RBTTYPE=RUNNING" >> $RESFILE
ArchiveLogs

if [ "$CONFIGURATION" != "OK" ]
then
   echo "ERROR: configuration - dcps_perform_rbt_tests"
   exit 1
fi

cd testsuite/bin ||
{
    echo "ERROR: could not cd to testsuite/bin dir - dcps_perform_rbt_tests";
    exit 2;
}


mkdir $RBTLOGDIR ||
{
    echo "ERROR: could not make directory $RBTLOGDIR - dcps_perform_rbt_tests";
    exit 3;
}
if [ "$RBTTYPE" = "SP" ]
then
   TEST_DEPLOYMENT_MODE=singleprocess
else
   TEST_DEPLOYMENT_MODE=sharedmemory
fi
export TEST_DEPLOYMENT_MODE

bash ./run_rbt
bash ./RBT_management_data
for i in `find ../rbt/Results/ -type f`
do
    FILE=$i
    basename $i | grep "\." 2>&1 > /dev/null
    if [ $? != 0 ]
    then
        FILE=$i.txt
        mv $i $FILE
    fi
    cp $FILE $RBTLOGDIR/. ||
    {
        echo "ERROR: could not copy $i - dcps_perform_rbt_tests";
        exit 4;
    }
    rm $FILE ||
    {
        echo "ERROR: could not remove $FILE - dcps_perform_rbt_tests";
        exit 5;
    }
done
exit 0
