author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 39 | 2bb754abd467 |
parent 6 | 0173bcd7697c |
permissions | -rw-r--r-- |
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 |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
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_multifile - write 100 files to / read them 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 a target drive.\n") if (@ARGV < 1); |
|
41 |
||
42 |
my $help = 0; |
|
43 |
my $drive = ""; |
|
44 |
my $size = 4; # size of a single file in MB |
|
45 |
my $files = 100; # total number of files |
|
46 |
my $reading = 0; |
|
47 |
my $logfile = ""; |
|
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 |
'read=s' => \$reading, |
|
64 |
'files=i' => \$files, |
|
65 |
'size=i' => \$size, |
|
66 |
'logfile=s' => \$logfile); |
|
67 |
||
68 |
GetOptions(%opts) || pod2usage(2); |
|
69 |
pod2usage(-exitval => 1, -verbose => 2) if $help; |
|
70 |
||
71 |
$size = 1 if $size < 1; |
|
72 |
$files = 1 if $files < 1; |
|
73 |
||
74 |
# Check OS |
|
75 |
# ME : "Windows" "4.90" |
|
76 |
# 2k : "Windows NT" "5.0" |
|
77 |
# XP : "Windows NT" "5.1" |
|
78 |
# Mac: "Darwin" "7.4.1" |
|
79 |
LogPrint("START - usbperformance_multifile.pl\n"); |
|
80 |
LogPrint("drive=$drive files=$files size=$size read=$reading\n"); |
|
81 |
LogPrint((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n"); |
|
82 |
if (not $TimeHiRes) |
|
83 |
{ |
|
84 |
LogPrint("!WARNING! Package Time::HiRes is not installed\n"); |
|
85 |
} |
|
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 $files $size-MB files to the remote directory.\n"); |
|
94 |
LogPrint("Creating source files...\n"); |
|
95 |
create_files(); |
|
96 |
LogPrint("Writing target files...\n"); |
|
97 |
my $write_time = write_files(); |
|
98 |
LogPrint("File write took $write_time ms.\n"); |
|
99 |
} |
|
100 |
else |
|
101 |
{ |
|
102 |
LogPrint("Reading files back from remote directory.\n"); |
|
103 |
LogPrint("Reading source files...\n"); |
|
104 |
my $read_time = read_files(); |
|
105 |
LogPrint("File read took $read_time ms.\n"); |
|
106 |
delete_files(); |
|
107 |
} |
|
108 |
||
109 |
Leave($returncode); |
|
110 |
exit $KErrOther; |
|
111 |
||
112 |
# --- subs |
|
113 |
||
114 |
sub Leave |
|
115 |
{ |
|
116 |
my ($errcode) = @_; |
|
117 |
LogPrint("END - usbperformance_multifile.pl - return code:$errcode\n"); |
|
118 |
exit $errcode |
|
119 |
} |
|
120 |
||
121 |
sub LogPrint |
|
122 |
{ |
|
123 |
if ($logfile ne "") |
|
124 |
{ |
|
125 |
open LOGFILE, ">>$logfile" or exit $KErrLogFile; |
|
126 |
print LOGFILE @_; |
|
127 |
close LOGFILE; |
|
128 |
} |
|
129 |
print @_; |
|
130 |
} |
|
131 |
||
132 |
sub write_files |
|
133 |
{ |
|
134 |
my ($start, $end, $duration); |
|
135 |
if ($TimeHiRes) |
|
136 |
{ |
|
137 |
$start = Time::HiRes::time(); |
|
138 |
} |
|
139 |
else |
|
140 |
{ |
|
141 |
$start = time(); |
|
142 |
} |
|
143 |
for (my $i = 1; $i <= $files; $i++) |
|
144 |
{ |
|
145 |
my $filename = "usbfile" . $i . ".dat"; |
|
146 |
move($filename, "$drive" . $filename) or Leave($KErrWriteFile); |
|
147 |
} |
|
148 |
if ($TimeHiRes) |
|
149 |
{ |
|
150 |
$end = Time::HiRes::time(); |
|
151 |
} |
|
152 |
else |
|
153 |
{ |
|
154 |
$end = time(); |
|
155 |
} |
|
156 |
# Duration in ms |
|
157 |
$duration = int(1000 * ($end - $start)); |
|
158 |
return ($duration); |
|
159 |
} |
|
160 |
||
161 |
sub read_files |
|
162 |
{ |
|
163 |
my ($start, $end, $duration); |
|
164 |
if ($TimeHiRes) |
|
165 |
{ |
|
166 |
$start = Time::HiRes::time(); |
|
167 |
} |
|
168 |
else |
|
169 |
{ |
|
170 |
$start = time(); |
|
171 |
} |
|
172 |
for (my $i = 1; $i <= $files; $i++) |
|
173 |
{ |
|
174 |
my $filename = "usbfile" . $i . ".dat"; |
|
175 |
move("$drive" . $filename, $filename) or Leave($KErrReadFile); |
|
176 |
} |
|
177 |
if ($TimeHiRes) |
|
178 |
{ |
|
179 |
$end = Time::HiRes::time(); |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
$end = time(); |
|
184 |
} |
|
185 |
# Duration in ms |
|
186 |
$duration = int(1000 * ($end - $start)); |
|
187 |
return ($duration); |
|
188 |
} |
|
189 |
||
190 |
sub create_files |
|
191 |
{ |
|
192 |
for (my $i = 1; $i <= $files; $i++) |
|
193 |
{ |
|
194 |
my $filename = "usbfile" . $i . ".dat"; |
|
195 |
LogPrint "Creating file $filename\n"; |
|
196 |
if (not open FILE, ">$filename ") |
|
197 |
{ |
|
198 |
LogPrint("Can't write to $filename: $!\n"); |
|
199 |
Leave($KErrWriteFile); |
|
200 |
} |
|
201 |
my $fills = ($size * 1024 * 1024) / 64; |
|
202 |
my $j = 0; |
|
203 |
while ($j++ < $fills) |
|
204 |
{ |
|
205 |
# Add 64 characters at a time |
|
206 |
if (not print FILE '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!') |
|
207 |
{ |
|
208 |
LogPrint("Can't write to $filename: $!\n"); |
|
209 |
Leave($KErrWriteFile); |
|
210 |
} |
|
211 |
} |
|
212 |
close FILE; |
|
213 |
} |
|
214 |
print "\n"; |
|
215 |
} |
|
216 |
||
217 |
sub delete_files |
|
218 |
{ |
|
219 |
for (my $i = 1; $i <= $files; $i++) |
|
220 |
{ |
|
221 |
my $filename = "usbfile" . $i . ".dat"; |
|
222 |
unlink $filename; |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
###################################################################### |
|
227 |
||
228 |
__END__ |
|
229 |
||
230 |
=head1 NAME |
|
231 |
||
232 |
usbperformance_multifile.pl - Create 100 files and write them to a Mass Storage device or |
|
233 |
read them back. |
|
234 |
||
235 |
=head1 SYNOPSIS |
|
236 |
||
237 |
Usage: usbperformance_multifile.pl [options] |
|
238 |
||
239 |
=head1 OPTIONS |
|
240 |
||
241 |
=over 2 |
|
242 |
||
243 |
=item --help |
|
244 |
||
245 |
Displays this help. |
|
246 |
||
247 |
=item --drive=<drive> |
|
248 |
||
249 |
The path to / drive letter of the USB Mass Storage device. |
|
250 |
||
251 |
=item --read=<0/1> |
|
252 |
||
253 |
0 to write |
|
254 |
1 to read |
|
255 |
||
256 |
Default value if no option given is 0 (write). |
|
257 |
||
258 |
Ensure the card/device has been ejected and thus flushed before you do the |
|
259 |
reading test after the writing case, otherwise the content will be cached by |
|
260 |
the local OS and the time measured won't be realistic. |
|
261 |
||
262 |
'Write' will leave the transferred files on the remote disk, but 'Read' will |
|
263 |
delete them (moving them to the local PC). So a practical test order is: |
|
264 |
||
265 |
'Write' test, then disconnect/re-connect USB drive, then 'Read' test. |
|
266 |
||
267 |
This sequence will start and finish with an empty USB disk. |
|
268 |
||
269 |
=item --files=<number of files> |
|
270 |
||
271 |
The number of file to write to the device (default: 100) |
|
272 |
||
273 |
=item --size=<file size> |
|
274 |
||
275 |
Size of files in MB (default: 4) |
|
276 |
||
277 |
=item --logfile=<file> |
|
278 |
||
279 |
Append test output to specified file. |
|
280 |
||
281 |
=back |
|
282 |
||
283 |
=head1 DESCRIPTION |
|
284 |
||
285 |
This is a simple utility to create a file on a mass storage unit and measure |
|
286 |
the performance in MB / seconds of the USB connection. |
|
287 |
||
288 |
=head2 Test Case Specification |
|
289 |
||
290 |
TestCaseID: PBASE-PREQ709-0045-Performance |
|
291 |
TestType: IT |
|
292 |
TestCaseDesc: Test Mass Storage performance on different platforms |
|
293 |
(Windows 2000/XP/ME, MacOS) (Manual test) |
|
294 |
||
295 |
TestActions: |
|
296 |
||
297 |
Build a ROM with usbmsapp.exe on it. Connect the board to the PC with an USB |
|
298 |
cable. Execute usbmsapp.exe on the device to map the mass storage unit (MMC/SD |
|
299 |
card) onto the PC. Execute this script on the PC, and make sure the card has |
|
300 |
free space for the file that is going to be created. The default size is 400 |
|
301 |
MB. |
|
302 |
||
303 |
=cut |