#!/bin/sh

SMOKE_TEST_LOG_DIR=/tmp
NO_ECHO=yes

CONTINUE_WHEN_FAILED=
cur_dir=`pwd`

while [ $# -gt 0 ]; do 
  case "$1" in 
  -logdir) shift; SMOKE_TEST_LOG_DIR=$1;;
  -echo) NO_ECHO="";;
  -stoponfail) CONTINUE_WHEN_FAILED="true";;
  esac
  shift
done

log_message () {
  if [ "$NO_ECHO" = "" ] ; then 
    echo $1
  fi
  echo $1 >> $SMOKE_TEST_LOG_DIR/smoke_test_results
}

rm -f $SMOKE_TEST_LOG_DIR/smoke_test_results

for i in `find . -type d` ; do 
  if [ "$i" = "." ] ; then continue; fi;
  if [ "$i" = ".." ] ; then continue; fi;
  log_message "Executing component smoke test for $i"
  $cur_dir/SmokeTestComp  $i $SMOKE_TEST_LOG_DIR 
  if [ ! "$?" = "0" ] ; then 
    if [ "$CONTINUE_WHEN_FAILED" = "true" ]; then
      log_message "Single test failed.  Exiting.... (-stoponfail selected)"
      exit 1
    fi
  fi
done
