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: # USBinterop2 sl@0: # sl@0: # sl@0: sl@0: use strict; sl@0: use Digest::MD5; sl@0: use POSIX; sl@0: use Getopt::Long; sl@0: use Pod::Usage; sl@0: sl@0: my $drive = "."; sl@0: my $size = 1024; sl@0: my $pause = 1; sl@0: my $help = 0; sl@0: my $filename = "file0000.txt"; sl@0: sl@0: my %opts = ( '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: $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: $filename = "$drive$filename"; sl@0: my $writeDigest = writefile($filename, $size); 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: my $readDigest = readfile($filename); sl@0: print "$filename\t$writeDigest\t$readDigest\t" . ($writeDigest eq $readDigest ? "ok" : "ERROR") . "\n"; sl@0: unlink($filename) or die("Can't remove $filename: $!\n"); 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: sl@0: ###################################################################### sl@0: sl@0: __END__ sl@0: sl@0: =head1 NAME sl@0: sl@0: usbinterop2.pl - Create drive-filling file, read back and compare sl@0: sl@0: =head1 SYNOPSIS sl@0: sl@0: usage: usbinterop2.pl [options] sl@0: sl@0: =head1 OPTIONS sl@0: sl@0: =over 4 sl@0: sl@0: =item --size= sl@0: sl@0: The size in bytes for the test file. 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 a file that fills the USB drive as sl@0: much as possible, and reads it back to verify its contents. sl@0: sl@0: =head2 Test Case Specification sl@0: sl@0: TestCaseID: Interoperability_2 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 queries size of it. Than script sl@0: create file with size close to drive size and check free space. Then sl@0: script prompt ask to unplug/plug USB cable (to flash OS read cache) sl@0: and then read the file back and compare. sl@0: sl@0: TestExpectedResults: sl@0: File creation should succeed. Read data from file should match sl@0: with written. Sum of file size and free space should be close to sl@0: drive size. 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