toolsandutils/e32tools/elftools/test/Elftran-test.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 #
       
     2 # Copyright (c) 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 #
       
    16 #!/usr/bin/perl -w
       
    17 use strict;
       
    18 
       
    19 # Perl script that creates PKG files and test MAKESIS tools with different ranges
       
    20 
       
    21 #my $logFile = "\\epoc32\\winscw\\c\\ELFTRAN_test.txt";
       
    22 my $logFile = "ELFTRAN_test.txt";
       
    23 my @retval = 0;
       
    24 
       
    25 #
       
    26 # Counters for results
       
    27 #
       
    28 my $NumberOfTests  = 0;
       
    29 my $NumberOfPassed = 0;
       
    30 my $NumberOfFailed = 0;
       
    31 
       
    32 #
       
    33 #Function to write log into file
       
    34 #
       
    35 sub WriteLog {
       
    36 	my ($log) = @_;
       
    37 	#public $logfile;
       
    38         my $fh;
       
    39 	unless( open($fh, ">> $logFile")) {
       
    40 		printf STDERR "Can\'t open $logFile:$!\n";
       
    41 		return;
       
    42 	}
       
    43 	printf $fh $log;
       
    44 	printf $log;
       
    45 	close $fh;
       
    46 }
       
    47 
       
    48 
       
    49 #
       
    50 # Run command with prepared command line parameters and administrate its result
       
    51 #
       
    52 sub RunCommand {
       
    53 
       
    54 	my( $command, $expectedResult, $expectedLog, $expectedVal) = @_;
       
    55 	#my ($pkgfile) = @_[0];
       
    56 	#my ($expectedResult) = @_[1];
       
    57 	#$pkgfile =~ s/\.pkg//;
       
    58 
       
    59        	#@retval = system("$command >run.log");
       
    60         @retval = system("$command >NUL");
       
    61         my $logMsg = sprintf "Expected code:%5d   result Code:%5d \n", $expectedResult, @retval;
       
    62         WriteLog( $logMsg);
       
    63         
       
    64         #open CMDPIPE, "$command 3>&1 2>&1 | ";
       
    65         open CMDPIPE, "$command 2>&1 | ";
       
    66         
       
    67         my @lines=<CMDPIPE>;
       
    68         close CMDPIPE;
       
    69        
       
    70         my $receivedVal;
       
    71         if( $expectedLog ne "")
       
    72         {
       
    73             $receivedVal = ProcessResult($expectedLog, $expectedVal, @lines);
       
    74             $logMsg = sprintf "Expected %s:%s   result value:%s \n", $expectedLog, $expectedVal, $receivedVal;
       
    75             WriteLog( $logMsg);
       
    76         }
       
    77         else
       
    78         {
       
    79             $receivedVal=$expectedVal;
       
    80         }
       
    81        
       
    82 	$NumberOfTests++;
       
    83 
       
    84 	if( $retval[0] == $expectedResult ) {
       
    85                 if( $receivedVal eq $expectedVal ){
       
    86                     $NumberOfPassed++;
       
    87                     WriteLog("Passed\n\n");
       
    88                 }
       
    89                 else
       
    90                 {
       
    91                     $NumberOfFailed++;
       
    92                     WriteLog("Failed\n\n");
       
    93                 }
       
    94 	}
       
    95 	else {
       
    96 		$NumberOfFailed++;
       
    97 		WriteLog("Failed\n\n");
       
    98 	}
       
    99 
       
   100 	#unlink("$pkgfile-tmp.sis");
       
   101 	#unlink("$pkgfile.log");
       
   102 	#unlink("$pkgfile.pkg");
       
   103 
       
   104 }
       
   105 
       
   106 sub ProcessResult {
       
   107     my ($expLog, $expVal, @result) = @_;
       
   108     for my $line (@result) {
       
   109         #WriteLog( $line);
       
   110         if($line =~ /($expLog):[ \t](.*)/i)
       
   111         #if($line =~ /.?($expLog)[ :][ \t](.*)/i)
       
   112         {
       
   113             #WriteLog($1);
       
   114             if( $2 eq $expVal)
       
   115             {
       
   116                 return $2;
       
   117             }
       
   118         }
       
   119         
       
   120     }
       
   121     return "";
       
   122 }
       
   123 
       
   124 #
       
   125 # Main
       
   126 #
       
   127 # Create environment and control test flow to testing ELFTRAN
       
   128 #
       
   129 
       
   130 unlink($logFile);
       
   131 WriteLog("ELFTRAN test.\n\n");
       
   132 
       
   133 
       
   134 my $Command = "ELFTRAN.EXE";
       
   135 my $Path = "\\epoc32\\tools\\";
       
   136 #
       
   137 # Array of contents of ELFTRAN parameters and expected results
       
   138 #
       
   139 #                    command,     options                                           inputfile/,         outfile    expected , expected log,     expeced log
       
   140 #                                                                                   e32imagefile                    result     message          value
       
   141 #               ------------------------------------------------------------------------------------------------------------------------------------------------ 
       
   142 my @TestItems = (   [$Command,  "",                                                 "",                     "",     65280,    , "",		""],
       
   143                     [$Command,  "-h",                                               "",                     "",       256,    , "ERROR",        "Cannot open -h for input."],
       
   144                     [$Command,  "-dump h -nocompress",                              "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   145                     [$Command,  "-dump h",                                          "camera1_test.exe",     "",         0,    , "Compression",	"101f7afc"],
       
   146                     [$Command,  "-dump h -nocompress",                              "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   147                     [$Command,  "-dump h -compress",                                "camera1_test.exe",     "",         0,    , "Compression",  "101f7afc"],                    
       
   148                     [$Command,  "-dump h -nocompress",                              "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   149                     [$Command,  "-dump h -compressionmethod bytepair",              "camera1_test.exe",     "",         0,    , "Compression",  "102822aa"],
       
   150                     [$Command,  "-dump h -compressionmethod none",                  "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   151                     [$Command,  "-dump h -compressionmethod deflate",               "camera1_test.exe",     "",         0,    , "Compression",  "101f7afc"],
       
   152                     [$Command,  "-dump h -compress -compressionmethod bytepair",    "camera1_test.exe",     "",         0,    , "Compression",  "102822aa"],
       
   153                     [$Command,  "-dump h -compress -compressionmethod deflate",     "camera1_test.exe",     "",         0,    , "Compression",  "101f7afc"],
       
   154                     [$Command,  "-dump h -compress -compressionmethod none",        "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   155                     [$Command,  "-dump h -nocompress -compressionmethod deflate",   "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   156                     [$Command,  "-dump h -nocompress -compressionmethod none",      "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   157                     [$Command,  "-dump h -nocompress -compressionmethod bytepair",  "camera1_test.exe",     "",         0,    , "Compression",  "00000000"],
       
   158 	     );
       
   159 
       
   160 
       
   161 #
       
   162 # Do test for each elements of TestItems array
       
   163 #
       
   164 my $loop = 1;
       
   165 for my $Test ( @TestItems )  {
       
   166 
       
   167     WriteLog( sprintf "Loop:%3d\n", $loop++);
       
   168         
       
   169     my $command = sprintf "%s%s %s %s %s", $Path, $Test->[0], $Test->[1], $Test->[2], $Test->[3];
       
   170     my $logLine = "Command: '$command'\n";
       
   171     WriteLog($logLine);
       
   172 
       
   173     RunCommand($command, $Test->[4], $Test->[5], $Test->[6]);
       
   174  
       
   175 }
       
   176 
       
   177 
       
   178 #
       
   179 # Display the result
       
   180 #
       
   181 WriteLog("\n\nTests completed OK\n");
       
   182 WriteLog(sprintf "Run: %d\n", $NumberOfTests );
       
   183 WriteLog(sprintf "Passed: %d\n", $NumberOfPassed );
       
   184 WriteLog(sprintf "%d tests failed out of %d\n", $NumberOfFailed, $NumberOfTests );