#!/bin/csh
#
#
set REV = 0004
#
#
#    03/24/94   Roger Richardson
#     		Created
#
#    05/17/94   Added a file command test to insure that the drive is
#    Rev. 002	spun up before the test is started.
#		
#
#    11/16/94   Elimated the block device option and added an option
#    Rev. 003	that would zero out the disk label. to insure the dt script
#		does not report a "Read-only file system" error.
#		General clean up. 
#
#    12/29/94   Modified the script to complete one full pass before looping.
#    Rev. 004   Added error checking, if an error is detected with 'dt'
#		the script will terminate and no additional passes will
#		be performed.
#
#	Description:
#
#	This script is used to verify tag-queuing option of hard drives.
#	Multiple processes will be started in parallel. Data will be
#	written and then read and compared.
#	The script can be run in either the interactive mode where the
#	user will be asked for the arguments with default
#	values supplied, or by using command line arguments.
#	This script does not currently support optical devices.
#
#	The format for the the data is as follows :
#
#	Example of using the interactive mode :
#	./dt_tag_sh
#
#	The user will be prompted for the arguments with default values
#	supplied.
#
#	Example of using the command line argument mode :
#	./dt_tag_sh rrz18c rz26l rz26l_log ''  1 ''&
#
#	device name   = rrz18c
#	device type   = rz26l 
#	log file      = rz26l_log
#	data limit    = default
#	pass count    = 1
#	# of processes= default	

# Arguments:
#	$1    The device name.    Example :  rrz4c, rrz8c, etc.
#	$2    The device type.    Example :  rz26l, rz28, etc.
#	$3    The log file name.  default = [device_type]_[device_name]_[date]_tag
#	$4    The data limit.     default = 100m
#	$5    The pass count.     default = 1 
#	$6    # of processes 	  default = 36
#
set DEVICE=$1
set DISK_T=$2
set LOG_FILE=$3
set DATA_LIMIT=$4
set NUM_PROCS=$5
set PASS_COUNT=$6
 
set DT = `date "+%m%d%y"`

if ($DEVICE == '') then
    echo -n 'Enter RAW device to test (rrz4c, rrz8c, etc. Note: include the partition): '
    set DEV = $<
    if (`echo $DEV | sed  "s/z.*//"` == r) then
	set DEVN = r$DEV			# device name, rrrz?c, etc.
	set DEV = '/dev/r'$DEV			# force the raw device
    else
	set DEVN = $DEV			# device name, rrrz?c, etc.
	set DEV = '/dev/'$DEV
    endif

    echo -n 'Enter Disk type (rz25, rz26, ez54r, etc.) : '
    set DISK_T = $<
 
    set LOG_FILE = $DISK_T'_'$DEVN'_'$DT'_tag'

    echo -n "Enter logfile name [ $LOG_FILE ] : "
    set RESP = $<
    if ( $RESP != "" ) then
       set LOG_FILE = $RESP
    endif

    set DATA_LIMIT = 100m
    echo -n "Enter the number of blocks to test [$DATA_LIMIT] : "
    set RESP = $<
    if ( $RESP != "" ) then
      set DATA_LIMIT = $RESP
    endif

    set PASS_COUNT = 1
    echo -n "Enter number of passes [$PASS_COUNT] : "
    set RESP = $<
    if ( $RESP != "" ) then
       set PASS_COUNT = $RESP
    endif

    set NUM_PROCS = 36
    echo "The number of processes should be equal to the tag queue depth : "
    echo -n "Enter number of processes [$NUM_PROCS] : "
    set RESP = $<
    if ( $RESP != "" ) then
       set NUM_PROCS = $RESP
    endif

else						# using command line interface
        if (`echo $DEVICE | sed  "s/z.*//"` == r) then
	    set DEVN = r$DEVICE			# device name rmt*c, etc.
	    set DEV = /dev/r$DEVICE		# force the raw device
	else
	    set DEVN = $DEVICE			# device name rmt*c, etc.
	    set DEV = /dev/$DEVICE
	endif
endif

    if ($LOG_FILE == '') then
	set LOG_FILE=$DISK_T'_'$DEVN'_'$DT'_tag'
    endif

    if ($DATA_LIMIT == '') then
	set DATA_LIMIT=100m
    endif

    if ($PASS_COUNT == '') then
	set PASS_COUNT=1
    endif

    if ($NUM_PROCS == '') then
	set NUM_PROCS=36
    endif

endif



if (-f $LOG_FILE) then
	rm -f $LOG_FILE
endif

# Log the Operating System version and the device firmware revision.

