os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbinterop2.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbinterop2.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,170 @@
     1.4 +#!perl -w
     1.5 +# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +# All rights reserved.
     1.7 +# This component and the accompanying materials are made available
     1.8 +# under the terms of the License "Eclipse Public License v1.0"
     1.9 +# which accompanies this distribution, and is available
    1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +#
    1.12 +# Initial Contributors:
    1.13 +# Nokia Corporation - initial contribution.
    1.14 +#
    1.15 +# Contributors:
    1.16 +#
    1.17 +# Description:
    1.18 +# USBinterop2
    1.19 +# 
    1.20 +#
    1.21 +
    1.22 +use strict;
    1.23 +use Digest::MD5;
    1.24 +use POSIX;
    1.25 +use Getopt::Long;
    1.26 +use Pod::Usage;
    1.27 +
    1.28 +my $drive = ".";
    1.29 +my $size = 1024;
    1.30 +my $pause = 1;
    1.31 +my $help = 0;
    1.32 +my $filename = "file0000.txt";
    1.33 +
    1.34 +my %opts = ( 'drive=s' 	=> \$drive,
    1.35 +	     'size=i' 	=> \$size,
    1.36 +	     'pause!' 	=> \$pause,
    1.37 +	     'help!' 	=> \$help);
    1.38 +
    1.39 +GetOptions(%opts) || pod2usage(2);
    1.40 +pod2usage(-exitval => 1, -verbose => 2) if $help;
    1.41 +
    1.42 +$drive =~ s/\\/\//g;
    1.43 +$drive .= "/" unless ($drive =~ m/\/$/);
    1.44 +$size = 1 if $size < 1;
    1.45 +
    1.46 +# Check OS
    1.47 +# ME : "Windows" "4.90"
    1.48 +# 2k : "Windows NT" "5.0"
    1.49 +# XP : "Windows NT" "5.1"
    1.50 +# Mac: "Darwin" "7.4.1"
    1.51 +print((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n");
    1.52 +
    1.53 +$filename = "$drive$filename";
    1.54 +my $writeDigest = writefile($filename, $size);
    1.55 +
    1.56 +if ($pause)
    1.57 +{
    1.58 +	print "Unplug and replug the USB cable, then press enter...";
    1.59 +	$pause = <STDIN>;
    1.60 +}
    1.61 +
    1.62 +my $readDigest = readfile($filename);
    1.63 +print "$filename\t$writeDigest\t$readDigest\t" . ($writeDigest eq $readDigest ? "ok" : "ERROR") . "\n";
    1.64 +unlink($filename) or die("Can't remove $filename: $!\n");
    1.65 +
    1.66 +sub makeblock
    1.67 +{
    1.68 +	my $length = shift;
    1.69 +	my @list = ();
    1.70 +	for (my $i = 0; $i < $length; $i++)
    1.71 +	{
    1.72 +		push @list, int((91 - 65) * rand()) + 65;
    1.73 +	}
    1.74 +	return pack "C$length", @list;
    1.75 +}
    1.76 +
    1.77 +
    1.78 +sub writefile
    1.79 +{
    1.80 +	my $file = shift;
    1.81 +	my $length = shift;
    1.82 +	my $block = 1024;
    1.83 +	open(FILE, ">$file") or warn ("Unable to open $file for writing: $!\n");
    1.84 +	my $md5 = Digest::MD5->new();
    1.85 +	while ($length > 0)
    1.86 +	{	
    1.87 +		my $data = makeblock(($length > $block) ? $block : $length);
    1.88 +		$md5->add($data);
    1.89 +		print(FILE $data);
    1.90 +		$length -= $block;
    1.91 +	}
    1.92 +	close(FILE);
    1.93 +	return $md5->hexdigest();
    1.94 +}
    1.95 +
    1.96 +
    1.97 +sub readfile 
    1.98 +{
    1.99 +	my $file = shift;
   1.100 +	open(FILE, $file) or warn ("Unable to open $file for reading: $!\n");
   1.101 +	my $md5 = Digest::MD5->new();
   1.102 +	$md5->addfile(*FILE);
   1.103 +	close(FILE);
   1.104 +	return $md5->hexdigest();
   1.105 +}
   1.106 +
   1.107 +
   1.108 +
   1.109 +######################################################################
   1.110 +
   1.111 +__END__
   1.112 +
   1.113 +=head1 NAME
   1.114 +
   1.115 +usbinterop2.pl - Create drive-filling file, read back and compare
   1.116 +
   1.117 +=head1 SYNOPSIS
   1.118 +
   1.119 +usage:   usbinterop2.pl [options]
   1.120 +
   1.121 +=head1 OPTIONS
   1.122 +
   1.123 +=over 4
   1.124 +
   1.125 +=item --size=<size of files to create>
   1.126 +
   1.127 +The size in bytes for the test file.
   1.128 +
   1.129 +Default value is "1024".
   1.130 +
   1.131 +=item --drive=<USB drive location>
   1.132 +
   1.133 +The path to the USB drive in which to write the files.
   1.134 +
   1.135 +Default value is ".", the current working directory.
   1.136 +
   1.137 +=item --help=<file>
   1.138 +
   1.139 +Displays this help.
   1.140 +
   1.141 +=back
   1.142 +
   1.143 +=head1 DESCRIPTION
   1.144 +
   1.145 +This is a simple utility to create a file that fills the USB drive as
   1.146 +much as possible, and reads it back to verify its contents.
   1.147 +
   1.148 +=head2 Test Case Specification
   1.149 +
   1.150 + TestCaseID:	Interoperability_2
   1.151 + TestType: 	IT
   1.152 + TestCaseDesc:  Test Mass Storage functionality on different platforms
   1.153 +	        (Windows 2000/XP/ME, MacOS) (Manual test)
   1.154 + FssID: 	Base/emstore/1.1.1
   1.155 + FssID: 	Base/emstore/3.1.1
   1.156 +
   1.157 + TestActions:
   1.158 +	Connect device to a host PC. Enable MS. Start perl script on
   1.159 + PC.  This script formats drive and queries size of it.  Than script
   1.160 + create file with size close to drive size and check free space.  Then
   1.161 + script prompt ask to unplug/plug USB cable (to flash OS read cache)
   1.162 + and then read the file back and compare.
   1.163 +
   1.164 + TestExpectedResults:
   1.165 +	File creation should succeed. Read data from file should match
   1.166 + with written.  Sum of file size and free space should be close to
   1.167 + drive size.
   1.168 +
   1.169 +=head1 COPYRIGHT
   1.170 +
   1.171 +Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
   1.172 +
   1.173 +=cut