#!/bin/sh
# dt-test [path] [sz_limit] [run_count]
#         $1     $2         $3

zpool list
echo "now DATE TIME= `date`"

ERROR_FILE="/usr/bin/dt-errors"

start_time=`date`
if [ ! -d $1 ]; then
	echo "PATH $1 is not existing..."
	exit
fi

SIZE_LIMIT=$2
if [ $2 -eq 0 ]; then
	# sz_limit default = 500m
	SIZE_LIMIT=500m
fi

RUN_COUNT=$3
if [ $RUN_COUNT -eq 0 ]; then
	RUN_COUNT=99
fi

# read -p "press key for dt-test PATH=$1 SIZE_LIMIT=$SIZE_LIMIT RUN_COUNT=$RUN_COUNT ..."

if [ -e $ERROR_FILE ]; then
	rm $ERROR_FILE
fi

N=0
while [ $N -lt $RUN_COUNT ]; do
	echo "RUN $N : dt of=$1/writefile bs=128k limit=$SIZE_LIMIT pf=pattern_all enable=debug,Debug,rdebug"

	dt of=$1/writefile bs=128k limit=$SIZE_LIMIT pf=/usr/bin/pattern_all enable=debug,Debug,rdebug 2>&1 | dt-filter

	if [ -e $ERROR_FILE ]; then
		break
	fi

	if [ $3 -ne 0 ]; then
		N=`expr $N + 1`
	fi
done
end_time=`date`

echo "START= $start_time  END= $end_time"

