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