os/kernelhwsrv/kerneltest/f32test/smassstorage/scripts/usbinterop2.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
# USBinterop2
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 Getopt::Long;
sl@0
    23
use Pod::Usage;
sl@0
    24
sl@0
    25
my $drive = ".";
sl@0
    26
my $size = 1024;
sl@0
    27
my $pause = 1;
sl@0
    28
my $help = 0;
sl@0
    29
my $filename = "file0000.txt";
sl@0
    30
sl@0
    31
my %opts = ( 'drive=s' 	=> \$drive,
sl@0
    32
	     'size=i' 	=> \$size,
sl@0
    33
	     'pause!' 	=> \$pause,
sl@0
    34
	     'help!' 	=> \$help);
sl@0
    35
sl@0
    36
GetOptions(%opts) || pod2usage(2);
sl@0
    37
pod2usage(-exitval => 1, -verbose => 2) if $help;
sl@0
    38
sl@0
    39
$drive =~ s/\\/\//g;
sl@0
    40
$drive .= "/" unless ($drive =~ m/\/$/);
sl@0
    41
$size = 1 if $size < 1;
sl@0
    42
sl@0
    43
# Check OS
sl@0
    44
# ME : "Windows" "4.90"
sl@0
    45
# 2k : "Windows NT" "5.0"
sl@0
    46
# XP : "Windows NT" "5.1"
sl@0
    47
# Mac: "Darwin" "7.4.1"
sl@0
    48
print((uname)[0] . " v" . (uname)[2] . ":" . (uname)[3] . "\n");
sl@0
    49
sl@0
    50
$filename = "$drive$filename";
sl@0
    51
my $writeDigest = writefile($filename, $size);
sl@0
    52
sl@0
    53
if ($pause)
sl@0
    54
{
sl@0
    55
	print "Unplug and replug the USB cable, then press enter...";
sl@0
    56
	$pause = <STDIN>;
sl@0
    57
}
sl@0
    58
sl@0
    59
my $readDigest = readfile($filename);
sl@0
    60
print "$filename\t$writeDigest\t$readDigest\t" . ($writeDigest eq $readDigest ? "ok" : "ERROR") . "\n";
sl@0
    61
unlink($filename) or die("Can't remove $filename: $!\n");
sl@0
    62
sl@0
    63
sub makeblock
sl@0
    64
{
sl@0
    65
	my $length = shift;
sl@0
    66
	my @list = ();
sl@0
    67
	for (my $i = 0; $i < $length; $i++)
sl@0
    68
	{
sl@0
    69
		push @list, int((91 - 65) * rand()) + 65;
sl@0
    70
	}
sl@0
    71
	return pack "C$length", @list;
sl@0
    72
}
sl@0
    73
sl@0
    74
sl@0
    75
sub writefile
sl@0
    76
{
sl@0
    77
	my $file = shift;
sl@0
    78
	my $length = shift;
sl@0
    79
	my $block = 1024;
sl@0
    80
	open(FILE, ">$file") or warn ("Unable to open $file for writing: $!\n");
sl@0
    81
	my $md5 = Digest::MD5->new();
sl@0
    82
	while ($length > 0)
sl@0
    83
	{	
sl@0
    84
		my $data = makeblock(($length > $block) ? $block : $length);
sl@0
    85
		$md5->add($data);
sl@0
    86
		print(FILE $data);
sl@0
    87
		$length -= $block;
sl@0
    88
	}
sl@0
    89
	close(FILE);
sl@0
    90
	return $md5->hexdigest();
sl@0
    91
}
sl@0
    92
sl@0
    93
sl@0
    94
sub readfile 
sl@0
    95
{
sl@0
    96
	my $file = shift;
sl@0
    97
	open(FILE, $file) or warn ("Unable to open $file for reading: $!\n");
sl@0
    98
	my $md5 = Digest::MD5->new();
sl@0
    99
	$md5->addfile(*FILE);
sl@0
   100
	close(FILE);
sl@0
   101
	return $md5->hexdigest();
sl@0
   102
}
sl@0
   103
sl@0
   104
sl@0
   105
sl@0
   106
######################################################################
sl@0
   107
sl@0
   108
__END__
sl@0
   109
sl@0
   110
=head1 NAME
sl@0
   111
sl@0
   112
usbinterop2.pl - Create drive-filling file, read back and compare
sl@0
   113
sl@0
   114
=head1 SYNOPSIS
sl@0
   115
sl@0
   116
usage:   usbinterop2.pl [options]
sl@0
   117
sl@0
   118
=head1 OPTIONS
sl@0
   119
sl@0
   120
=over 4
sl@0
   121
sl@0
   122
=item --size=<size of files to create>
sl@0
   123
sl@0
   124
The size in bytes for the test file.
sl@0
   125
sl@0
   126
Default value is "1024".
sl@0
   127
sl@0
   128
=item --drive=<USB drive location>
sl@0
   129
sl@0
   130
The path to the USB drive in which to write the files.
sl@0
   131
sl@0
   132
Default value is ".", the current working directory.
sl@0
   133
sl@0
   134
=item --help=<file>
sl@0
   135
sl@0
   136
Displays this help.
sl@0
   137
sl@0
   138
=back
sl@0
   139
sl@0
   140
=head1 DESCRIPTION
sl@0
   141
sl@0
   142
This is a simple utility to create a file that fills the USB drive as
sl@0
   143
much as possible, and reads it back to verify its contents.
sl@0
   144
sl@0
   145
=head2 Test Case Specification
sl@0
   146
sl@0
   147
 TestCaseID:	Interoperability_2
sl@0
   148
 TestType: 	IT
sl@0
   149
 TestCaseDesc:  Test Mass Storage functionality on different platforms
sl@0
   150
	        (Windows 2000/XP/ME, MacOS) (Manual test)
sl@0
   151
 FssID: 	Base/emstore/1.1.1
sl@0
   152
 FssID: 	Base/emstore/3.1.1
sl@0
   153
sl@0
   154
 TestActions:
sl@0
   155
	Connect device to a host PC. Enable MS. Start perl script on
sl@0
   156
 PC.  This script formats drive and queries size of it.  Than script
sl@0
   157
 create file with size close to drive size and check free space.  Then
sl@0
   158
 script prompt ask to unplug/plug USB cable (to flash OS read cache)
sl@0
   159
 and then read the file back and compare.
sl@0
   160
sl@0
   161
 TestExpectedResults:
sl@0
   162
	File creation should succeed. Read data from file should match
sl@0
   163
 with written.  Sum of file size and free space should be close to
sl@0
   164
 drive size.
sl@0
   165
sl@0
   166
=head1 COPYRIGHT
sl@0
   167
sl@0
   168
Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
   169
sl@0
   170
=cut