#!/usr/bin/perl
#
# rawtest /dev/raw/rawX
#
# test hd performance of raw device. See raw(8)
#
# (c) Tomas Pospisek. Licensed under the GPL V2.
#

# How many blocks should be accessed
my $BLOCKS=10000;

help() if $ARGV[0] eq "--help";

my $rawdevice = $ARGV[0];

if(`stat --format="%t %T" $rawdevice 2>/dev/null` ne "a2 1\n") {
  print "Usage: rawtest /dev/raw/rawX\n";
  print "Error: You need to supply a raw device as argument!\n";
  print "       Try \"rawtest --help\".\n";
  exit 1;
}

print "Testing $rawdevice will DESTROY all data on that device?\n";
print "Press \"Enter\" if you want to proceed and \"CTRL-C\" to abort\n";
my $enter=<STDIN>;

print "Read performace:\n";
print `time dd if=$rawdevice of=/dev/null count=$BLOCKS`."\n";

print "Write performace:\n";
print `time dd if=/dev/zero of=$rawdevice count=$BLOCKS`."\n";
print "\n";

exit 0;

sub help() {
  print <<EOT;
Usage: rawtest /dev/raw/rawX

rawtest is a tool to test throughput to raw devices. A raw device
is an alternative interface to a block device where the linux
kernel will not buffer anything. See raw(8) for more info. 

To create a raw device first make an empty partition that is at
least $BLOCKS large (see fdisk(8), cfdisk(8)). Then attach the
raw device to that partition (see raw(8)). Finally run rawtest
on it.

ALL THE DATA ON SUCH A DEVICE WILL BE DESTROYED!!!!!

So please BE CAREFUL when using rawtest and the disk partitioning
tools.
EOT

exit 0;

}
