#!/bin/ksh
#
# ident "@(#)rmdtest	1.4      01/07/16 SMI"
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#
# THIS IS THE HARD DISK 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
prgdir=/opt/SUNWstaf/prgs	# program directory
iosize=$2			# i/o MB size
iodev=$1			# input device
infile=$iodev/rmd1.$$.hcts	# input file	
outfile=$iodev/rmd2.$$.hcts	# output file
#maxwarn=50      # max number of nonfatal warnings to tolerate.


# functions

# clean up output file
clean_up()
{
	rm -f $infile $outfile
}

### MAIN ###

# check args
if [ $# -ne 2 ]
then
	echo "!ERROR: Usage: $0 [output directory] [I/O MB size]"
	exit 1
fi

# check iosize
if [ -z "$iosize" ]
then
        iosize=1
fi

# set trap
trap 'clean_up; exit' 17

# SET LOGFILE FLAG FOR MAX WARNING COUNT
# This is checked by staf.eng, and if exceeded, staf.eng will kill this module.
# ( This only makes sense if this script echos warning messages, but
#   inclusion of this variable in the log file is *MANDATORY* in all cases. )
#echo "maxwarnings=${maxwarn}"


echo "Starting Rmdtest on $1..."
# create input file
$prgdir/rwutil /dev/zero $infile $iosize 2>&1

# check for errors
if [ $? -ne 0 ]
then
	echo "!ERROR: Rmdrive I/O -> $infile"
	exit 1
fi

# copy input file to output file
$prgdir/rwutil $infile $outfile 2>&1

# check for errors
if [ $? -ne 0 ]
then
	echo "!ERROR: Rmdrive I/O -> $outfile"
	exit 1
fi

# remove output
clean_up

