#! /usr/bin/ksh
#
#ident	"@(#)runtests.sh	1.11	04/12/08 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
       
date # debug
pdir=../../../../prgs
device=$1
sleep ${RUNTIME:-14400} &
sleepid=$!
RUNTIME1=`expr ${RUNTIME:-14400} - 300`
ARGS=`$pdir/getppid`
$pdir/timer $RUNTIME1 $ARGS &
rm -rf /tmp/tape_result

HANDLE_FOR_SIG_16()
{
    PID_TO_KILL=`pgrep tape.sh`

    echo "!PASS: No errors found in tape - 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=0
while [ -d /proc/$sleepid ]
do
	starttime=`../../../../prgs/time_sec`
	./tape.sh $device&
        PID=$!
	if [ $? -ne 0 ]
	then
		echo "!ERROR: tape failed"
		exit 1
	fi
        while [  -d /proc/$PID -a ! -f /tmp/tape_result ]
        do
		ls -l >/dev/null
		sleep 5
	done
        if [ -f /tmp/tape_result ]
        then 
		echo "!ERROR: tape failed"
                exit 1
	fi
	i=`expr $i + 1`
	endtime=`../../../../prgs/time_sec`
	echo LOOPTIME: `expr $endtime - $starttime`
	sleep 240
done

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

exit 0

