tsrc/testing/tools/rerunsubs.pl
changeset 71 60b4b6493d7b
equal deleted inserted replaced
-1:000000000000 71:60b4b6493d7b
       
     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 
       
    17 my $regexpCaseName = '[<>\x3C\x3E\(\)\w.,\/:_\-&\' ]+';
       
    18 
       
    19 { # No globals.
       
    20     # Solve where the script is located.
       
    21     $0=~/^(.+[\\\/])[^\\\/]+[\\\/]*$/;
       
    22     my $cgidir= $1 || "./";
       
    23     
       
    24     # And try to solve relative path.
       
    25     if( index( $cgidir, "..\\" ) != -1 )
       
    26     {
       
    27     	my $p = cwd;
       
    28     	$p =~ s/\//\\/g;
       
    29     	$cgidir =~ s/\//\\/g;
       
    30     	while(1) 
       
    31     	{
       
    32     		my $pos = index( $cgidir, "..\\" );
       
    33     		last if( $pos == -1 );
       
    34     		$cgidir = substr( $cgidir, $pos+3 );
       
    35     		
       
    36     		$pos = rindex( $p, "\\" );
       
    37     		last if( $pos == -1 );
       
    38     		$p = substr( $p, 0, $pos);
       
    39     	}
       
    40     	$cgidir = $p . "\\" . $cgidir;
       
    41     }
       
    42     
       
    43     if ( ! -e( $cgidir . "rerunsubs.pl" ) )
       
    44     {
       
    45         $cgidir = cwd;
       
    46         my $domain = "VideoApp_Domain";
       
    47         my $pos = index( $cgidir, $domain );
       
    48         if( $pos != -1 )
       
    49         {
       
    50             $cgidir = substr( $cgidir, 0, $pos + length( $domain ) ) . "\\videoplayer\\tsrc\\testing\\tools\\";
       
    51             
       
    52         }
       
    53     }
       
    54     
       
    55     require( $cgidir . "utils.pl" );
       
    56 }
       
    57 
       
    58 #------------------------------------------------------------------------------------
       
    59 # Rerun_ReadFailedCases
       
    60 # Parameters:
       
    61 #	$filename, filename of the result IPTV_Engine testreport.
       
    62 #	$refCfgs, reference to array which contains failed cases as a result
       
    63 #
       
    64 # array
       
    65 #  {
       
    66 #    array { $cfgFilename, @cases },
       
    67 #    array { $cfgFilename, @cases },
       
    68 #    ...
       
    69 #  }
       
    70 #
       
    71 # returns 1 if something fails, otherwise 0
       
    72 #------------------------------------------------------------------------------------
       
    73 
       
    74 sub Rerun_ReadFailedCases
       
    75 {
       
    76     my( $filename, $refCfgs ) = @_;
       
    77 
       
    78 	if( !open(FILE_HANDLE, $filename) )
       
    79 	{
       
    80 		print("ERROR! Could not open file '" . $filename . "'\n");
       
    81 		return 1;
       
    82 	}
       
    83 	my @array = <FILE_HANDLE>;
       
    84 	close(FILE_HANDLE);
       
    85 
       
    86     my $refCfg;
       
    87     my $cfgHasFailedCases = 0;
       
    88 
       
    89 	my $lineCount = scalar(@array);
       
    90 	for($i=0; $i<$lineCount; $i++ )
       
    91 	{
       
    92 	    $line = $array[$i];
       
    93         XmlToText(\$line);
       
    94 	    $line =~ s/\'/\"/g;
       
    95 
       
    96         # Read the name of cfg
       
    97 	    if($line =~ m/Cell ss:MergeAcross=\"11\" ss:StyleID=\"/ )
       
    98 	    {
       
    99 	        #<Cell ss:MergeAcross="11" ss:StyleID="m150670304"><Data ss:Type="String">IptvEpgEngineTest.cfg</Data></Cell>
       
   100 	        if($line =~ m/>([a-z0-9_\-]+).cfg<\/Data>/i)
       
   101 	        {
       
   102                 # Add cfg to cfg list if it has failed cases.
       
   103                 if( defined( @$refCfg ) and $cfgHasFailedCases )
       
   104                 {
       
   105                     push @$refCfgs, [ @$refCfg ];
       
   106                 }
       
   107 
       
   108                 # Initialize new array for new cfg, if the cfg exists.
       
   109                 $cfgHasFailedCases = 0;
       
   110      	        
       
   111      	        my $cfgFilename = $1 . ".cfg";
       
   112 
       
   113     	        my @cfg;
       
   114     	        $refCfg = \@cfg;
       
   115     	        push @cfg, $cfgFilename;
       
   116     	        my @cases;
       
   117     	        push @cfg, [@cases];
       
   118 	        }
       
   119 	    }
       
   120 
       
   121         #<Cell ss:MergeAcross="5" ss:StyleID="m150670456"><Data ss:Type="String">ET17099 &lt;not a test&gt; Setup EPG tests</Data></Cell>
       
   122         #<Cell ss:MergeAcross="5" ss:StyleID="m150686796"><Data ss:Type="String">ET17001 Update EPG 3G</Data></Cell>
       
   123 	    #<Cell ss:StyleID="s57"><Data ss:Type="String">PASSED</Data></Cell>
       
   124 
       
   125 	    # Read case and the result
       
   126 	    if( defined( @$refCfg ) && $line =~ m/Cell ss:MergeAcross=\"5\" ss:StyleID=\"/ )
       
   127 	    {
       
   128 	        if($line =~ m/>($regexpCaseName)<\/Data><\/Cell>/i)
       
   129 	        {
       
   130 	            my $caseName = $1;
       
   131                 my $saveCase = 0;
       
   132 
       
   133 	            $line2 = $array[$i+1];
       
   134 	            XmlToText(\$line2);
       
   135 	            
       
   136 	            #print("Found case: $caseName\n");
       
   137 	            
       
   138 	            if( $line =~ m/Setup/i or $line =~ m/not a test/i or $line =~ m/set up/i or $line =~m/not test/i or $line =~m/cleanup/i)
       
   139 	            {
       
   140 	                #print(" - is for setup\n");
       
   141 	                $saveCase = 1;
       
   142 	            }
       
   143 
       
   144 	            # If case has failed.
       
   145 	            if($line2 =~ m/>CRASHED</ or $line2 =~ m/>FAILED</)
       
   146 	            {
       
   147 	                #print(" - failed\n");
       
   148 	                $saveCase = 1;
       
   149 	                $cfgHasFailedCases = 1;
       
   150 	            }
       
   151 
       
   152                 # It's marked for rerun.
       
   153 	            if($saveCase)
       
   154 	            {
       
   155                     my $refCases = @$refCfg[1];
       
   156 	                push @$refCases, $caseName;
       
   157 	                #print(" - ADDED\n");
       
   158 	            }
       
   159 	        }
       
   160         }
       
   161 	}
       
   162 
       
   163     # If cfg has failed cases then add it
       
   164     if(defined(@$refCfg) and $cfgHasFailedCases != 0)
       
   165     {
       
   166         push @$refCfgs, [ @$refCfg ];
       
   167     }
       
   168 	return 0;
       
   169 }
       
   170 
       
   171 
       
   172 #------------------------------------------------------------------------------------
       
   173 # Rerun_GenerateCfg
       
   174 # Parameters:
       
   175 #   $srcFile, $destFile
       
   176 #------------------------------------------------------------------------------------
       
   177 sub Rerun_GenerateCfg
       
   178 {
       
   179     my($srcFile, $destFile, $refFailedCfgs) = @_;
       
   180     
       
   181     my $refCases = 0;
       
   182     
       
   183     foreach my $cfg( @$refFailedCfgs )
       
   184     {
       
   185         my $cfgFile = GetPathFileName( $srcFile );
       
   186         if( @$cfg[0] =~ m/$cfgFile/i )
       
   187         {
       
   188             $refCases = @$cfg[1];    
       
   189             last;
       
   190         }
       
   191     }
       
   192     
       
   193     if( !$refCases )
       
   194     {
       
   195         my $cfgFile = GetPathFileName( $srcFile );
       
   196         #print("Writing empty cfg for $cfgFile, no fails.\n");
       
   197 
       
   198         open(FILE_HANDLE, ">$destFile");
       
   199         close(FILE_HANDLE);
       
   200         
       
   201         return 0;
       
   202     }
       
   203     
       
   204     my @foundFailedCases;
       
   205 
       
   206     my @lines;
       
   207 
       
   208 	if( open(FILE_HANDLE, $srcFile) )
       
   209 	{
       
   210 		@lines = <FILE_HANDLE>;
       
   211 		close(FILE_HANDLE);
       
   212 	}
       
   213 	else
       
   214 	{
       
   215 		print("ERROR: could not read file: $srcFile\n");
       
   216 		return 0;
       
   217 	}
       
   218 
       
   219 	print("Writing cfg $destFile\n");
       
   220 	if( !open(FILE_HANDLE, ">$destFile") )
       
   221 	{
       
   222 		print("ERROR: could not write to file: $destFile\n");
       
   223 		return 0;
       
   224 	}
       
   225 
       
   226     my $lastLineBeforeCases = 0;
       
   227     for( my $i=0; $i<scalar(@lines); $i++ )
       
   228     {
       
   229         $line = $lines[$i];
       
   230         $lastLineBeforeCases = $i if( $line =~ m/\[Enddefine\]/i or $line =~ m/\[EndSub\]/i );
       
   231     }
       
   232 
       
   233     # Write lines before first case
       
   234     foreach my $line(@lines)
       
   235     {
       
   236         print FILE_HANDLE ( $line );
       
   237 
       
   238         if($line =~ m/\[Enddefine\]/i)
       
   239         {
       
   240             last;
       
   241         }
       
   242     }
       
   243 
       
   244     # Write all subs
       
   245 
       
   246     my $inSub = 0;
       
   247     my $refSubLines;
       
   248     foreach my $line (@lines)
       
   249     {
       
   250         RemoveWhiteSpaces(\$line);
       
   251 
       
   252         # Sub starts?
       
   253         if($line =~ m/\[Sub [a-zA-Z0-9]+\]/)
       
   254         {
       
   255             $inSub= 1;
       
   256             my @subLines;
       
   257             $refSubLines = \@subLines;
       
   258         }
       
   259 
       
   260         # Add lines
       
   261         if($inSub)
       
   262         {
       
   263             push @$refSubLines, $line;
       
   264         }
       
   265 
       
   266         # Sub ends?
       
   267         if($line =~ m/\[EndSub\]/)
       
   268         {
       
   269             $inSub = 0;
       
   270 
       
   271             foreach $l (@$refSubLines)
       
   272             {
       
   273                 print FILE_HANDLE ( "$l" . "\n" );
       
   274             }
       
   275 
       
   276             print FILE_HANDLE ( "\n" );
       
   277             print FILE_HANDLE ( "\n" );
       
   278         }
       
   279     }
       
   280 
       
   281     print FILE_HANDLE ( "\n" );
       
   282     print FILE_HANDLE ( "\n" );
       
   283 
       
   284     my $savedCases = 0;
       
   285 
       
   286     # Write cases
       
   287     my $inCase = 0;
       
   288     my $refCaseLines;
       
   289     my $writeCase = 0;
       
   290     foreach my $line(@lines)
       
   291     {
       
   292         RemoveWhiteSpaces(\$line);
       
   293 
       
   294         # Case starts?
       
   295         if($line =~ m/\[Test\]/)
       
   296         {
       
   297             $inCase = 1;
       
   298             my @caseLines;
       
   299             $refCaseLines = \@caseLines;
       
   300             $writeCase = 0;
       
   301         }
       
   302 
       
   303         # Add lines
       
   304         if($inCase)
       
   305         {
       
   306             push @$refCaseLines, $line;
       
   307         }
       
   308 
       
   309         # Case ends?
       
   310         if($line =~ m/\[Endtest\]/)
       
   311         {
       
   312             $inCase = 0;
       
   313 
       
   314             # And it had failed. Write into new cfg.
       
   315             if($writeCase)
       
   316             {
       
   317                 foreach $l(@$refCaseLines)
       
   318                 {
       
   319                     print FILE_HANDLE ( "$l" . "\n" );
       
   320                 }
       
   321 
       
   322                 print FILE_HANDLE ( "\n" );
       
   323                 print FILE_HANDLE ( "\n" );
       
   324             }
       
   325         }
       
   326 
       
   327         # title line for the case
       
   328         if($inCase and $line =~ m/^title /)
       
   329 	    {
       
   330 	    	my $caseName = substr($line, length("title "));
       
   331 	    	RemoveWhiteSpaces(\$caseName);
       
   332 
       
   333             foreach my $failedCaseName (@$refCases)
       
   334             {
       
   335                 my $addFoundCase = 0;
       
   336                 if( $line =~ m/Setup/i or $line =~ m/not a test/i or $line =~ m/set up/i or $line =~m/not test/i or $line =~m/cleanup/i)
       
   337                 {
       
   338                     $addFoundCase = 1;
       
   339                 }
       
   340                 
       
   341                 if($failedCaseName eq $caseName)
       
   342                 {
       
   343                     $addFoundCase = 1;
       
   344                 }
       
   345                 if( $addFoundCase )
       
   346                 {
       
   347                     push @foundFailedCases, $caseName;
       
   348                     print(" - Case: $failedCaseName\n");
       
   349                     $writeCase = 1;
       
   350                     $savedCases++;
       
   351                 }
       
   352             }
       
   353         }
       
   354     }
       
   355 
       
   356     my $caseIsFound = 0;
       
   357     foreach my $failedCaseName (@$refCases)
       
   358     {
       
   359         foreach my $foundCaseName (@foundFailedCases)
       
   360         {
       
   361             $caseIsFound = 1 if($foundCaseName eq $failedCaseName);
       
   362         }
       
   363         if(!$caseIsFound)
       
   364         {
       
   365             print("ERROR: Case '$failedCaseName' couldn't be found from the CFG files!\n");
       
   366         }
       
   367         $caseIsFound = 0;
       
   368     }
       
   369 }