#!/bin/bash
#set -v
#Get the Test dir from the build Plan Name or from command line

TOP_DIR=`pwd`
TEST=`echo $1 | awk -F " - " '{print $3}'`
shift

cd test/core/$TEST

echo "TEST is $TEST"
pwd

PLANFILE=`mktemp plan.XXXXXX`

#Launch the test
./run-bamboo-test "$@" | tee $PLANFILE

STATUS=$?
if [ $STATUS != 0 ]; then
   echo "Workflow submission failed"
   exit $STATUS
fi

#Get RUNDIR from the planning output
RUN_DIR=`grep pegasus-remove $PLANFILE | awk '{print $5}'`
echo "RUNDIR is $RUN_DIR"

# Change in to the rundir
cd $RUN_DIR

#Check status
$TOP_DIR/test/common/check-status

STATUS=$?


if [ $STATUS = 0 ]; then
  # Run Pegasus Statistics
   pegasus-statistics $RUN_DIR
else 
   echo "Pegasus status failed"
   exit $STATUS
fi

exit
