#!/bin/bash

. buildsys/functions

ProcessArgs $*
Assert LoadConfigs
Assert SetupLogDir
Assert SetupResFile

cd ../../..

SetState Testing
ArchiveLogs

if [ "$DEP" != "none" ]
then
   OSPL_HOME=$DEPWORKDIR
   export OSPL_HOME
fi

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

echo "RUN/RBT=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 $LOGDIR/RBT-Results ||
{ 
    echo "ERROR: could not make directory $LOGDIR/RBT-Results - dcps_perform_rbt_tests"; 
    exit 3; 
}

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 $LOGDIR/RBT-Results/. ||
    { 
        echo "ERROR: could not copy $i - dcps_perform_rbt_tests"; 
        exit 4; 
    }
done
exit 0
