author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 15:02:23 +0300 | |
changeset 152 | 657f875b013e |
parent 90 | 947f0dc9f7a8 |
child 200 | 73ea206103e6 |
permissions | -rw-r--r-- |
0 | 1 |
#!perl -w |
2 |
# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
# All rights reserved. |
|
4 |
# This component and the accompanying materials are made available |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
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 |
# USBinterop1 |
|
16 |
# |
|
17 |
# |
|
18 |
||
19 |
use strict; |
|
20 |
use Digest::MD5; |
|
21 |
use POSIX; |
|
22 |
use File::Path; |
|
23 |
use Getopt::Long; |
|
24 |
use Pod::Usage; |
|
25 |
||
26 |
my $spread = 3; |
|
27 |
my $depth = 1; |
|
28 |
my $drive = ""; |
|
29 |
my $rootfolder = ""; |
|
30 |
my $size = 1024; |
|
31 |
my $reading = 0; |
|
32 |
my $logfile = ""; |
|
33 |
my $help = 0; |
|
34 |
||
35 |
# Error codes |
|
36 |
my $KErrNone = 0; # No error - Test passed |
|
37 |
my $KErrLogFile = -1; # Can't open log file |
|
38 |
my $KErrWriteFile = -2; # Can't open file for writing |
|
39 |
my $KErrReadFile = -3; # Can't open file for reading |
|
40 |
my $KErrRmFile = -4; # Can't remove file |
|
41 |
my $KErrRmDir = -5; # Can't remove directory |
|
42 |
my $KErrCmp = -6; # File comparison failed |
|
43 |
my $KErrOther = -7; # Other |
|
44 |
my $KErrDirectory = -8; # Creating Directories |
|
45 |
my $KErrFormat = -9; # Format Device |
|
46 |
||
47 |
my $returncode = $KErrNone; |
|
48 |
||
49 |
my %opts = ( 'spread=i' => \$spread, |
|
50 |
'depth=i' => \$depth, |
|
51 |
'drive=s' => \$drive, |
|
52 |
'size=i' => \$size, |
|
53 |
'read=i' => \$reading, |
|
54 |
'logfile=s'=> \$logfile, |
|
55 |
'help!' => \$help); |
|
56 |
||
57 |
GetOptions(%opts) || pod2usage(2); |
|
58 |
pod2usage(-exitval => 1, -verbose => 2) if $help; |
|
59 |
||
60 |
$drive =~ s/\\/\//g; |
|
61 |
$rootfolder = $drive; |
|
62 |
$rootfolder .= "/" unless ($drive =~ m/\/$/); |
|
63 |
$spread = 1 if $spread < 1; |
|
64 |
$depth = 1 if $depth < 1; |
|
65 |
$size = 1 if $size < 1; |
|
66 |
||
67 |
# Check OS |
|
68 |
# ME : "Windows" "4.90" |
|
69 |
# 2k : "Windows NT" "5.0" |
|
70 |
# XP : "Windows NT" "5.1" |
|
71 |
# Mac: "Darwin" "7.4.1" |
|
72 |
LogPrint("START - usbinterop1.pl\n"); |
|
73 |
LogPrint("spread=$spread depth=$depth drive=$drive size=$size read=$reading\n"); |
|
74 |
LogPrint((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n"); |
|
75 |
||
76 |
# Set the random number seed |
|
77 |
srand(2008 * $spread * $depth); |
|
78 |
||
79 |
LogPrint("Generating Folder Names\n"); |
|
80 |
my @folders = createfolders($rootfolder, $spread, $depth); |
|
81 |
||
82 |
if ($reading == 0) |
|
83 |
{ |
|
84 |
LogPrint("Creating Folders\n"); |
|
85 |
foreach my $path (@folders) { |
|
86 |
next if -d $path; |
|
87 |
if (!mkdir($path)) { |
|
88 |
LogPrint("Error Creating Directory so formating device ".$drive."\n"); |
|
89 |
open (INPUTPIPE,"| format ".$drive." /FS:FAT") or Leave($KErrFormat); |
|
90 |
close (INPUTPIPE); |
|
91 |
LogPrint("Format complete\n"); |
|
92 |
$returncode = $KErrDirectory; |
|
93 |
last; |
|
94 |
} |
|
95 |
} |
|
96 |
if ($returncode == $KErrDirectory) { |
|
97 |
foreach my $path (@folders) { |
|
98 |
next if -d $path; |
|
99 |
Leave($KErrDirectory) if (!mkdir($path)); |
|
100 |
} |
|
101 |
} |
|
102 |
$returncode = $KErrNone; |
|
103 |
} |
|
104 |
||
105 |
LogPrint("Creating Files\n"); |
|
106 |
my %digests = createfiles(\@folders, $size, $spread); |
|
107 |
||
108 |
if ($reading == 1) |
|
109 |
{ |
|
110 |
LogPrint("Checking Files\n"); |
|
111 |
checkfiles(\%digests); |
|
112 |
LogPrint("Removing Files\n"); |
|
113 |
removefiles(\%digests); |
|
114 |
LogPrint("Removing Folders\n"); |
|
115 |
removefolders(\@folders); |
|
116 |
} |
|
117 |
||
118 |
Leave($returncode); |
|
119 |
exit $KErrOther; |
|
120 |
||
121 |
sub Leave |
|
122 |
{ |
|
123 |
my ($errcode) = @_; |
|
124 |
LogPrint("END - usbinterop1.pl - return code:$errcode\n"); |
|
125 |
exit $errcode |
|
126 |
} |
|
127 |
||
128 |
sub LogPrint |
|
129 |
{ |
|
130 |
if ($logfile ne "") |
|
131 |
{ |
|
132 |
open LOGFILE, ">>$logfile" or exit $KErrLogFile; |
|
133 |
print LOGFILE @_; |
|
134 |
close LOGFILE; |
|
135 |
} |
|
136 |
print @_; |
|
137 |
} |
|
138 |
||
139 |
sub createfolder |
|
140 |
{ |
|
141 |
my $dirlist = shift; |
|
142 |
my $fbase = shift; |
|
143 |
my $spread = shift; |
|
144 |
my $depth = shift; |
|
145 |
||
146 |
return unless $depth > 0; |
|
147 |
||
148 |
for (my $i = 0; $i < $spread; $i++) |
|
149 |
{ |
|
150 |
my $dir = sprintf("%sdir%05d/", $fbase, $i + 1); |
|
151 |
push @$dirlist, $dir; |
|
152 |
createfolder($dirlist, $dir, $spread, $depth - 1); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
sub createfolders |
|
157 |
{ |
|
158 |
my $drive = shift; |
|
159 |
$drive = "" unless defined $drive; |
|
160 |
my $spread = shift; |
|
161 |
$spread = 1 unless defined $spread; |
|
162 |
my $depth = shift; |
|
163 |
$depth = 1 unless defined $depth; |
|
164 |
||
165 |
my @dirlist = (); |
|
166 |
createfolder(\@dirlist, $drive, $spread, $depth); |
|
167 |
return @dirlist; |
|
168 |
} |
|
169 |
||
170 |
sub makeblock |
|
171 |
{ |
|
172 |
my $length = shift; |
|
173 |
my @list = (); |
|
174 |
for (my $i = 0; $i < $length; $i++) |
|
175 |
{ |
|
176 |
push @list, int((91 - 65) * rand()) + 65; |
|
177 |
} |
|
178 |
return pack "C$length", @list; |
|
179 |
} |
|
180 |
||
181 |
||
182 |
sub writefile |
|
183 |
{ |
|
184 |
my $file = shift; |
|
185 |
my $length = shift; |
|
186 |
my $block = 1024; |
|
187 |
if ($reading == 0) |
|
188 |
{ |
|
189 |
if (not open(FILE, ">$file")) |
|
190 |
{ |
|
191 |
LogPrint "Unable to open $file for writing: $!\n"; |
|
192 |
Leave($KErrWriteFile); |
|
193 |
} |
|
194 |
} |
|
195 |
my $md5 = Digest::MD5->new(); |
|
196 |
while ($length > 0) |
|
197 |
{ |
|
198 |
my $data = makeblock(($length > $block) ? $block : $length); |
|
199 |
$md5->add($data); |
|
200 |
if ($reading == 0) |
|
201 |
{ |
|
202 |
print(FILE $data); |
|
203 |
} |
|
204 |
$length -= $block; |
|
205 |
} |
|
206 |
if ($reading == 0) |
|
207 |
{ |
|
208 |
close(FILE); |
|
209 |
} |
|
210 |
return $md5->hexdigest(); |
|
211 |
} |
|
212 |
||
213 |
||
214 |
sub readfile |
|
215 |
{ |
|
216 |
my $file = shift; |
|
217 |
if (!sysopen(FILE, $file, O_RDONLY)) { |
|
218 |
LogPrint("Unable to open $file for reading: $!\n"); |
|
219 |
$returncode = $KErrReadFile unless($returncode); |
|
220 |
return ""; |
|
221 |
}; |
|
222 |
my $md5 = Digest::MD5->new(); |
|
223 |
$md5->addfile(*FILE); |
|
224 |
close(FILE); |
|
225 |
return $md5->hexdigest(); |
|
226 |
} |
|
227 |
||
228 |
||
229 |
sub createfiles |
|
230 |
{ |
|
231 |
my $dirlist = shift; |
|
232 |
my $size = shift; |
|
233 |
$size = 1024 unless defined $size; |
|
234 |
my $nfiles = shift; |
|
235 |
$nfiles = 1 unless defined $nfiles; |
|
236 |
||
237 |
my %digest; |
|
238 |
||
239 |
foreach (@$dirlist) |
|
240 |
{ |
|
241 |
for (my $i = 0; $i < $nfiles; $i++) |
|
242 |
{ |
|
243 |
my $file = sprintf("${_}file%04d.txt", $i + 1); |
|
244 |
$digest{$file} = writefile($file, $size); |
|
245 |
} |
|
246 |
} |
|
247 |
return %digest; |
|
248 |
} |
|
249 |
||
250 |
sub checkfiles |
|
251 |
{ |
|
252 |
my $digests = shift; |
|
253 |
||
254 |
foreach (sort keys %$digests) |
|
255 |
{ |
|
256 |
my $readDigest = readfile($_); |
|
257 |
if ($readDigest) { |
|
258 |
if ($digests->{$_} ne $readDigest) |
|
259 |
{ |
|
260 |
LogPrint "$_\t" . "ERROR" . "\t$digests->{$_}\t$readDigest" . "\n"; |
|
261 |
$returncode = $KErrCmp unless($returncode); |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
||
268 |
sub removefiles |
|
269 |
{ |
|
270 |
my $digests = shift; |
|
271 |
my @cant = grep {not unlink} (keys %$digests); |
|
272 |
if (@cant) |
|
273 |
{ |
|
274 |
LogPrint "Unable to remove @cant\n"; |
|
275 |
$returncode = $KErrRmFile unless($returncode); |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
||
280 |
sub removefolders |
|
281 |
{ |
|
282 |
my $folders = shift; |
|
283 |
foreach (@$folders) |
|
284 |
{ |
|
285 |
if (-e) |
|
286 |
{ |
|
287 |
if (not rmtree($_)) |
|
288 |
{ |
|
289 |
LogPrint "Unable to remove $_: $!\n"; |
|
290 |
$returncode = $KErrRmDir unless($returncode); |
|
291 |
} |
|
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
###################################################################### |
|
297 |
||
298 |
__END__ |
|
299 |
||
300 |
=head1 NAME |
|
301 |
||
302 |
usbinterop1.pl - Create directories and files, read back and compare |
|
303 |
||
304 |
=head1 SYNOPSIS |
|
305 |
||
306 |
usage: usbinterop1.pl [options] |
|
307 |
||
308 |
=head1 OPTIONS |
|
309 |
||
310 |
=over 4 |
|
311 |
||
312 |
=item --spread=<number of directories and files> |
|
313 |
||
314 |
Spread is the number of directories and files that are created at each |
|
315 |
level of the created tree. For example, a spread of three would |
|
316 |
create three directories and three files in each of the directories. |
|
317 |
Spread is a measure of the "bushiness" of the directory tree. |
|
318 |
||
319 |
Default value is "3". |
|
320 |
||
321 |
=item --depth=<directory nesting level> |
|
322 |
||
323 |
Each directory can have subdirectories up to the limit of the depth |
|
324 |
parameter. Depth is a measure of the "height" of the directory tree. |
|
325 |
||
326 |
Default value is "1". |
|
327 |
||
328 |
=item --size=<size of files to create> |
|
329 |
||
330 |
The size in bytes for each test file. Be careful as the disk space |
|
331 |
used is a function of this parameter as well as the depth and spread |
|
332 |
parameters: |
|
333 |
||
334 |
total size = size*(sp^(dep+1)+sp^(dep)+sp^(dep-1)+..+sp^2) |
|
335 |
||
336 |
Default value is "1024". |
|
337 |
||
338 |
=item --drive=<USB drive location> |
|
339 |
||
340 |
The path to the USB drive in which to write the files. |
|
341 |
||
342 |
Default value is ".", the current working directory. |
|
343 |
||
344 |
=item --read=<0/1> |
|
345 |
||
346 |
0 to write |
|
347 |
1 to read |
|
348 |
||
349 |
Default value if no option given is 0 (write). |
|
350 |
||
351 |
Ensure the card/device has been ejected and thus flushed before you do the |
|
352 |
reading test after the writing case, otherwise the content will be cached by |
|
353 |
the local OS and the time measured won't be realistic. |
|
354 |
||
355 |
'Write' will leave the transferred files on the remote disk, but 'Read' will |
|
356 |
delete them (moving them to the local PC). So a practical test order is: |
|
357 |
||
358 |
'Write' test, then disconnect/re-connect USB drive, then 'Read' test. |
|
359 |
||
360 |
This sequence will start and finish with an empty USB disk. |
|
361 |
||
362 |
=item --logfile=<file> |
|
363 |
||
364 |
Append test output to specified file. |
|
365 |
||
366 |
=item --help=<file> |
|
367 |
||
368 |
Displays this help. |
|
369 |
||
370 |
=back |
|
371 |
||
372 |
=head1 DESCRIPTION |
|
373 |
||
374 |
This is a simple utility to create folders and files with varying |
|
375 |
levels of nesting and sizes on a USB drive, and read them back to |
|
376 |
verify their contents. |
|
377 |
||
378 |
=head2 Test Case Specification |
|
379 |
||
380 |
TestCaseID: Interoperability_1 |
|
381 |
TestType: IT |
|
382 |
TestCaseDesc: Test Mass Storage functionality on different platforms |
|
383 |
(Windows 2000/XP/ME, MacOS) (Manual test) |
|
384 |
FssID: Base/emstore/1.1.1 |
|
385 |
FssID: Base/emstore/3.1.1 |
|
386 |
||
387 |
TestActions: |
|
388 |
Connect device to a host PC. Enable MS. Start perl script on |
|
389 |
PC. This script formats drive and creates several folders with |
|
390 |
levels of nested folders and writes set of files to them. File sizes |
|
391 |
varied from several kilobytes to several megabytes. The number of |
|
392 |
folders, nest depth, number of files placed in each folder and there |
|
393 |
sizes should be configurable. Then script prompt ask to unplug/plug |
|
394 |
USB cable (to flash OS read cache) and then read all files back and |
|
395 |
compare. |
|
396 |
||
397 |
TestExpectedResults: |
|
398 |
Read data from files should match with written. |
|
399 |
||
400 |
=head1 COPYRIGHT |
|
401 |
||
402 |
Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
403 |
||
404 |
=cut |