#!/bin/bash
# Guifré Molera 12/10/2006
#
# Long test to verify VSIB data and HDD behaviour
# modified version from longtest16 : 31/08/2006
#
# Execute via 'sudo ./longtest' or as root
#
# Assumes 'wr' is compiled and found in /usr/src/vsib
# Assumes 4 SATA disk raid on sda,sdb,sdc,sdd
# -------------------------------------------------------
# Settings:
# - where your raid is mounted /i1 or /raid (no trailing /)
export VSIRAIDMOUNTPOINT=/raid 

# - raid test directory in the mountpoint (no trailing /)
export VSIRAIDDIR=$VSIRAIDMOUNTPOINT/t

# - assume bigbuf size was set to 144MiB in kernel boot params
#   (this can also be read from 'cat /proc/bigphysarea')
export BIGBUF=144000000


function cleanup()
{
  free
  echo "rm -f $VSIRAIDDIR/t0*:"
  /usr/bin/time rm -f $VSIRAIDDIR/t0*
  df $VSIRAIDMOUNTPOINT
  sync
  echo "---"
  echo " "
}

function run ()
{
  date
  echo $@
 /usr/bin/time $@
 cleanup
}

function runnd ()
{
  date
  echo $@
 /usr/bin/time $@
}

function checkfiles()
{
 md5sum $VSIRAIDDIR/t0*
}

function blocks_available()
{
 VAR1=`df $VSIRAIDDIR | tail +2`
 VAR2=`echo $VAR1 | cut -d ' ' -f4`
 VAR3=$((($VAR2 * 99 / 100) * 1024 / 80000 ))
}

# Init script testlog

# Display hard drive info & settings.
cat /proc/mdstat
smartctl -d ata -a /dev/sda
smartctl -d ata -a /dev/sdb
smartctl -d ata -a /dev/sdc
smartctl -d ata -a /dev/sdd

# Tests
echo "'longtest' script start at `date`."
echo "============================================================"
cleanup

while true; 
do
 rmmod vsib
 modprobe vsib bigbufsize=$BIGBUF
 # wait for VSIB driver to intialize the controller
 sleep 2
 echo "------------------------------------------------------------"
 blocks_available
 runnd /usr/src/vsib/wr 80000 `echo $VAR3` 2 0 1 0 1 $VSIRAIDDIR/t%06d 4000 </dev/vsib
 tail -30 /var/log/messages
 df $VSIRAIDMOUNTPOINT
 checkfiles
 cleanup
done
