author | mikek |
Wed, 16 Jun 2010 12:59:18 +0100 | |
branch | GCC_SURGE |
changeset 160 | 30e086416910 |
parent 90 | 947f0dc9f7a8 |
child 148 | 31ea0f8e3c99 |
child 152 | 657f875b013e |
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 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
5 |
# under the terms of "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 $size = 1024; |
|
30 |
my $pause = 1; |
|
31 |
my $help = 0; |
|
32 |
||
33 |
my %opts = ( 'spread=i' => \$spread, |
|
34 |
'depth=i' => \$depth, |
|
35 |
'drive=s' => \$drive, |
|
36 |
'size=i' => \$size, |
|
37 |
'pause!' => \$pause, |
|
38 |
'help!' => \$help); |
|
39 |
||
40 |
GetOptions(%opts) || pod2usage(2); |
|
41 |
pod2usage(-exitval => 1, -verbose => 2) if $help; |
|
42 |
||
43 |
$drive =~ s/\\/\//g; |
|
44 |
$drive .= "/" unless ($drive =~ m/\/$/); |
|
45 |
$spread = 1 if $spread < 1; |
|
46 |
$depth = 1 if $depth < 1; |
|
47 |
$size = 1 if $size < 1; |
|
48 |
||
49 |
# Check OS |
|
50 |
# ME : "Windows" "4.90" |
|
51 |
# 2k : "Windows NT" "5.0" |
|
52 |
# XP : "Windows NT" "5.1" |
|
53 |
# Mac: "Darwin" "7.4.1" |
|
54 |
print((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n"); |
|
55 |
||
56 |
my @folders = createfolders($drive, $spread, $depth); |
|
57 |
mkpath(\@folders); |
|
58 |
my %digests = createfiles(\@folders, $size, $spread); |
|
59 |
||
60 |
if ($pause) |
|
61 |
{ |
|
62 |
print "Unplug and replug the USB cable, then press enter..."; |
|
63 |
$pause = <STDIN>; |
|
64 |
} |
|
65 |
||
66 |
checkfiles(\%digests); |
|
67 |
removefiles(\%digests); |
|
68 |
removefolders(\@folders); |
|
69 |
||
70 |
||
71 |
||
72 |
sub createfolder |
|
73 |
{ |
|
74 |
my $dirlist = shift; |
|
75 |
my $fbase = shift; |
|
76 |
my $spread = shift; |
|
77 |
my $depth = shift; |
|
78 |
||
79 |
return unless $depth > 0; |
|
80 |
||
81 |
for (my $i = 0; $i < $spread; $i++) |
|
82 |
{ |
|
83 |
my $dir = sprintf("%sdir%05d/", $fbase, $i + 1); |
|
84 |
push @$dirlist, $dir; |
|
85 |
createfolder($dirlist, $dir, $spread, $depth - 1); |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
||
90 |
sub createfolders |
|
91 |
{ |
|
92 |
my $drive = shift; |
|
93 |
$drive = "" unless defined $drive; |
|
94 |
my $spread = shift; |
|
95 |
$spread = 1 unless defined $spread; |
|
96 |
my $depth = shift; |
|
97 |
$depth = 1 unless defined $depth; |
|
98 |
||
99 |
my @dirlist = (); |
|
100 |
createfolder(\@dirlist, $drive, $spread, $depth); |
|
101 |
return @dirlist; |
|
102 |
} |
|
103 |
||
104 |
sub makeblock |
|
105 |
{ |
|
106 |
my $length = shift; |
|
107 |
my @list = (); |
|
108 |
for (my $i = 0; $i < $length; $i++) |
|
109 |
{ |
|
110 |
push @list, int((91 - 65) * rand()) + 65; |
|
111 |
} |
|
112 |
return pack "C$length", @list; |
|
113 |
} |
|
114 |
||
115 |
||
116 |
sub writefile |
|
117 |
{ |
|
118 |
my $file = shift; |
|
119 |
my $length = shift; |
|
120 |
my $block = 1024; |
|
121 |
open(FILE, ">$file") or warn ("Unable to open $file for writing: $!\n"); |
|
122 |
my $md5 = Digest::MD5->new(); |
|
123 |
while ($length > 0) |
|
124 |
{ |
|
125 |
my $data = makeblock(($length > $block) ? $block : $length); |
|
126 |
$md5->add($data); |
|
127 |
print(FILE $data); |
|
128 |
$length -= $block; |
|
129 |
} |
|
130 |
close(FILE); |
|
131 |
return $md5->hexdigest(); |
|
132 |
} |
|
133 |
||
134 |
||
135 |
sub readfile |
|
136 |
{ |
|
137 |
my $file = shift; |
|
138 |
open(FILE, $file) or warn ("Unable to open $file for reading: $!\n"); |
|
139 |
my $md5 = Digest::MD5->new(); |
|
140 |
$md5->addfile(*FILE); |
|
141 |
close(FILE); |
|
142 |
return $md5->hexdigest(); |
|
143 |
} |
|
144 |
||
145 |
||
146 |
sub createfiles |
|
147 |
{ |
|
148 |
my $dirlist = shift; |
|
149 |
my $size = shift; |
|
150 |
$size = 1024 unless defined $size; |
|
151 |
my $nfiles = shift; |
|
152 |
$nfiles = 1 unless defined $nfiles; |
|
153 |
||
154 |
my %digest; |
|
155 |
||
156 |
foreach (@$dirlist) |
|
157 |
{ |
|
158 |
for (my $i = 0; $i < $nfiles; $i++) |
|
159 |
{ |
|
160 |
my $file = sprintf("${_}file%04d.txt", $i + 1); |
|
161 |
$digest{$file} = writefile($file, $size); |
|
162 |
} |
|
163 |
} |
|
164 |
return %digest; |
|
165 |
} |
|
166 |
||
167 |
sub checkfiles |
|
168 |
{ |
|
169 |
my $digests = shift; |
|
170 |
||
171 |
foreach (sort keys %$digests) |
|
172 |
{ |
|
173 |
my $readDigest = readfile($_); |
|
174 |
print "$_\t$digests->{$_}\t$readDigest\t" . ($digests->{$_} eq $readDigest ? "ok" : "ERROR") . "\n"; |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
||
179 |
sub removefiles |
|
180 |
{ |
|
181 |
my $digests = shift; |
|
182 |
my @cant = grep {not unlink} (keys %$digests); |
|
183 |
warn "Unable to remove @cant\n" if @cant; |
|
184 |
} |
|
185 |
||
186 |
||
187 |
sub removefolders |
|
188 |
{ |
|
189 |
my $folders = shift; |
|
190 |
foreach (@$folders) |
|
191 |
{ |
|
192 |
if (-e) |
|
193 |
{ |
|
194 |
rmtree($_) or warn "Unable to remove $_: $!\n"; |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
||
200 |
###################################################################### |
|
201 |
||
202 |
__END__ |
|
203 |
||
204 |
=head1 NAME |
|
205 |
||
206 |
usbinterop1.pl - Create directories and files, read back and compare |
|
207 |
||
208 |
=head1 SYNOPSIS |
|
209 |
||
210 |
usage: usbinterop1.pl [options] |
|
211 |
||
212 |
=head1 OPTIONS |
|
213 |
||
214 |
=over 4 |
|
215 |
||
216 |
=item --spread=<number of directories and files> |
|
217 |
||
218 |
Spread is the number of directories and files that are created at each |
|
219 |
level of the created tree. For example, a spread of three would |
|
220 |
create three directories and three files in each of the directories. |
|
221 |
Spread is a measure of the "bushiness" of the directory tree. |
|
222 |
||
223 |
Default value is "3". |
|
224 |
||
225 |
=item --depth=<directory nesting level> |
|
226 |
||
227 |
Each directory can have subdirectories up to the limit of the depth |
|
228 |
parameter. Depth is a measure of the "height" of the directory tree. |
|
229 |
||
230 |
Default value is "1". |
|
231 |
||
232 |
=item --size=<size of files to create> |
|
233 |
||
234 |
The size in bytes for each test file. Be careful as the disk space |
|
235 |
used is a function of this parameter as well as the depth and spread |
|
236 |
parameters: |
|
237 |
||
238 |
total size = size*(sp^(dep+1)+sp^(dep)+sp^(dep-1)+..+sp^2) |
|
239 |
||
240 |
Default value is "1024". |
|
241 |
||
242 |
=item --drive=<USB drive location> |
|
243 |
||
244 |
The path to the USB drive in which to write the files. |
|
245 |
||
246 |
Default value is ".", the current working directory. |
|
247 |
||
248 |
=item --help=<file> |
|
249 |
||
250 |
Displays this help. |
|
251 |
||
252 |
=back |
|
253 |
||
254 |
=head1 DESCRIPTION |
|
255 |
||
256 |
This is a simple utility to create folders and files with varying |
|
257 |
levels of nesting and sizes on a USB drive, and read them back to |
|
258 |
verify their contents. |
|
259 |
||
260 |
=head2 Test Case Specification |
|
261 |
||
262 |
TestCaseID: Interoperability_1 |
|
263 |
TestType: IT |
|
264 |
TestCaseDesc: Test Mass Storage functionality on different platforms |
|
265 |
(Windows 2000/XP/ME, MacOS) (Manual test) |
|
266 |
FssID: Base/emstore/1.1.1 |
|
267 |
FssID: Base/emstore/3.1.1 |
|
268 |
||
269 |
TestActions: |
|
270 |
Connect device to a host PC. Enable MS. Start perl script on |
|
271 |
PC. This script formats drive and creates several folders with |
|
272 |
levels of nested folders and writes set of files to them. File sizes |
|
273 |
varied from several kilobytes to several megabytes. The number of |
|
274 |
folders, nest depth, number of files placed in each folder and there |
|
275 |
sizes should be configurable. Then script prompt ask to unplug/plug |
|
276 |
USB cable (to flash OS read cache) and then read all files back and |
|
277 |
compare. |
|
278 |
||
279 |
TestExpectedResults: |
|
280 |
Read data from files should match with written. |
|
281 |
||
282 |
=head1 COPYRIGHT |
|
283 |
||
284 |
Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
285 |
||
286 |
=cut |