1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbperformance.pl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,181 @@
1.4 +#!/usr/bin/perl -w
1.5 +# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +# All rights reserved.
1.7 +# This component and the accompanying materials are made available
1.8 +# under the terms of the License "Eclipse Public License v1.0"
1.9 +# which accompanies this distribution, and is available
1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +#
1.12 +# Initial Contributors:
1.13 +# Nokia Corporation - initial contribution.
1.14 +#
1.15 +# Contributors:
1.16 +#
1.17 +# Description:
1.18 +# USBperformance - write file to / read file from
1.19 +# a USB Mass Storage device,
1.20 +# measure the time taken,
1.21 +# and display the data rate achieved.
1.22 +#
1.23 +#
1.24 +
1.25 +use strict;
1.26 +use File::Copy;
1.27 +use Getopt::Long;
1.28 +use Pod::Usage;
1.29 +
1.30 +pod2usage("$0: Specify at least a target drive.\n") if (@ARGV < 1);
1.31 +
1.32 +my $help = 0;
1.33 +my $size = 400;
1.34 +my $reading = 0;
1.35 +my $local_file = "gobble.dat";
1.36 +
1.37 +my %opts = ('help' => \$help,
1.38 + 'size=s' => \$size,
1.39 + 'read=s' => \$reading);
1.40 +
1.41 +GetOptions(%opts) || pod2usage(2);
1.42 +pod2usage(-exitval => 1, -verbose => 2) if $help;
1.43 +
1.44 +$size = 1 if $size < 1;
1.45 +
1.46 +my $drive = $ARGV[@ARGV - 1];
1.47 +$drive =~ s/\\/\//g;
1.48 +$drive .= "/" unless ($drive =~ m/\/$/);
1.49 +print "Remote drive: " . $drive . "\n";
1.50 +
1.51 +my $remote_file = "$drive$local_file";
1.52 +
1.53 +# If set to nonzero $¦ forces a flush right away and after every write or print
1.54 +# on the currently selected output channel.
1.55 +$¦ = 1;
1.56 +
1.57 +if ($reading == 0)
1.58 +{
1.59 + print "Writing a $size MB file to the remote directory.\n";
1.60 + print "Creating source file \"$local_file\"...\n";
1.61 + create_gobblefile();
1.62 + print "Writing target file \"$remote_file\"...\n";
1.63 + my $write_time = writefile();
1.64 + print "File write took $write_time seconds.\n";
1.65 + printf "That's about %.2f MB/s.\n", ($size / $write_time);
1.66 +}
1.67 +else
1.68 +{
1.69 + print "Reading file from a remote directory.\n";
1.70 + -e $remote_file or die "Remote file \"$remote_file\" doesn't seem to exist";
1.71 + -z $remote_file and die "Remote file \"$remote_file\" seems to be empty";
1.72 + my $size_bytes = -s $remote_file;
1.73 + $size = $size_bytes / 1024 / 1024;
1.74 + print "Reading source file \"$remote_file\" ($size_bytes bytes = $size MB)...\n";
1.75 + my $read_time = readfile();
1.76 + print "File read took $read_time seconds.\n";
1.77 + printf "That's about %.2f MB/s.\n", ($size / $read_time);
1.78 + unlink $local_file;
1.79 +}
1.80 +
1.81 +
1.82 +# --- subs
1.83 +
1.84 +sub writefile
1.85 +{
1.86 + my $start = time();
1.87 + move($local_file, $remote_file);
1.88 + return (time() - $start);
1.89 +}
1.90 +
1.91 +sub readfile
1.92 + {
1.93 + my $start = time();
1.94 + move($remote_file, $local_file);
1.95 + return (time() - $start);
1.96 + }
1.97 +
1.98 +sub create_gobblefile
1.99 +{
1.100 + open FILE, ">$local_file " or die $!;
1.101 + my $realsize = ($size * 1024 * 1024) / 40;
1.102 + my $i = 0;
1.103 + while ($i++ < $realsize)
1.104 + {
1.105 + # Add 40 characters
1.106 + print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd' or die $!;
1.107 + }
1.108 + close FILE;
1.109 +}
1.110 +
1.111 +######################################################################
1.112 +
1.113 +__END__
1.114 +
1.115 +=head1 NAME
1.116 +
1.117 +usbperformance.pl - Create a large file and write it to a Mass Storage device, or
1.118 + read it back.
1.119 +
1.120 +=head1 SYNOPSIS
1.121 +
1.122 +Usage: usbperformance.pl [options] <USB drive>
1.123 +
1.124 +<USB drive>: The path to / drive letter of the USB Mass Storage device.
1.125 +
1.126 +=head1 OPTIONS
1.127 +
1.128 +=over 3
1.129 +
1.130 +=item --help
1.131 +
1.132 +Displays this help.
1.133 +
1.134 +=item --size=<size>
1.135 +
1.136 +The size of the file to be created to measure the speed connection.
1.137 +
1.138 +Size is expected in MB. Default value if no option given is 400 MB.
1.139 +
1.140 +=item --read=<0/1>
1.141 +
1.142 +0 to write
1.143 +1 to read
1.144 +
1.145 +Default value if no option given is 0 (write).
1.146 +
1.147 +Ensure the card/device has been ejected and thus flushed before you do the
1.148 +reading test after the writing case, otherwise the content will be cached by
1.149 +the local OS and the time measured won't be realistic.
1.150 +
1.151 +'Write' will leave the transferred file on the remote disk, but 'Read' will
1.152 +delete it (moving it to the local PC). So a practical test order is:
1.153 +
1.154 +'Write' test, then disconnect/re-connect USB drive, then 'Read' test.
1.155 +
1.156 +This sequence will start and finish with an empty USB disk.
1.157 +
1.158 +=back
1.159 +
1.160 +=head1 DESCRIPTION
1.161 +
1.162 +This is a simple utility to create a file on a mass storage unit and measure
1.163 +the performance in MB / seconds of the USB connection.
1.164 +
1.165 +=head2 Test Case Specification
1.166 +
1.167 + TestCaseID: PBASE-PREQ709-0045-Performance
1.168 + TestType: IT
1.169 + TestCaseDesc: Test Mass Storage performance on different platforms
1.170 + (Windows 2000/XP/ME, MacOS) (Manual test)
1.171 +
1.172 + TestActions:
1.173 +
1.174 +Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB
1.175 +cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD
1.176 +card) onto the PC. Execute this script on the PC, and make sure the card has
1.177 +free space for the file that is going to be created. The default size is 400
1.178 +MB.
1.179 +
1.180 +=head1 COPYRIGHT
1.181 +
1.182 + Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.183 +
1.184 +=cut