#!/bin/bash

#set -x

TESTNAME=fsropn_1

if (! [ -d run_test_${TESTNAME} ] ) 
then
    mkdir run_test_${TESTNAME}
fi

SIONDUMP=../siondump

(

  cd run_test_${TESTNAME}
  
  export SION_DEBUG=test_${TESTNAME}
  export SION_DEBUG_MASK=1023
  export SION_DEBUG_RANK1=0
  export SION_DEBUG_RANK2=1
  export SION_ERROR_MSG_RANK=0
  ../test_${TESTNAME} 1> stdout.log 2> stderr_t.log

  grep -v 'Writing debug output' stderr_t.log > stderr.log

  export SION_DEBUG=siondump_${TESTNAME}
  ${SIONDUMP} -a -l testA.out 1> stdoutdump.log 2> stderrdump.log
  grep 'siondump:' stdoutdump.log | grep -v 'endianness' | grep -v 'SIONlib version' >> stdout.log
  grep 'Task ' stdoutdump.log >> stdout.log



  if diff stderr.log ../test_${TESTNAME}_stderr.log > /dev/null
  then
      if diff stdout.log ../test_${TESTNAME}_stdout.log > /dev/null
      then
	  echo "     test_${TESTNAME}              ... OK"
      else
	  echo "     test_${TESTNAME}              ... FAILED (diff in stdout)"
	  diff -u stdout.log ../test_${TESTNAME}_stdout.log
      fi
  else
      echo "     test_${TESTNAME}              ... FAILED (diff in stderr)"
      diff -u stderr.log ../test_${TESTNAME}_stderr.log
  fi

)
