#!/bin/sh

###############################################
#
# External USB mass-storage speed test script.
#
# Copyright(C) 2010 KEISOKU GIKEN Co., Ltd.
# Author : Shinichiro Nakamura
#
###############################################

#
# Variables.
#
BSLIST="256 512 1024 2048 4096"
COUNT="65536"
DEV_ZERO="/dev/zero"
DEV_NULL="/dev/null"
IOFILE="/mnt/xdmdrv/image/disk1/umass_speed.tmp"
LOGFILE="umass_speed_wofw.log"
KEY="real"

MNT_TYPE="dos"
MNT_POINT="/mnt/xdmdrv/image/disk1"
DEV_DRIVE="/dev/hd2t11"

CNT="0"
MAX="100"

while [ ! $CNT == $MAX ]
do
	#
	# Mount the target drive.
	#
        mount -t $MNT_TYPE $DEV_DRIVE $MNT_POINT
	if [ ! $? == 0 ]
	then
	    echo "Failure to mount the devie."
	    exit 1
	fi

	#
	# Header for you.
	#
	echo "###############################################" | tee -a $LOGFILE
	echo "# MEMO:                                        " | tee -a $LOGFILE
	echo "###############################################" | tee -a $LOGFILE
	echo "" | tee -a $LOGFILE

	#
	# Write test.
	#
	echo "###############################################" | tee -a $LOGFILE
	echo "# Write test:                                  " | tee -a $LOGFILE
	echo "###############################################" | tee -a $LOGFILE
	for BS in $BSLIST
	do
	    SIZE=`expr $BS '*' $COUNT`
	    echo "# $SIZE [Bytes] ($BS x $COUNT)" | tee -a $LOGFILE
	    (time dd if=$DEV_ZERO of=$IOFILE bs=$BS count=$COUNT) 2>&1 \
		| grep $KEY \
		| tee -a $LOGFILE
	done

	#
	# Read test.
	#
	echo "###############################################" | tee -a $LOGFILE
	echo "# Read test:                                   " | tee -a $LOGFILE
	echo "###############################################" | tee -a $LOGFILE
	for BS in $BSLIST
	do
	    SIZE=`expr $BS '*' $COUNT`
	    echo "# $SIZE [Bytes] ($BS x $COUNT)" | tee -a $LOGFILE
	    (time dd if=$IOFILE of=$DEV_NULL bs=$BS count=$COUNT) 2>&1 \
		| grep $KEY \
		| tee -a $LOGFILE
	done

	#
	# End marker.
	#
	echo "" | tee -a $LOGFILE
	echo "" | tee -a $LOGFILE
	echo "" | tee -a $LOGFILE

	#
	# Unmount the target drive.
        umount $MNT_POINT
	if [ ! $? == 0 ]
	then
	    echo "Failure to umount the devie."
	    exit 1
	fi

        #
        # Update execute counter.
        #
	CNT=`expr $CNT + 1`

done

exit 0

