#!/usr/bin/ksh
#
#ident	"@(#)spray.sh	1.12	05/06/08 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# This test is designed to add extra stress to the network while other tests
# are already running.

warnings=0
iters=0
threshold=25

if [ $# -ne 1 ]
then
	echo "Usage: $0 destination."
	exit 1
fi

echo "Running time: $RUNTIME seconds."
sleep $RUNTIME &
sleepid=$!

while [ -d /proc/$sleepid ]
do
	out=`spray -c 500 -l 8192 $1 2>&1`
        if [ $? -ne 0 ]
        then
		warnings=$(($warnings+1))
        fi
	iters=$(($iters+1))
	sleep 10
done

if [ $(($warnings*100/$iters)) -le $threshold ]
then
	echo "!PASS: Spray completed."
else
	echo "!ERROR: Spray failed."
fi
