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