#!/bin/ksh
#
#ident	"@(#)rmd.stf	1.7	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# THIS IS THE RMDISK TEST MODULE
#
#########################################################################
# NOTES ON OPERATION AND ERROR HANDLING:
# This script is called by staf.eng, which is the main test harness.
# Standard output gets recorded in the test module log file by staf.eng.
#
# Variable maxwarn is checked by staf.eng in the "chk_err()" monitoring process,# by grep'ing the log file of this test module.
# If maxwarn is exceeded, the staf.eng script will kill this test module.
# There are two formats for the error echos to the log files;
#
# 1.   echo "!ERROR: blah blah foo bar";
#      which will terminate the test.  If the test harness detects
#      a string match with "!ERROR", then all testing terminates.
#
# 2.   echo "!WARNING: blah blah foo bar";
#       The above format "!WARNING:" will make the log file entry,
#       but all testing will continue, no termination of tests,
#       UNLESS maxwarnings variable is exceeded.
#
# DANGER!!:  Even if you do not intend to use WARNING messages, variable
# maxwarn *MUST* be defined and the "maxwarnings=" line *MUST* be
# echo'ed to the logfile.  This syntax is mandatory.
#########################################################################


# variables
#maxwarn=50      # max number of nonfatal warnings to tolerate.
dev=		 # device mount point

# device list
dls=`cat /etc/mnttab | grep  -w "rmdisk" | grep "rw," | tr ":" "-"`

if [ -z "$dls" ]
then
        echo "No rmdisk found."
        exit 2
fi

sleep $RUNTIME &
#sleep 120 &
sleepid=$!
ldev=

while [ -d /proc/$sleepid ]
do
	
	pid=`/usr/bin/pgrep rmdtest`
	if [ -z "$pid" ] 
	then
		# get device list
		echo "$dls" | while read inline
		do
			dev=`echo "$inline" | awk '{print $2}'` # mount point
			if [ "$dev" != "$ldev" ] 
			then
			 	rmd/bin/rmdtest $dev 1 &
				jobid=$!
				sleep 2
				if [ ! -d /proc/$jobid ]; then
					echo "!ERROR Starting $dev"
					exit 1
				fi
			fi
			ldev="$dev"

		done

	fi
done

while :
do
	pid=`/usr/bin/pgrep rmdtest`

	if [ -z "$pid" ] && [ ! -d /proc/$sleepid ]
	then
		if [ $? -ne 0 ]
		then
			echo "!ERROR during rmdtest"; exit 1

		else
			echo "!PASS: Rmdtest completed"; exit 0
		fi
	fi
done


