sl@0: #!/usr/bin/perl -w sl@0: # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # USBperformance - write file to / read file from sl@0: # a USB Mass Storage device, sl@0: # measure the time taken, sl@0: # and display the data rate achieved. sl@0: # sl@0: # sl@0: sl@0: use strict; sl@0: use File::Copy; sl@0: use Getopt::Long; sl@0: use Pod::Usage; sl@0: sl@0: pod2usage("$0: Specify at least a target drive.\n") if (@ARGV < 1); sl@0: sl@0: my $help = 0; sl@0: my $size = 400; sl@0: my $reading = 0; sl@0: my $local_file = "gobble.dat"; sl@0: sl@0: my %opts = ('help' => \$help, sl@0: 'size=s' => \$size, sl@0: 'read=s' => \$reading); sl@0: sl@0: GetOptions(%opts) || pod2usage(2); sl@0: pod2usage(-exitval => 1, -verbose => 2) if $help; sl@0: sl@0: $size = 1 if $size < 1; sl@0: sl@0: my $drive = $ARGV[@ARGV - 1]; sl@0: $drive =~ s/\\/\//g; sl@0: $drive .= "/" unless ($drive =~ m/\/$/); sl@0: print "Remote drive: " . $drive . "\n"; sl@0: sl@0: my $remote_file = "$drive$local_file"; sl@0: sl@0: # If set to nonzero $¦ forces a flush right away and after every write or print sl@0: # on the currently selected output channel. sl@0: $¦ = 1; sl@0: sl@0: if ($reading == 0) sl@0: { sl@0: print "Writing a $size MB file to the remote directory.\n"; sl@0: print "Creating source file \"$local_file\"...\n"; sl@0: create_gobblefile(); sl@0: print "Writing target file \"$remote_file\"...\n"; sl@0: my $write_time = writefile(); sl@0: print "File write took $write_time seconds.\n"; sl@0: printf "That's about %.2f MB/s.\n", ($size / $write_time); sl@0: } sl@0: else sl@0: { sl@0: print "Reading file from a remote directory.\n"; sl@0: -e $remote_file or die "Remote file \"$remote_file\" doesn't seem to exist"; sl@0: -z $remote_file and die "Remote file \"$remote_file\" seems to be empty"; sl@0: my $size_bytes = -s $remote_file; sl@0: $size = $size_bytes / 1024 / 1024; sl@0: print "Reading source file \"$remote_file\" ($size_bytes bytes = $size MB)...\n"; sl@0: my $read_time = readfile(); sl@0: print "File read took $read_time seconds.\n"; sl@0: printf "That's about %.2f MB/s.\n", ($size / $read_time); sl@0: unlink $local_file; sl@0: } sl@0: sl@0: sl@0: # --- subs sl@0: sl@0: sub writefile sl@0: { sl@0: my $start = time(); sl@0: move($local_file, $remote_file); sl@0: return (time() - $start); sl@0: } sl@0: sl@0: sub readfile sl@0: { sl@0: my $start = time(); sl@0: move($remote_file, $local_file); sl@0: return (time() - $start); sl@0: } sl@0: sl@0: sub create_gobblefile sl@0: { sl@0: open FILE, ">$local_file " or die $!; sl@0: my $realsize = ($size * 1024 * 1024) / 40; sl@0: my $i = 0; sl@0: while ($i++ < $realsize) sl@0: { sl@0: # Add 40 characters sl@0: print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd' or die $!; sl@0: } sl@0: close FILE; sl@0: } sl@0: sl@0: ###################################################################### sl@0: sl@0: __END__ sl@0: sl@0: =head1 NAME sl@0: sl@0: usbperformance.pl - Create a large file and write it to a Mass Storage device, or sl@0: read it back. sl@0: sl@0: =head1 SYNOPSIS sl@0: sl@0: Usage: usbperformance.pl [options] sl@0: sl@0: : The path to / drive letter of the USB Mass Storage device. sl@0: sl@0: =head1 OPTIONS sl@0: sl@0: =over 3 sl@0: sl@0: =item --help sl@0: sl@0: Displays this help. sl@0: sl@0: =item --size= sl@0: sl@0: The size of the file to be created to measure the speed connection. sl@0: sl@0: Size is expected in MB. Default value if no option given is 400 MB. sl@0: sl@0: =item --read=<0/1> sl@0: sl@0: 0 to write sl@0: 1 to read sl@0: sl@0: Default value if no option given is 0 (write). sl@0: sl@0: Ensure the card/device has been ejected and thus flushed before you do the sl@0: reading test after the writing case, otherwise the content will be cached by sl@0: the local OS and the time measured won't be realistic. sl@0: sl@0: 'Write' will leave the transferred file on the remote disk, but 'Read' will sl@0: delete it (moving it to the local PC). So a practical test order is: sl@0: sl@0: 'Write' test, then disconnect/re-connect USB drive, then 'Read' test. sl@0: sl@0: This sequence will start and finish with an empty USB disk. sl@0: sl@0: =back sl@0: sl@0: =head1 DESCRIPTION sl@0: sl@0: This is a simple utility to create a file on a mass storage unit and measure sl@0: the performance in MB / seconds of the USB connection. sl@0: sl@0: =head2 Test Case Specification sl@0: sl@0: TestCaseID: PBASE-PREQ709-0045-Performance sl@0: TestType: IT sl@0: TestCaseDesc: Test Mass Storage performance on different platforms sl@0: (Windows 2000/XP/ME, MacOS) (Manual test) sl@0: sl@0: TestActions: sl@0: sl@0: Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB sl@0: cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD sl@0: card) onto the PC. Execute this script on the PC, and make sure the card has sl@0: free space for the file that is going to be created. The default size is 400 sl@0: MB. sl@0: sl@0: =head1 COPYRIGHT sl@0: sl@0: Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: =cut