sl@0: #!perl -w sl@0: # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # USBinterop1 sl@0: # sl@0: # sl@0: sl@0: use strict; sl@0: use Digest::MD5; sl@0: use POSIX; sl@0: use File::Path; sl@0: use Getopt::Long; sl@0: use Pod::Usage; sl@0: sl@0: my $spread = 3; sl@0: my $depth = 1; sl@0: my $drive = ""; sl@0: my $size = 1024; sl@0: my $pause = 1; sl@0: my $help = 0; sl@0: sl@0: my %opts = ( 'spread=i' => \$spread, sl@0: 'depth=i' => \$depth, sl@0: 'drive=s' => \$drive, sl@0: 'size=i' => \$size, sl@0: 'pause!' => \$pause, sl@0: 'help!' => \$help); sl@0: sl@0: GetOptions(%opts) || pod2usage(2); sl@0: pod2usage(-exitval => 1, -verbose => 2) if $help; sl@0: sl@0: $drive =~ s/\\/\//g; sl@0: $drive .= "/" unless ($drive =~ m/\/$/); sl@0: $spread = 1 if $spread < 1; sl@0: $depth = 1 if $depth < 1; sl@0: $size = 1 if $size < 1; sl@0: sl@0: # Check OS sl@0: # ME : "Windows" "4.90" sl@0: # 2k : "Windows NT" "5.0" sl@0: # XP : "Windows NT" "5.1" sl@0: # Mac: "Darwin" "7.4.1" sl@0: print((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n"); sl@0: sl@0: my @folders = createfolders($drive, $spread, $depth); sl@0: mkpath(\@folders); sl@0: my %digests = createfiles(\@folders, $size, $spread); sl@0: sl@0: if ($pause) sl@0: { sl@0: print "Unplug and replug the USB cable, then press enter..."; sl@0: $pause = ; sl@0: } sl@0: sl@0: checkfiles(\%digests); sl@0: removefiles(\%digests); sl@0: removefolders(\@folders); sl@0: sl@0: sl@0: sl@0: sub createfolder sl@0: { sl@0: my $dirlist = shift; sl@0: my $fbase = shift; sl@0: my $spread = shift; sl@0: my $depth = shift; sl@0: sl@0: return unless $depth > 0; sl@0: sl@0: for (my $i = 0; $i < $spread; $i++) sl@0: { sl@0: my $dir = sprintf("%sdir%05d/", $fbase, $i + 1); sl@0: push @$dirlist, $dir; sl@0: createfolder($dirlist, $dir, $spread, $depth - 1); sl@0: } sl@0: } sl@0: sl@0: sl@0: sub createfolders sl@0: { sl@0: my $drive = shift; sl@0: $drive = "" unless defined $drive; sl@0: my $spread = shift; sl@0: $spread = 1 unless defined $spread; sl@0: my $depth = shift; sl@0: $depth = 1 unless defined $depth; sl@0: sl@0: my @dirlist = (); sl@0: createfolder(\@dirlist, $drive, $spread, $depth); sl@0: return @dirlist; sl@0: } sl@0: sl@0: sub makeblock sl@0: { sl@0: my $length = shift; sl@0: my @list = (); sl@0: for (my $i = 0; $i < $length; $i++) sl@0: { sl@0: push @list, int((91 - 65) * rand()) + 65; sl@0: } sl@0: return pack "C$length", @list; sl@0: } sl@0: sl@0: sl@0: sub writefile sl@0: { sl@0: my $file = shift; sl@0: my $length = shift; sl@0: my $block = 1024; sl@0: open(FILE, ">$file") or warn ("Unable to open $file for writing: $!\n"); sl@0: my $md5 = Digest::MD5->new(); sl@0: while ($length > 0) sl@0: { sl@0: my $data = makeblock(($length > $block) ? $block : $length); sl@0: $md5->add($data); sl@0: print(FILE $data); sl@0: $length -= $block; sl@0: } sl@0: close(FILE); sl@0: return $md5->hexdigest(); sl@0: } sl@0: sl@0: sl@0: sub readfile sl@0: { sl@0: my $file = shift; sl@0: open(FILE, $file) or warn ("Unable to open $file for reading: $!\n"); sl@0: my $md5 = Digest::MD5->new(); sl@0: $md5->addfile(*FILE); sl@0: close(FILE); sl@0: return $md5->hexdigest(); sl@0: } sl@0: sl@0: sl@0: sub createfiles sl@0: { sl@0: my $dirlist = shift; sl@0: my $size = shift; sl@0: $size = 1024 unless defined $size; sl@0: my $nfiles = shift; sl@0: $nfiles = 1 unless defined $nfiles; sl@0: sl@0: my %digest; sl@0: sl@0: foreach (@$dirlist) sl@0: { sl@0: for (my $i = 0; $i < $nfiles; $i++) sl@0: { sl@0: my $file = sprintf("${_}file%04d.txt", $i + 1); sl@0: $digest{$file} = writefile($file, $size); sl@0: } sl@0: } sl@0: return %digest; sl@0: } sl@0: sl@0: sub checkfiles sl@0: { sl@0: my $digests = shift; sl@0: sl@0: foreach (sort keys %$digests) sl@0: { sl@0: my $readDigest = readfile($_); sl@0: print "$_\t$digests->{$_}\t$readDigest\t" . ($digests->{$_} eq $readDigest ? "ok" : "ERROR") . "\n"; sl@0: } sl@0: } sl@0: sl@0: sl@0: sub removefiles sl@0: { sl@0: my $digests = shift; sl@0: my @cant = grep {not unlink} (keys %$digests); sl@0: warn "Unable to remove @cant\n" if @cant; sl@0: } sl@0: sl@0: sl@0: sub removefolders sl@0: { sl@0: my $folders = shift; sl@0: foreach (@$folders) sl@0: { sl@0: if (-e) sl@0: { sl@0: rmtree($_) or warn "Unable to remove $_: $!\n"; sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: ###################################################################### sl@0: sl@0: __END__ sl@0: sl@0: =head1 NAME sl@0: sl@0: usbinterop1.pl - Create directories and files, read back and compare sl@0: sl@0: =head1 SYNOPSIS sl@0: sl@0: usage: usbinterop1.pl [options] sl@0: sl@0: =head1 OPTIONS sl@0: sl@0: =over 4 sl@0: sl@0: =item --spread= sl@0: sl@0: Spread is the number of directories and files that are created at each sl@0: level of the created tree. For example, a spread of three would sl@0: create three directories and three files in each of the directories. sl@0: Spread is a measure of the "bushiness" of the directory tree. sl@0: sl@0: Default value is "3". sl@0: sl@0: =item --depth= sl@0: sl@0: Each directory can have subdirectories up to the limit of the depth sl@0: parameter. Depth is a measure of the "height" of the directory tree. sl@0: sl@0: Default value is "1". sl@0: sl@0: =item --size= sl@0: sl@0: The size in bytes for each test file. Be careful as the disk space sl@0: used is a function of this parameter as well as the depth and spread sl@0: parameters: sl@0: sl@0: total size = size*(sp^(dep+1)+sp^(dep)+sp^(dep-1)+..+sp^2) sl@0: sl@0: Default value is "1024". sl@0: sl@0: =item --drive= sl@0: sl@0: The path to the USB drive in which to write the files. sl@0: sl@0: Default value is ".", the current working directory. sl@0: sl@0: =item --help= sl@0: sl@0: Displays this help. sl@0: sl@0: =back sl@0: sl@0: =head1 DESCRIPTION sl@0: sl@0: This is a simple utility to create folders and files with varying sl@0: levels of nesting and sizes on a USB drive, and read them back to sl@0: verify their contents. sl@0: sl@0: =head2 Test Case Specification sl@0: sl@0: TestCaseID: Interoperability_1 sl@0: TestType: IT sl@0: TestCaseDesc: Test Mass Storage functionality on different platforms sl@0: (Windows 2000/XP/ME, MacOS) (Manual test) sl@0: FssID: Base/emstore/1.1.1 sl@0: FssID: Base/emstore/3.1.1 sl@0: sl@0: TestActions: sl@0: Connect device to a host PC. Enable MS. Start perl script on sl@0: PC. This script formats drive and creates several folders with sl@0: levels of nested folders and writes set of files to them. File sizes sl@0: varied from several kilobytes to several megabytes. The number of sl@0: folders, nest depth, number of files placed in each folder and there sl@0: sizes should be configurable. Then script prompt ask to unplug/plug sl@0: USB cable (to flash OS read cache) and then read all files back and sl@0: compare. sl@0: sl@0: TestExpectedResults: sl@0: Read data from files should match with written. sl@0: sl@0: =head1 COPYRIGHT sl@0: sl@0: Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: =cut