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