#!/bin/ksh
#
#ident	"@(#)largedisk.stf	1.3	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# This is the Largedisk 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=../../prgs	# program directory
device=$1			# Scratch directory to use.
size=$2			# Scratch directory to use.
usbdiskfile=/tmp/usbdisk.dat
hname=`hostname`
results=/opt/SUNWhcts/results/$hname


# functions

clean_up()
{
	echo "Large Disk Ending!"
	if [ -f $usbdiskfile ]
	then
		#rm -f $usbdiskfile
                sleep 0
	fi
}

### MAIN ###


if [ -z "$device" ]
then
    if [ -f $usbdiskfile ]
    then
        #if [ `/usr/local/bin/expr match $i $keyword` -eq ${#keyword} ]
        #then
        #    device=`echo $i | sed 's/^$keyword : //g'`
        #fi
        while read i
        do
            echo $i | grep "device" >/dev/null
            if [ $? -eq 0 ]
            then
                device=`echo $i | sed 's/^device : //g'`
            fi
        done <$usbdiskfile
    else
        echo "!Error: No target disk and size found."
        exit 1
    fi
fi
if [ -z "$size" ]
then
    if [ -f $usbdiskfile ]
    then
        #if [ `/usr/local/bin/expr match $i $keyword` -eq ${#keyword} ]
        #then
        #    device=`echo $i | sed 's/^$keyword : //g'`
        #fi
        while read i
        do
            echo $i | grep "size" >/dev/null
            if [ $? -eq 0 ]
            then
                size=`echo $i | sed 's/^size : //g'`
            fi
        done <$usbdiskfile
    fi
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 Large Disk Test..."

if [ -f $results/largedisk.results ]
then
	rm -f $results/largedisk.results
fi

cd largedisk/bin
./largedisk.sh $device $size

clean_up








