os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbperformance_multifile.pl
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbperformance_multifile.pl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,193 @@
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_multifile - write 100 files to / read them 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 a target drive.\n") if (@ARGV < 1);
1.31 +
1.32 +my $help = 0;
1.33 +my $size = 4; # size of a single file in MB
1.34 +my $files = 100; # total number of files
1.35 +my $reading = 0;
1.36 +
1.37 +my %opts = ('help' => \$help,
1.38 + 'read=s' => \$reading);
1.39 +
1.40 +GetOptions(%opts) || pod2usage(2);
1.41 +pod2usage(-exitval => 1, -verbose => 2) if $help;
1.42 +
1.43 +my $drive = $ARGV[@ARGV - 1];
1.44 +$drive =~ s/\\/\//g;
1.45 +$drive .= "/" unless ($drive =~ m/\/$/);
1.46 +print "Remote drive: " . $drive . "\n";
1.47 +
1.48 +# If set to nonzero $¦ forces a flush right away and after every write or print
1.49 +# on the currently selected output channel.
1.50 +$¦ = 1;
1.51 +
1.52 +if ($reading == 0)
1.53 +{
1.54 + print "Writing $files $size-MB files to the remote directory.\n";
1.55 + print "Creating source files...\n";
1.56 + create_files();
1.57 + print "Writing target files...\n";
1.58 + my $write_time = write_files();
1.59 + print "File write took $write_time seconds.\n";
1.60 + printf "That's about %.2f MB/s.\n", ($size * $files / $write_time);
1.61 +}
1.62 +else
1.63 +{
1.64 + print "Reading files back from remote directory.\n";
1.65 + print "Reading source files...\n";
1.66 + my $read_time = read_files();
1.67 + print "File read took $read_time seconds.\n";
1.68 + printf "That's about %.2f MB/s.\n", ($size * $files / $read_time);
1.69 + delete_files();
1.70 +}
1.71 +
1.72 +
1.73 +# --- subs
1.74 +
1.75 +sub write_files
1.76 +{
1.77 + my $start = time();
1.78 + for (my $i = 1; $i <= $files; $i++)
1.79 + {
1.80 + my $filename = "usbfile" . $i . ".dat";
1.81 + print "Writig $filename\r";
1.82 + move($filename, "$drive" . $filename);
1.83 + }
1.84 + print "\n";
1.85 + return (time() - $start);
1.86 +}
1.87 +
1.88 +sub read_files
1.89 +{
1.90 + my $start = time();
1.91 + for (my $i = 1; $i <= $files; $i++)
1.92 + {
1.93 + my $filename = "usbfile" . $i . ".dat";
1.94 + print "Reading $filename\r";
1.95 + move("$drive" . $filename, $filename);
1.96 + }
1.97 + print "\n";
1.98 + return (time() - $start);
1.99 +}
1.100 +
1.101 +sub create_files
1.102 +{
1.103 + for (my $i = 1; $i <= $files; $i++)
1.104 + {
1.105 + my $filename = "usbfile" . $i . ".dat";
1.106 + print "Creating file $filename\r";
1.107 + open FILE, ">$filename " or die $!;
1.108 + my $fills = ($size * 1024 * 1024) / 64;
1.109 + my $j = 0;
1.110 + while ($j++ < $fills)
1.111 + {
1.112 + # Add 64 characters at a time
1.113 + print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!' or die $!;
1.114 + }
1.115 + close FILE;
1.116 + }
1.117 + print "\n";
1.118 +}
1.119 +
1.120 +sub delete_files
1.121 +{
1.122 + for (my $i = 1; $i <= $files; $i++)
1.123 + {
1.124 + my $filename = "usbfile" . $i . ".dat";
1.125 + unlink $filename;
1.126 + }
1.127 +}
1.128 +
1.129 +######################################################################
1.130 +
1.131 +__END__
1.132 +
1.133 +=head1 NAME
1.134 +
1.135 +usbperformance_multifile.pl - Create 100 files and write them to a Mass Storage device or
1.136 + read them back.
1.137 +
1.138 +=head1 SYNOPSIS
1.139 +
1.140 +Usage: usbperformance_multifile.pl [options] <USB drive>
1.141 +
1.142 +<USB drive>: The path to / drive letter of the USB Mass Storage device.
1.143 +
1.144 +=head1 OPTIONS
1.145 +
1.146 +=over 2
1.147 +
1.148 +=item --help
1.149 +
1.150 +Displays this help.
1.151 +
1.152 +=item --read=<0/1>
1.153 +
1.154 +0 to write
1.155 +1 to read
1.156 +
1.157 +Default value if no option given is 0 (write).
1.158 +
1.159 +Ensure the card/device has been ejected and thus flushed before you do the
1.160 +reading test after the writing case, otherwise the content will be cached by
1.161 +the local OS and the time measured won't be realistic.
1.162 +
1.163 +'Write' will leave the transferred files on the remote disk, but 'Read' will
1.164 +delete them (moving them to the local PC). So a practical test order is:
1.165 +
1.166 +'Write' test, then disconnect/re-connect USB drive, then 'Read' test.
1.167 +
1.168 +This sequence will start and finish with an empty USB disk.
1.169 +
1.170 +=back
1.171 +
1.172 +=head1 DESCRIPTION
1.173 +
1.174 +This is a simple utility to create a file on a mass storage unit and measure
1.175 +the performance in MB / seconds of the USB connection.
1.176 +
1.177 +=head2 Test Case Specification
1.178 +
1.179 + TestCaseID: PBASE-PREQ709-0045-Performance
1.180 + TestType: IT
1.181 + TestCaseDesc: Test Mass Storage performance on different platforms
1.182 + (Windows 2000/XP/ME, MacOS) (Manual test)
1.183 +
1.184 + TestActions:
1.185 +
1.186 +Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB
1.187 +cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD
1.188 +card) onto the PC. Execute this script on the PC, and make sure the card has
1.189 +free space for the file that is going to be created. The default size is 400
1.190 +MB.
1.191 +
1.192 +=head1 COPYRIGHT
1.193 +
1.194 +Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.195 +
1.196 +=cut