#!/bin/sh

JAVA_HOME=/home/dmitry/bundles/jdk9/b70/fastdebug/

FAILED_ITERATIONS=0
TEST_CLASS=HelloWorld

for ITERATION in $(seq 1 $1)
do
   echo "Current iteration: $ITERATION. Failed iterations = $FAILED_ITERATIONS"
   $JAVA_HOME/bin/java -XX:+UseConcMarkSweepGC -XX:CMSYoungGenPerWorker=1 $TEST_CLASS 2>err.log 1>normal.log
   grep "A fatal error has been detected" normal.log 
   if [ $? -eq 0 ]
   then
      FAILED_ITERATIONS=$(($FAILED_ITERATIONS + 1));
      mkdir $FAILED_ITERATIONS
      cp err.log $FAILED_ITERATIONS/err.log
      cp normal.log $FAILED_ITERATIONS/normal.log
   fi
done


