#!/bin/bash
#
# Small version to verify data from the VSIB
# modified version from longtest16 : 31/08/2006, Jan Wagner
#
# Execute via 'sudo ./vsib-test' 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*
}

if [ ! -d $VSIRAIDDIR ]; then
   echo "Test file directory $VSIRAIDDIR doesn't exist, please check script"
   exit
fi

# 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 "'vsib-test' script start at `date`."
echo "============================================================"
cleanup

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