#!/usr/bin/bash
CEPH_SRC=~/work/github/ceph.git
TEST_SCRIPT_DIR=${CEPH_SRC}/qa/workunits/fs/snaps
LOG_DIR=~/snaps

mkdir -p ${LOG_DIR}
rm -f ${LOG_DIR}/*

for ((test_num = 1; test_num <= 20; test_num++)); do
  error=false
  for mytest in $(ls ${TEST_SCRIPT_DIR}); do
    echo -n "running ${test_num}:${mytest} ... "
    sudo ${TEST_SCRIPT_DIR}/${mytest} >& ${LOG_DIR}/test-$(printf "%03d" ${test_num})-${mytest}.log
    if [ $? != 0 ]; then
      echo -e "\n----- Error in ${mytest}"
      error=true
      break;
    else
      echo "done"
    fi
    sudo find . -type d -name '.snap' -exec rmdir {}/* ';'
    sudo rm -rf *
    sleep 10
  done
  echo "-----"
  if $error; then
    break;
  fi
  sleep 1
done
