os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbperformance_multifile.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#!/usr/bin/perl -w
sl@0
     2
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
# All rights reserved.
sl@0
     4
# This component and the accompanying materials are made available
sl@0
     5
# under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
# which accompanies this distribution, and is available
sl@0
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
#
sl@0
     9
# Initial Contributors:
sl@0
    10
# Nokia Corporation - initial contribution.
sl@0
    11
#
sl@0
    12
# Contributors:
sl@0
    13
#
sl@0
    14
# Description:
sl@0
    15
# USBperformance_multifile - write 100 files to / read them from
sl@0
    16
# a USB Mass Storage device,
sl@0
    17
# measure the time taken,
sl@0
    18
# and display the data rate achieved.
sl@0
    19
# 
sl@0
    20
#
sl@0
    21
sl@0
    22
use strict;
sl@0
    23
use File::Copy;
sl@0
    24
use Getopt::Long;
sl@0
    25
use Pod::Usage;
sl@0
    26
sl@0
    27
pod2usage("$0: Specify a target drive.\n")  if (@ARGV < 1);
sl@0
    28
sl@0
    29
my $help = 0;
sl@0
    30
my $size = 4;									  # size of a single file in MB
sl@0
    31
my $files = 100;										# total number of files
sl@0
    32
my $reading = 0;
sl@0
    33
sl@0
    34
my %opts = ('help' => \$help,
sl@0
    35
			'read=s' => \$reading);
sl@0
    36
sl@0
    37
GetOptions(%opts) || pod2usage(2);
sl@0
    38
pod2usage(-exitval => 1, -verbose => 2) if $help;
sl@0
    39
sl@0
    40
my $drive = $ARGV[@ARGV - 1];
sl@0
    41
$drive =~ s/\\/\//g;
sl@0
    42
$drive .= "/" unless ($drive =~ m/\/$/);
sl@0
    43
print "Remote drive: " . $drive . "\n";
sl@0
    44
sl@0
    45
# If set to nonzero $¦ forces a flush right away and after every write or print
sl@0
    46
# on the currently selected output channel.
sl@0
    47
$¦ = 1;
sl@0
    48
sl@0
    49
if ($reading == 0)
sl@0
    50
{
sl@0
    51
	print "Writing $files $size-MB files to the remote directory.\n";
sl@0
    52
	print "Creating source files...\n";
sl@0
    53
	create_files();
sl@0
    54
	print "Writing target files...\n";
sl@0
    55
	my $write_time = write_files();
sl@0
    56
	print "File write took $write_time seconds.\n";
sl@0
    57
	printf "That's about %.2f MB/s.\n", ($size * $files / $write_time);
sl@0
    58
}
sl@0
    59
else
sl@0
    60
{
sl@0
    61
	print "Reading files back from remote directory.\n";
sl@0
    62
	print "Reading source files...\n";
sl@0
    63
	my $read_time = read_files();
sl@0
    64
	print "File read took $read_time seconds.\n";
sl@0
    65
	printf "That's about %.2f MB/s.\n", ($size * $files / $read_time);
sl@0
    66
	delete_files();
sl@0
    67
}
sl@0
    68
sl@0
    69
sl@0
    70
# --- subs
sl@0
    71
sl@0
    72
sub write_files
sl@0
    73
{
sl@0
    74
	my $start = time();
sl@0
    75
	for (my $i = 1; $i <= $files; $i++)
sl@0
    76
	{
sl@0
    77
		my $filename = "usbfile" . $i . ".dat";
sl@0
    78
		print "Writig $filename\r";
sl@0
    79
		move($filename, "$drive" . $filename);
sl@0
    80
	}
sl@0
    81
	print "\n";
sl@0
    82
	return (time() - $start);
sl@0
    83
}
sl@0
    84
sl@0
    85
sub read_files
sl@0
    86
{
sl@0
    87
	my $start = time();
sl@0
    88
	for (my $i = 1; $i <= $files; $i++)
sl@0
    89
	{
sl@0
    90
		my $filename = "usbfile" . $i . ".dat";
sl@0
    91
		print "Reading $filename\r";
sl@0
    92
		move("$drive" . $filename, $filename);
sl@0
    93
	}
sl@0
    94
	print "\n";
sl@0
    95
	return (time() - $start);
sl@0
    96
}
sl@0
    97
