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