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_multifile - write 100 files to / read them 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 a target drive.\n") if (@ARGV < 1); sl@0: sl@0: my $help = 0; sl@0: my $size = 4; # size of a single file in MB sl@0: my $files = 100; # total number of files sl@0: my $reading = 0; sl@0: sl@0: my %opts = ('help' => \$help, 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: 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: # 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 $files $size-MB files to the remote directory.\n"; sl@0: print "Creating source files...\n"; sl@0: create_files(); sl@0: print "Writing target files...\n"; sl@0: my $write_time = write_files(); sl@0: print "File write took $write_time seconds.\n"; sl@0: printf "That's about %.2f MB/s.\n", ($size * $files / $write_time); sl@0: } sl@0: else sl@0: { sl@0: print "Reading files back from remote directory.\n"; sl@0: print "Reading source files...\n"; sl@0: my $read_time = read_files(); sl@0: print "File read took $read_time seconds.\n"; sl@0: printf "That's about %.2f MB/s.\n", ($size * $files / $read_time); sl@0: delete_files(); sl@0: } sl@0: sl@0: sl@0: # --- subs sl@0: sl@0: sub write_files sl@0: { sl@0: my $start = time(); sl@0: for (my $i = 1; $i <= $files; $i++) sl@0: { sl@0: my $filename = "usbfile" . $i . ".dat"; sl@0: print "Writig $filename\r"; sl@0: move($filename, "$drive" . $filename); sl@0: } sl@0: print "\n"; sl@0: return (time() - $start); sl@0: } sl@0: sl@0: sub read_files sl@0: { sl@0: my $start = time(); sl@0: for (my $i = 1; $i <= $files; $i++) sl@0: { sl@0: my $filename = "usbfile" . $i . ".dat"; sl@0: print "Reading $filename\r"; sl@0: move("$drive" . $filename, $filename); sl@0: } sl@0: print "\n"; sl@0: return (time() - $start); sl@0: } sl@0: sl@0: sub create_files sl@0: { sl@0: for (my $i = 1; $i <= $files; $i++) sl@0: { sl@0: my $filename = "usbfile" . $i . ".dat"; sl@0: print "Creating file $filename\r"; sl@0: open FILE, ">$filename " or die $!; sl@0: my $fills = ($size * 1024 * 1024) / 64; sl@0: my $j = 0; sl@0: while ($j++ < $fills) sl@0: { sl@0: # Add 64 characters at a time sl@0: print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!' or die $!; sl@0: } sl@0: close FILE; sl@0: } sl@0: print "\n"; sl@0: } sl@0: sl@0: sub delete_files sl@0: { sl@0: for (my $i = 1; $i <= $files; $i++) sl@0: { sl@0: my $filename = "usbfile" . $i . ".dat"; sl@0: unlink $filename; sl@0: } sl@0: } sl@0: sl@0: ###################################################################### sl@0: sl@0: __END__ sl@0: sl@0: =head1 NAME sl@0: sl@0: usbperformance_multifile.pl - Create 100 files and write them to a Mass Storage device or sl@0: read them back. sl@0: sl@0: =head1 SYNOPSIS sl@0: sl@0: Usage: usbperformance_multifile.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 2 sl@0: sl@0: =item --help sl@0: sl@0: Displays this help. 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 files on the remote disk, but 'Read' will sl@0: delete them (moving them 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