os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbperformance.pl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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 - write file to / read file 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 at least a target drive.\n")  if (@ARGV < 1);
sl@0
    28
sl@0
    29
my $help = 0;
sl@0
    30
my $size = 400;
sl@0
    31
my $reading = 0;
sl@0
    32
my $local_file = "gobble.dat";
sl@0
    33
sl@0
    34
my %opts = ('help' => \$help,
sl@0
    35
			'size=s' => \$size,
sl@0
    36
			'read=s' => \$reading);
sl@0
    37
sl@0
    38
GetOptions(%opts) || pod2usage(2);
sl@0
    39
pod2usage(-exitval => 1, -verbose => 2) if $help;
sl@0
    40
sl@0
    41
$size = 1 if $size < 1;
sl@0
    42
sl@0
    43
my $drive = $ARGV[@ARGV - 1];
sl@0
    44
$drive =~ s/\\/\//g;
sl@0
    45
$drive .= "/" unless ($drive =~ m/\/$/);
sl@0
    46
print "Remote drive: " . $drive . "\n";
sl@0
    47
sl@0
    48
my $remote_file = "$drive$local_file";
sl@0
    49
sl@0
    50
# If set to nonzero $¦ forces a flush right away and after every write or print
sl@0
    51
# on the currently selected output channel.
sl@0
    52
$¦ = 1;
sl@0
    53
sl@0
    54
if ($reading == 0)
sl@0
    55
{
sl@0
    56
	print "Writing a $size MB file to the remote directory.\n";
sl@0
    57
	print "Creating source file \"$local_file\"...\n";
sl@0
    58
	create_gobblefile();
sl@0
    59
	print "Writing target file \"$remote_file\"...\n";
sl@0
    60
	my $write_time = writefile();
sl@0
    61
	print "File write took $write_time seconds.\n";
sl@0
    62
	printf "That's about %.2f MB/s.\n", ($size / $write_time);
sl@0
    63
}
sl@0
    64
else
sl@0
    65
{
sl@0
    66
	print "Reading file from a remote directory.\n";
sl@0
    67
	-e $remote_file or die "Remote file \"$remote_file\" doesn't seem to exist";
sl@0
    68
	-z $remote_file and die "Remote file \"$remote_file\" seems to be empty";
sl@0
    69
	my $size_bytes = -s $remote_file;
sl@0
    70
	$size = $size_bytes / 1024 / 1024;
sl@0
    71
	print "Reading source file \"$remote_file\" ($size_bytes bytes = $size MB)...\n";
sl@0
    72
	my $read_time = readfile();
sl@0
    73
	print "File read took $read_time seconds.\n";
sl@0
    74
	printf "That's about %.2f MB/s.\n", ($size / $read_time);
sl@0
    75
	unlink $local_file;
sl@0
    76
}
sl@0
    77
sl@0
    78
sl@0
    79
# --- subs
sl@0
    80
sl@0
    81
sub writefile
sl@0
    82
{
sl@0
    83
	my $start = time();
sl@0
    84
	move($local_file, $remote_file);
sl@0
    85
	return (time() - $start);
sl@0
    86
}
sl@0
    87
sl@0
    88
sub readfile
sl@0
    89
	{
sl@0
    90
	my $start = time();
sl@0
    91
	move($remote_file, $local_file);
sl@0
    92
	return (time() - $start);
sl@0
    93
	}
sl@0
    94
sl@0
    95
sub create_gobblefile
sl@0
    96
{
sl@0
    97
	open FILE, ">$local_file " or die $!;
sl@0
    98
	my $realsize = ($size * 1024 * 1024) / 40;
sl@0
    99
	my $i = 0;
sl@0
   100
	while ($i++ < $realsize)
sl@0
   101
	{
sl@0
   102
		# Add 40 characters
sl@0
   103
		print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd' or die $!;
sl@0
   104
	}
sl@0
   105
	close FILE;
sl@0
   106
}
sl@0
   107
sl@0
   108
######################################################################
sl@0
   109
sl@0
   110
__END__
sl@0
   111
sl@0
   112
=head1 NAME
sl@0
   113
sl@0
   114
usbperformance.pl - Create a large file and write it to a Mass Storage device, or
sl@0
   115
	read it back.
sl@0
   116
sl@0
   117
=head1 SYNOPSIS
sl@0
   118
sl@0
   119
Usage: usbperformance.pl [options] <USB drive>
sl@0
   120
sl@0
   121
<USB drive>: The path to / drive letter of the USB Mass Storage device.
sl@0
   122
sl@0
   123
=head1 OPTIONS
sl@0
   124
sl@0
   125
=over 3
sl@0
   126
sl@0
   127
=item --help
sl@0
   128
sl@0
   129
Displays this help.
sl@0
   130
sl@0
   131
=item --size=<size>
sl@0
   132
sl@0
   133
The size of the file to be created to measure the speed connection.
sl@0
   134
sl@0
   135
Size is expected in MB. Default value if no option given is 400 MB.
sl@0
   136
sl@0
   137
=item --read=<0/1>
sl@0
   138
sl@0
   139
0 to write
sl@0
   140
1 to read
sl@0
   141
sl@0
   142
Default value if no option given is 0 (write).
sl@0
   143
sl@0
   144
Ensure the card/device has been ejected and thus flushed before you do the
sl@0
   145
reading test after the writing case, otherwise the content will be cached by
sl@0
   146
the local OS and the time measured won't be realistic.
sl@0
   147
sl@0
   148
'Write' will leave the transferred file on the remote disk, but 'Read' will
sl@0
   149
delete it (moving it to the local PC). So a practical test order is:
sl@0
   150
sl@0
   151
'Write' test, then disconnect/re-connect USB drive, then 'Read' test.
sl@0
   152
sl@0
   153
This sequence will start and finish with an empty USB disk.
sl@0
   154
sl@0
   155
=back
sl@0
   156
sl@0
   157
=head1 DESCRIPTION
sl@0
   158
sl@0
   159
This is a simple utility to create a file on a mass storage unit and measure
sl@0
   160
the performance in MB / seconds of the USB connection.
sl@0
   161
sl@0
   162
=head2 Test Case Specification
sl@0
   163
sl@0
   164
 TestCaseID:	PBASE-PREQ709-0045-Performance
sl@0
   165
 TestType: 	IT
sl@0
   166
 TestCaseDesc:  Test Mass Storage performance on different platforms
sl@0
   167
	        (Windows 2000/XP/ME, MacOS) (Manual test)
sl@0
   168
sl@0
   169
 TestActions:
sl@0
   170
sl@0
   171
Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB
sl@0
   172
cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD
sl@0
   173
card) onto the PC. Execute this script on the PC, and make sure the card has
sl@0
   174
free space for the file that is going to be created. The default size is 400
sl@0
   175
MB.
sl@0
   176
sl@0
   177
=head1 COPYRIGHT
sl@0
   178
sl@0
   179
 Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
   180
sl@0
   181
=cut