echo "**********************************************************************" >>&LOG_FILE
echo "" >>& $LOG_FILE
echo "                   OSF/ALPHA SCSI HARD DISK DT TAG-QUEUING SCRIPT" >>& $LOG_FILE
echo "                           Revision # $REV" >>& $LOG_FILE
echo "" >>& $LOG_FILE
set HOST = `hostname`
echo "                           Hostname : $HOST" >>& $LOG_FILE
echo "" >>& $LOG_FILE
echo "                           Operating System :" >>& $LOG_FILE
echo "" >>& $LOG_FILE
grep DEC /etc/motd  >>& $LOG_FILE
echo "" >>& $LOG_FILE
echo "**********************************************************************" >>& $LOG_FILE
echo "" >>& $LOG_FILE

echo '--------------------------------------------------------------------' >>& $LOG_FILE
echo '|                          File Command Test                       |' >>& $LOG_FILE
echo '--------------------------------------------------------------------' >>& $LOG_FILE
date >>& $LOG_FILE
echo "" >>& $LOG_FILE
echo '-----------------------' >>&  $LOG_FILE
echo '|    Command Line :   |' >>&  $LOG_FILE
echo '-----------------------' >>&  $LOG_FILE
echo file \{$DEV\} >>&  $LOG_FILE
echo "" >>&  $LOG_FILE
file {$DEV} >>&  $LOG_FILE
echo "" >>&  $LOG_FILE

echo '--------------------------------------------------------------------' >>&  $LOG_FILE
echo '|                          Show Inquiry Test                       |' >>&  $LOG_FILE
echo '--------------------------------------------------------------------' >>&  $LOG_FILE
date >>& $LOG_FILE
echo "" >>&  $LOG_FILE
# Set up scu cmd input file
echo "show inquiry" > scu.input.$LOG_FILE 
echo "quit">> scu.input.$LOG_FILE
echo '-----------------------' >>&  $LOG_FILE
echo '|    Command Line :   |' >>&  $LOG_FILE
echo '-----------------------' >>&  $LOG_FILE
echo "scu -f {$DEV} show inquiry" >>&  $LOG_FILE
echo "" >>& $LOG_FILE
scu -f {$DEV} < scu.input.$LOG_FILE >>&  $LOG_FILE

# Remove the scu cmd input file
rm scu.input.$LOG_FILE

echo "" >>& $LOG_FILE  
echo '--------------------------------------------------------------------' >>&  $LOG_FILE
echo '|                          Zero Out the Disklabel                   |' >>&  $LOG_FILE
echo '|                                                                   |' >>&  $LOG_FILE
echo '| If the disk is not labeled the following message will be returned |' >>&  $LOG_FILE
echo '|   Bad pack magic number (label is damaged, or pack is unlabeled)  |' >>&  $LOG_FILE
echo '--------------------------------------------------------------------' >>&  $LOG_FILE
date >>& $LOG_FILE
echo "" >>&  $LOG_FILE
echo '-----------------------' >>&  $LOG_FILE
echo '|    Command Line :   |' >>&  $LOG_FILE
echo '-----------------------' >>&  $LOG_FILE
echo "disklabel -z $DEV " >>&  $LOG_FILE
disklabel -z $DEV  >>&  $LOG_FILE


set nu = 0
while( $nu  < $PASS_COUNT )
@ nu++

echo "" >>& $LOG_FILE  
echo '--------------------------------------------------------------------' >>&  $LOG_FILE
echo '|                          DT Tag Queue Test                        |' >>&  $LOG_FILE
echo '--------------------------------------------------------------------' >>&  $LOG_FILE
date >>& $LOG_FILE
echo "" >>&  $LOG_FILE

echo "./dt of=$DEV min=1b max=64k incr=1b limit=$DATA_LIMIT procs=$NUM_PROCS align=p-13 pattern=pattern_6 " >>& $LOG_FILE 

./dt of=$DEV min=1b max=64k incr=1b limit=$DATA_LIMIT procs=$NUM_PROCS align=p-13 pattern=pattern_6 >>& $LOG_FILE 

if ( $status != 0 ) then
        echo "" >>& $LOG_FILE
        echo "********************************************" >> $LOG_FILE
        echo "*  WARNING TEST TERMINATED DUE TO FAILURE  *" >> $LOG_FILE
        echo "********************************************" >> $LOG_FILE
        date >> $LOG_FILE
        echo "" >> $LOG_FILE
        goto exit
endif

echo "" >>& $LOG_FILE
echo "************************************************************" >>& $LOG_FILE
echo "                      PASS  $nu  COMPLETED " >> $LOG_FILE
echo -n "                    " >> $LOG_FILE
date >>& $LOG_FILE
echo "************************************************************" >>& $LOG_FILE
end
exit:
