#! /bin/sh
#
#ident	"@(#)runtest.sh	1.15	05/06/08 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#


pdir=../../../../prgs
device=$1
sleep ${RUNTIME:-14400} &
sleepid=$!
RUNTIME1=`expr ${RUNTIME:-14400} - 300`
ARGS=`$pdir/getppid`
$pdir/timer $RUNTIME1 $ARGS &

HANDLE_FOR_SIG_16()
{

    echo "!PASS: No errors found in fs_stress - Did $count iterations"

    kidpid=`$pdir/child $$ | sed -e "s/${sleepid}//"`
    kill -9 $kidpid > /dev/null 2>&1

    while [ -d /proc/$sleepid ]
    do
        sleep 5
    done
    exit 0
}

trap 'HANDLE_FOR_SIG_16' 16

#count initialized to 1 since fs_stress will not finish within 4 hrs.  It
#will be assumed complete if no error messages within 4 hrs.
count=1
while [ -d /proc/$sleepid ]
do
        if [ ! -z "$HCTS_ENV" ]
        then
		starttime=`../../../../prgs/time_sec`
		#./fs_stress $* &
		./$FSTR_BIN/fs_stress $* &
		PID=$!
		wait $PID
		if [ $? != 0 ]
		then
			echo "!ERROR: fs_stress failed."
			exit 1
		fi
		count=`expr $count + 1`
		endtime=`../../../../prgs/time_sec`
		ltime=`expr $endtime - $starttime`
		if [ $ltime -gt 0 ]
		then
			echo LOOPTIME: $ltime
		fi
	else
		#./fs_stress $*
		./$FSTR_BIN/fs_stress $*
                if [ $? != 0 ]
                then
                        echo "!ERROR: fs_stress did not complete."
                        exit 1
                fi

		count=`expr $count + 1`
	fi		
done

echo "!PASS: fs_stress completed $count iterations without error";

exit 0