sl@0
    98
sub create_files
sl@0
    99
{
sl@0
   100
	for (my $i = 1; $i <= $files; $i++)
sl@0
   101
	{
sl@0
   102
		my $filename = "usbfile" . $i . ".dat";
sl@0
   103
		print "Creating file $filename\r";
sl@0
   104
		open FILE, ">$filename " or die $!;
sl@0
   105
		my $fills = ($size * 1024 * 1024) / 64;
sl@0
   106
		my $j = 0;
sl@0
   107
		while ($j++ < $fills)
sl@0
   108
		{
sl@0
   109
			# Add 64 characters at a time
sl@0
   110
			print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!' or die $!;
sl@0
   111
		}
sl@0
   112
		close FILE;
sl@0
   113
	}
sl@0
   114
	print "\n";
sl@0
   115
}
sl@0
   116
sl@0
   117
sub delete_files
sl@0
   118
{
sl@0
   119
	for (my $i = 1; $i <= $files; $i++)
sl@0
   120
	{
sl@0
   121
		my $filename = "usbfile" . $i . ".dat";
sl@0
   122
		unlink $filename;
sl@0
   123
	}
sl@0
   124
}
sl@0
   125
sl@0
   126
######################################################################
sl@0
   127
sl@0
   128
__END__
sl@0
   129
sl@0
   130
=head1 NAME
sl@0
   131
sl@0
   132
usbperformance_multifile.pl - Create 100 files and write them to a Mass Storage device or
sl@0
   133
	read them back.
sl@0
   134
sl@0
   135
=head1 SYNOPSIS
sl@0
   136
sl@0
   137
Usage: usbperformance_multifile.pl [options] <USB drive>
sl@0
   138
sl@0
   139
<USB drive>: The path to / drive letter of the USB Mass Storage device.
sl@0
   140
sl@0
   141
=head1 OPTIONS
sl@0
   142
sl@0
   143
=over 2
sl@0
   144
sl@0
   145
=item --help
sl@0
   146
sl@0
   147
Displays this help.
sl@0
   148
sl@0
   149
=item --read=<0/1>
sl@0
   150
sl@0
   151
0 to write
sl@0
   152
1 to read
sl@0
   153
sl@0
   154
Default value if no option given is 0 (write).
sl@0
   155
sl@0
   156
Ensure the card/device has been ejected and thus flushed before you do the
sl@0
   157
reading test after the writing case, otherwise the content will be cached by
sl@0
   158
the local OS and the time measured won't be realistic.
sl@0
   159
sl@0
   160
'Write' will leave the transferred files on the remote disk, but 'Read' will
sl@0
   161
delete them (moving them to the local PC). So a practical test order is:
sl@0
   162
sl@0
   163
'Write' test, then disconnect/re-connect USB drive, then 'Read' test.
sl@0
   164
sl@0
   165
This sequence will start and finish with an empty USB disk.
sl@0
   166
sl@0
   167
=back
sl@0
   168
sl@0
   169
=head1 DESCRIPTION
sl@0
   170
sl@0
   171
This is a simple utility to create a file on a mass storage unit and measure
sl@0
   172
the performance in MB / seconds of the USB connection.
sl@0
   173
sl@0
   174
=head2 Test Case Specification
sl@0
   175
sl@0
   176
 TestCaseID:	PBASE-PREQ709-0045-Performance
sl@0
   177
 TestType: 	IT
sl@0
   178
 TestCaseDesc:  Test Mass Storage performance on different platforms
sl@0
   179
	        (Windows 2000/XP/ME, MacOS) (Manual test)
sl@0
   180
sl@0
   181
 TestActions:
sl@0
   182
sl@0
   183
Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB
sl@0
   184
cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD
sl@0
   185
card) onto the PC. Execute this script on the PC, and make sure the card has
sl@0
   186
free space for the file that is going to be created. The default size is 400
sl@0
   187
MB.
sl@0
   188
sl@0
   189
=head1 COPYRIGHT
sl@0
   190
sl@0
   191
Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
   192
sl@0
   193
=cut