#! /usr/bin/sh
#
#ident "@(#)runtests 1.9 04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.All rights reserved.
# Use is subject to license terms.
#
# by Mark F. Logan

date #debug
pdir=../../../../prgs


if [ $# -ne 1 ]
then
	echo "!ERROR: Usage: $0 [disk slice]"
	exit 1
fi

DEV=$1

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

HANDLE_FOR_SIG_16()
{
    PID_TO_KILL=`pgrep -P $$`

    echo "!PASS: No errors found in dd - Did $i iterations"

    for pid in $PID_TO_KILL
    do
         kidpid=`$pdir/child ${pid}`
         # kill test parent
         kill -9 ${pid} > /dev/null 2>&1
         # kill test children
         kill -9 $kidpid > /dev/null 2>&1
    done

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

trap 'HANDLE_FOR_SIG_16' 16

i=1
while [ -d /proc/$sleepid ]
do
	starttime=`../../../../prgs/time_sec`
	sh dd.sh $DEV &
	PID=$!
	while [ -d /proc/$PID ]
	do
		ls -l > /dev/null
		sleep 5
	done
	i=`expr $i + 1`
	endtime=`../../../../prgs/time_sec`
	echo LOOPTIME: `expr $endtime - $starttime`
done

echo "!PASS: finale No errors found in dd - Did $i iterations"
