0
|
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 - write file to / read file 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 POSIX;
|
|
24 |
use File::Copy;
|
|
25 |
use Getopt::Long;
|
|
26 |
use Pod::Usage;
|
|
27 |
|
|
28 |
# Check if Time::HiRes package is installed
|
|
29 |
my $TimeHiRes = 1;
|
|
30 |
eval
|
|
31 |
{
|
|
32 |
require Time::HiRes;
|
|
33 |
};
|
|
34 |
if ($@)
|
|
35 |
{
|
|
36 |
# Not installed
|
|
37 |
$TimeHiRes = 0;
|
|
38 |
}
|
|
39 |
|
|
40 |
pod2usage("$0: Specify at least a target drive.\n") if (@ARGV < 1);
|
|
41 |
|
|
42 |
my $help = 0;
|
|
43 |
my $drive = "";
|
|
44 |
my $size = 400;
|
|
45 |
my $reading = 0;
|
|
46 |
my $logfile = "";
|
|
47 |
my $local_file = "gobble.dat";
|
|
48 |
|
|
49 |
# Error codes
|
|
50 |
my $KErrNone = 0; # No error - Test passed
|
|
51 |
my $KErrLogFile = -1; # Can't open log file
|
|
52 |
my $KErrWriteFile = -2; # Can't open file for writing
|
|
53 |
my $KErrReadFile = -3; # Can't open file for reading
|
|
54 |
my $KErrRmFile = -4; # Can't remove file
|
|
55 |
my $KErrRmDir = -5; # Can't remove directory
|
|
56 |
my $KErrCmp = -6; # File comparison failed
|
|
57 |
my $KErrOther = -7; # Other
|
|
58 |
|
|
59 |
my $returncode = $KErrNone;
|
|
60 |
|
|
61 |
my %opts = ('help' => \$help,
|
|
62 |
'drive=s' => \$drive,
|
|
63 |
'size=s' => \$size,
|
|
64 |
'read=s' => \$reading,
|
|
65 |
'logfile=s'=> \$logfile);
|
|
66 |
|
|
67 |
GetOptions(%opts) || pod2usage(2);
|
|
68 |
pod2usage(-exitval => 1, -verbose => 2) if $help;
|
|
69 |
|
|
70 |
$size = 1 if $size < 1;
|
|
71 |
|
|
72 |
# Check OS
|
|
73 |
# ME : "Windows" "4.90"
|
|
74 |
# 2k : "Windows NT" "5.0"
|
|
75 |
# XP : "Windows NT" "5.1"
|
|
76 |
# Mac: "Darwin" "7.4.1"
|
|
77 |
LogPrint("START - usbperformance.pl\n");
|
|
78 |
LogPrint("drive=$drive size=$size read=$reading\n");
|
|
79 |
LogPrint((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n");
|
|
80 |
if (not $TimeHiRes)
|
|
81 |
{
|
|
82 |
LogPrint("!WARNING! Package Time::HiRes is not installed\n");
|
|
83 |
}
|
|
84 |
|
|
85 |
my $remote_file = "$drive$local_file";
|
|
86 |
|
|
87 |
# If set to nonzero $¦ forces a flush right away and after every write or print
|
|
88 |
# on the currently selected output channel.
|
|
89 |
$¦ = 1;
|
|
90 |
|
|
91 |
if ($reading == 0)
|
|
92 |
{
|
|
93 |
LogPrint("Writing a $size MB file to the remote directory.\n");
|
|
94 |
LogPrint("Creating source file \"$local_file\"...\n");
|
|
95 |
create_gobblefile();
|
|
96 |
LogPrint("Writing target file \"$remote_file\"...\n");
|
|
97 |
my $write_time = writefile();
|
|
98 |
LogPrint("File write took $write_time ms.\n");
|
|
99 |
}
|
|
100 |
else
|
|
101 |
{
|
|
102 |
LogPrint("Reading file from a remote directory.\n");
|
|
103 |
if (not -e $remote_file)
|
|
104 |
{
|
|
105 |
LogPrint("Remote file \"$remote_file\" doesn't seem to exist\n");
|
|
106 |
Leave($KErrReadFile);
|
|
107 |
}
|
|
108 |
if (-z $remote_file)
|
|
109 |
{
|
|
110 |
LogPrint("Remote file \"$remote_file\" seems to be empty\n");
|
|
111 |
Leave($KErrReadFile);
|
|
112 |
}
|
|
113 |
my $size_bytes = -s $remote_file;
|
|
114 |
$size = $size_bytes / 1024 / 1024;
|
|
115 |
LogPrint("Reading source file \"$remote_file\" ($size_bytes bytes = $size MB)...\n");
|
|
116 |
my $read_time = readfile();
|
|
117 |
LogPrint("File read took $read_time ms.\n");
|
|
118 |
unlink $local_file;
|
|
119 |
}
|
|
120 |
|
|
121 |
Leave($returncode);
|
|
122 |
exit $KErrOther;
|
|
123 |
|
|
124 |
# --- subs
|
|
125 |
|
|
126 |
sub Leave
|
|
127 |
{
|
|
128 |
my ($errcode) = @_;
|
|
129 |
LogPrint("END - usbperformance.pl - return code:$errcode\n");
|
|
130 |
exit $errcode
|
|
131 |
}
|
|
132 |
|
|
133 |
sub LogPrint
|
|
134 |
{
|
|
135 |
if ($logfile ne "")
|
|
136 |
{
|
|
137 |
open LOGFILE, ">>$logfile" or exit $KErrLogFile;
|
|
138 |
print LOGFILE @_;
|
|
139 |
close LOGFILE;
|
|
140 |
}
|
|
141 |
print @_;
|
|
142 |
}
|
|
143 |
|
|
144 |
sub writefile
|
|
145 |
{
|
|
146 |
my ($start, $end, $duration);
|
|
147 |
if ($TimeHiRes)
|
|
148 |
{
|
|
149 |
$start = Time::HiRes::time();
|
|
150 |
}
|
|
151 |
else
|
|
152 |
{
|
|
153 |
$start = time();
|
|
154 |
}
|
|
155 |
move($local_file, $remote_file) or Leave($KErrWriteFile);
|
|
156 |
if ($TimeHiRes)
|
|
157 |
{
|
|
158 |
$end = Time::HiRes::time();
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
$end = time();
|
|
163 |
}
|
|
164 |
# Duration in ms
|
|
165 |
$duration = int(1000 * ($end - $start));
|
|
166 |
return ($duration);
|
|
167 |
}
|
|
168 |
|
|
169 |
sub readfile
|
|
170 |
{
|
|
171 |
my ($start, $end, $duration);
|
|
172 |
if ($TimeHiRes)
|
|
173 |
{
|
|
174 |
$start = Time::HiRes::time();
|
|
175 |
}
|
|
176 |
else
|
|
177 |
{
|
|
178 |
$start = time();
|
|
179 |
}
|
|
180 |
move($remote_file, $local_file) or Leave($KErrReadFile);
|
|
181 |
if ($TimeHiRes)
|
|
182 |
{
|
|
183 |
$end = Time::HiRes::time();
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
$end = time();
|
|
188 |
}
|
|
189 |
# Duration in ms
|
|
190 |
$duration = int(1000 * ($end - $start));
|
|
191 |
return ($duration);
|
|
192 |
}
|
|
193 |
|
|
194 |
sub create_gobblefile
|
|
195 |
{
|
|
196 |
if (not open FILE, ">$local_file ")
|
|
197 |
{
|
|
198 |
LogPrint "Can't create file: $!";
|
|
199 |
Leave($KErrWriteFile);
|
|
200 |
}
|
|
201 |
my $realsize = ($size * 1024);
|
|
202 |
my $i = 0;
|
|
203 |
while ($i++ < $realsize)
|
|
204 |
{
|
|
205 |
# Add a 1024-byte block
|
|
206 |
if (not print FILE '012345ABCDEFGHIJKLMNOPQRSTUVWXYZ'x32)
|
|
207 |
{
|
|
208 |
LogPrint("Write error: $!\n");
|
|
209 |
Leave($KErrWriteFile);
|
|
210 |
}
|
|
211 |
}
|
|
212 |
close FILE;
|
|
213 |
}
|
|
214 |
|
|
215 |
######################################################################
|
|
216 |
|
|
217 |
__END__
|
|
218 |
|
|
219 |
=head1 NAME
|
|
220 |
|
|
221 |
usbperformance.pl - Create a large file and write it to a Mass Storage device, or
|
|
222 |
read it back.
|
|
223 |
|
|
224 |
=head1 SYNOPSIS
|
|
225 |
|
|
226 |
Usage: usbperformance.pl [options]
|
|
227 |
|
|
228 |
=head1 OPTIONS
|
|
229 |
|
|
230 |
=over 3
|
|
231 |
|
|
232 |
=item --help
|
|
233 |
|
|
234 |
Displays this help.
|
|
235 |
|
|
236 |
=item --drive=<drive>
|
|
237 |
|
|
238 |
The path to / drive letter of the USB Mass Storage device.
|
|
239 |
|
|
240 |
=item --size=<size>
|
|
241 |
|
|
242 |
The size of the file to be created to measure the speed connection.
|
|
243 |
|
|
244 |
Size is expected in MB. Default value if no option given is 400 MB.
|
|
245 |
|
|
246 |
=item --read=<0/1>
|
|
247 |
|
|
248 |
0 to write
|
|
249 |
1 to read
|
|
250 |
|
|
251 |
Default value if no option given is 0 (write).
|
|
252 |
|
|
253 |
Ensure the card/device has been ejected and thus flushed before you do the
|
|
254 |
reading test after the writing case, otherwise the content will be cached by
|
|
255 |
the local OS and the time measured won't be realistic.
|
|
256 |
|
|
257 |
'Write' will leave the transferred file on the remote disk, but 'Read' will
|
|
258 |
delete it (moving it to the local PC). So a practical test order is:
|
|
259 |
|
|
260 |
'Write' test, then disconnect/re-connect USB drive, then 'Read' test.
|
|
261 |
|
|
262 |
This sequence will start and finish with an empty USB disk.
|
|
263 |
|
|
264 |
=item --logfile=<file>
|
|
265 |
|
|
266 |
Append test output to specified file.
|
|
267 |
|
|
268 |
=back
|
|
269 |
|
|
270 |
=head1 DESCRIPTION
|
|
271 |
|
|
272 |
This is a simple utility to create a file on a mass storage unit and measure
|
|
273 |
the performance in MB / seconds of the USB connection.
|
|
274 |
|
|
275 |
=head2 Test Case Specification
|
|
276 |
|
|
277 |
TestCaseID: PBASE-PREQ709-0045-Performance
|
|
278 |
TestType: IT
|
|
279 |
TestCaseDesc: Test Mass Storage performance on different platforms
|
|
280 |
(Windows 2000/XP/ME, MacOS) (Manual test)
|
|
281 |
|
|
282 |
TestActions:
|
|
283 |
|
|
284 |
Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB
|
|
285 |
cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD
|
|
286 |
card) onto the PC. Execute this script on the PC, and make sure the card has
|
|
287 |
free space for the file that is going to be created. The default size is 400
|
|
288 |
MB.
|
|
289 |
|
|
290 |
=head1 COPYRIGHT
|
|
291 |
|
|
292 |
Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
|
293 |
|
|
294 |
=cut
|