bldsystemtools/commonbldutils/GenResult/GenAutoSmokeTestResult.pm
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Script summarise and hotlink autosmoketest logs by reading
       
    15 # testdriver generated files
       
    16 # 
       
    17 #
       
    18 
       
    19 #!/usr/bin/perl -w
       
    20 package GenAutoSmokeTestResult;
       
    21 use FindBin;
       
    22 use FileRead;
       
    23 require GenResult;
       
    24 use strict;
       
    25 #use XML::Parser;
       
    26 
       
    27 # global vars
       
    28 my $iSTPublishDir;
       
    29 my $iSTLinkPath;
       
    30 my $iHTMLFileName = "testlog.html";
       
    31 my $iTraceFileName = "trace.txt";
       
    32 my $iDevkitFileName = "Devkit\.log";
       
    33 
       
    34 my ($iCfgFileLocation) = $FindBin::Bin;
       
    35 #Read in the products from a cfg file
       
    36 my $text = &FileRead::file_read ("$iCfgFileLocation\\Product_AutoSmokeTest.cfg");
       
    37 #Search for an entry matching (At the beginning of line there should be 1 or more alphanumberic chars
       
    38 #Followed by a "." followed by more alphanumberic chars followed by 0 or more spaces then an = then 0
       
    39 #or more spaces then any amount of chars till the end of the line.
       
    40 #8.1b = EMULATOR_WINSCW ARM4_LUBBOCK ARMV5_LUBBOCK
       
    41 my %iProducts = $text =~ /^\s*(\w+\.?\w+)\s*=\s*(.+)$/mg ;
       
    42 
       
    43 #Read in the auto smoketest list from a cfg file
       
    44 my $Smoketext = &FileRead::file_read ("$iCfgFileLocation\\AutoSmoketests.cfg");
       
    45 my %iTests = $Smoketext =~ /^\s*(\w+\s*\w*\s*)=\s*(.+)$/mg ;
       
    46 
       
    47 my $iNumberOfTests = scalar(my @iTempArray = values %iTests);
       
    48 my $iCountCols = 3 + $iNumberOfTests;
       
    49  
       
    50 # container for smoketest result
       
    51 my $gSmokeTestResultsRef;
       
    52 
       
    53 ##########################################################################
       
    54 #
       
    55 # Name    : generateSTHTMLSummary()
       
    56 # Synopsis: Creates a Smoketest HTML report for the specified build.
       
    57 # Inputs  : Array containing Logs directory location, Product built and 
       
    58 #			path to link results
       
    59 # Outputs : HTML code that will be part of the HTML report generated 
       
    60 #			by GenResult.pm
       
    61 #
       
    62 # Note: Test Column Results can be interpreted as follows:
       
    63 #
       
    64 #	  OK: 			All test steps passed
       
    65 #	  Unexecuted:		Test unexecuted or log file not found.
       
    66 #	  Passed=x, Failed=y:	Results of test steps in the case of at least one failure 	
       
    67 #
       
    68 #       General Column Results can be interpreted as follows
       
    69 #       
       
    70 #	  OK: 			All smoke tests passing
       
    71 #	  Unexecuted: 		At least one smoke test was unexecuted 
       
    72 #	  FAILURES:             At least one failure in the smoke tests
       
    73 #	  CRITICAL FAILURES:	TestApps smoketest (which tests basic epoc functionality) has failed.      
       
    74 #
       
    75 ##########################################################################
       
    76 sub generateSTHTMLSummary
       
    77 {
       
    78 	my ($iDir, $iSnapshot, $iProduct, $iLinkPath) = @_;
       
    79 
       
    80 	$iLinkPath =~  s/[^\\]$/$&\\/; #add trailing backslash, if missing
       
    81 	$iSTLinkPath = $iLinkPath;
       
    82 	
       
    83 	my $html_out = "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" align=\"top\">";
       
    84 	$html_out .= "<tr bgcolor=\"#006699\" align=\"top\"><th colspan=" 
       
    85 	. $iCountCols .
       
    86 	" rowspan=2><font color=\"#ffffff\">AUTO Smoke Test Results</font></th></tr>"
       
    87 	."<tr></tr><tr bgcolor=\"#006699\" align=\"top\">";
       
    88 	
       
    89 	$iDir =~  s/[^\\]$/$&\\/; #add trailing backslash, if missing
       
    90 	$iSTPublishDir = $iDir;
       
    91 	
       
    92 
       
    93 	if (-e $iSTPublishDir)
       
    94 	{
       
    95 
       
    96 		print "\nGenerating Auto Smoke Test Report.";
       
    97 
       
    98 		my @iProductList = ($iProducts{$iProduct} =~ m/\S+/ig);
       
    99 		if (@iProductList < 1)
       
   100 		{
       
   101 			# this product is not supported?
       
   102 			$html_out .= "<td><center><b><font color=#ffffff>Smoke Test not supported for $iProduct</font></b></center></td></tr></table>";
       
   103 			return $html_out;
       
   104 		}
       
   105 		else
       
   106 		{
       
   107 			# Header of the table
       
   108 			$html_out .= "<th><font color=\"#ffffff\">Platform</font></th>
       
   109 						  <th><font color=\"#ffffff\">SUMMARY</font></th>";
       
   110 			foreach my $iTestName (sort { $iTests{$a} <=> $iTests{$b} } keys %iTests)
       
   111 			{
       
   112 				$html_out .= "<th><font color=\"#ffffff\">$iTestName</font></th>"
       
   113 			}
       
   114 			$html_out .= "<th><font color=\"#ffffff\">Defects</font></th></tr>";
       
   115 			
       
   116 			#iFlag = 0 for html mode, 1 for brag status mode
       
   117 			my $iFlag = 0; #The second value is a dummy value. It is only used when deriving Brag status.
       
   118 		 
       
   119 			$html_out .= printSTResultRow($iFlag,$iFlag, @iProductList);
       
   120 			# $html_out .= printDEVKITRow(@iProductList) 
       
   121 			$html_out .= "</table>";
       
   122 			return $html_out;
       
   123 		}
       
   124 	}
       
   125 	else
       
   126 	{
       
   127 		print "REMARK: Auto Smoke Test Report not created: $! \n";
       
   128 		return;
       
   129 	}
       
   130 }
       
   131 ############################################################
       
   132 # Name: printSTResultRow
       
   133 # Description: This function prints out the table rows for the auto smoketest build report
       
   134 #	       file that is published in the ESR database. It is also used in determining
       
   135 #	       the brag status and is called from Bragstatus.pm. If the iFlag value is set to
       
   136 #	       0 then it will process the html results. Otherwise it returns a brag status of 0-green,1-Amber(Some tests failed)
       
   137 #	       2-Red(All platforms failed); -1-TBA (smoke test results are not present for some reason).
       
   138 #
       
   139 ############################################################
       
   140 sub printSTResultRow
       
   141 {	 
       
   142 	my ($iFlag, $iLogPublishLocation,  @iProductList) = @_;
       
   143 	my $iFileName = "Test Summary Report\.htm";  
       
   144  
       
   145 	#Counts the number of platforms that have failed to be smoketested.
       
   146 	my $iplatform_counter = 0;
       
   147 
       
   148  	#Test and DEBUG COUNTER
       
   149 	my $iBragStatus = 0;	#0=Green,1=Amber,2=Red, -1=TBA
       
   150 	my $iFullRowSet;
       
   151 	my $iHTMLfileName = $iFileName;  
       
   152 	
       
   153 	# Process the results for each platform eg winscw, armv5 h4
       
   154 	foreach my $iPlatform (@iProductList)
       
   155       {
       
   156 		my @iPlatformSubDirs = split /_/, $iPlatform;
       
   157 		my $iTempPath;
       
   158 		 
       
   159 		# Get the full path name to the results file for this platform.
       
   160 		foreach my $iTempDir (@iPlatformSubDirs)
       
   161 		{
       
   162 			$iTempPath .= "$iTempDir\\";
       
   163 		}  
       
   164 
       
   165 		if($iFlag == 1)
       
   166 		{
       
   167 		$iSTPublishDir = $iLogPublishLocation;
       
   168 		}  
       
   169  
       
   170 		# Process the results if the results log exists
       
   171 		if (-e $iSTPublishDir.$iTempPath.$iFileName)  {
       
   172 
       
   173 		 
       
   174 		# Read in the results log
       
   175 		my $resultsFile = "$iSTPublishDir"."$iTempPath"."$iFileName";
       
   176 		open(RESULTSFILE, "<$resultsFile");
       
   177 		local $/ = undef; # undefine the input record separator to read in as one line.
       
   178 		my $results = <RESULTSFILE>;
       
   179 		close(RESULTSFILE);
       
   180 			
       
   181 		# Parse to make reading the file simpler
       
   182 		$results =~ s/\<TD\>//ig;
       
   183 		$results =~ s/\<\/TD\>//ig;
       
   184 		$results =~ s/\<td BGCOLOR \= .*?\>//ig;
       
   185 		
       
   186 		my $iTestResults = "";
       
   187 		my $unexecutedStatus 		= 0;
       
   188 		my $failureStatus 		= 0;
       
   189 		my $criticalFailureStatus 	= 0;
       
   190 
       
   191 			
       
   192 		# Add one table cell within the row for each smoke test 
       
   193 		foreach my $iTestName (sort { $iTests{$a} <=> $iTests{$b} } keys %iTests)
       
   194 			{
       
   195 			my $testScript = "$iTests{$iTestName}";
       
   196 			my $passed = 0;
       
   197 			my $failed = 0; 
       
   198 			my $testInLogFile = 0;
       
   199  
       
   200 			# Extract the script execution line for this test from the results.
       
   201 			if (	$results =~ /($testScript)\.script(?:\d)?(?:\.htm)?\s*(?:UDEB|UREL)\s*(\d*)\s*passed,\s*(\d*)\s*failed/i)
       
   202 			{		 
       
   203 				$testInLogFile = $1; 
       
   204  				$passed = $2;
       
   205 				$failed = $3; 
       
   206  			}
       
   207 
       
   208   			# Find result of test execution
       
   209 			if (!($testInLogFile))
       
   210 				{
       
   211 				$unexecutedStatus = 1;
       
   212 				$iTestResults .= "<td><font color=orange>";
       
   213 				$iTestResults .= "Unexecuted"."</font></td>";
       
   214 				$iBragStatus = -1;# At least one test is unexecuted
       
   215 				}
       
   216 			else
       
   217 				{
       
   218  				if (($failed==0) && ($passed > 0))
       
   219  					{
       
   220 					$iTestResults .= "<td><font color=green>";
       
   221 					$iTestResults .= "OK"."</font></td>";
       
   222   					}
       
   223   				else 
       
   224    					{
       
   225    					if ($failed > 0)
       
   226   						{ 
       
   227  						# Differentiate between the basic TestApps test (which just fires up
       
   228 						# the emulator and runs exes) and application tests (e.g. messaging). 
       
   229     						if ($testScript eq "smoketest_testapps")
       
   230     							{
       
   231 							$criticalFailureStatus = 1;
       
   232 							$iTestResults .= "<td><font color=red>";
       
   233 							$iBragStatus = 2;# Critical failures  
       
   234     							}
       
   235     						else
       
   236     							{
       
   237 							$failureStatus = 1;
       
   238 							$iTestResults .= "<td><font color=orange>";
       
   239 							$iBragStatus = 1; # At least one test has failed
       
   240     							}
       
   241 						$iTestResults .= "Passed="."$passed"." Failed="."$failed"."</font></td>";
       
   242   						}
       
   243 
       
   244  						}
       
   245 					 }
       
   246 			} # foreach my $iTestName
       
   247  
       
   248 			# Leave blank cell for defects 
       
   249 			$iTestResults .= "<td>&nbsp</td>";
       
   250 
       
   251 			 	
       
   252 			# Print out platform e.g. winscw (emulator) to start a new row in the results table
       
   253 			my $iRow = "<tr><td><a class =\"hoverlink\" href=\"" .&GenResult::setBrowserFriendlyLinks($iSTLinkPath.$iTempPath.$iHTMLfileName) ."\">"
       
   254 				.@iPlatformSubDirs[1]." ( ".@iPlatformSubDirs[0];
       
   255 			if (defined @iPlatformSubDirs[2])
       
   256 				{
       
   257 					$iRow .= " @iPlatformSubDirs[2] ";
       
   258 				}
       
   259 			$iRow .= " ) </a></td><td>";
       
   260 				
       
   261  
       
   262  			# Print the overall summary cell 
       
   263 			if ("$criticalFailureStatus")
       
   264 				{
       
   265 				$iRow .= "<font color=red>";
       
   266 				$iRow .= "CRITICAL FAILURES";  
       
   267 				}
       
   268 				else 
       
   269   					{
       
   270      					if ("$failureStatus")
       
   271      						{
       
   272       					$iRow .= "<font color=orange>";
       
   273 						$iRow .= "FAILURES";  
       
   274       					}
       
   275      					else 
       
   276      						{
       
   277         					if ("$unexecutedStatus")
       
   278         						{
       
   279           						$iRow .= "<font color=orange>";
       
   280 							$iRow .= "Unexecuted";  
       
   281         						}
       
   282         					else
       
   283         						{
       
   284 							$iRow .= "<font color=green>";
       
   285 							$iRow .= "OK";  
       
   286         						}
       
   287       					}
       
   288     					}
       
   289 
       
   290 
       
   291 			# Put the whole row together
       
   292 			$iRow .= "$iTestResults";
       
   293 			$iRow .= "</td>"; # end the last cell TD??
       
   294 			$iFullRowSet .= $iRow;
       
   295 
       
   296 		} # if (-e $iSTPublishDir.$iTempPath.$iFileName)
       
   297 		 
       
   298 
       
   299 		 
       
   300 	else # results file doesn't exist.
       
   301 		{
       
   302  
       
   303 		# smoke test directory for that platform has not been produced 
       
   304 		# - this is usually a sign that ROMs have not been made,
       
   305 		# or that the smoke tests haven't been run.
       
   306 			
       
   307 		my $iRow = "<tr><td>"
       
   308 		.@iPlatformSubDirs[1]." ( ".@iPlatformSubDirs[0];
       
   309 		if (defined @iPlatformSubDirs[2])
       
   310 			{
       
   311 			$iRow .= " @iPlatformSubDirs[2] ";
       
   312 			}
       
   313 		$iRow .= " ) </td><td>Smoke Test Not Run</td>";
       
   314 		foreach my $iTestName (sort { $iTests{$a} <=> $iTests{$b} } keys %iTests)
       
   315 			{
       
   316 			$iRow .= "<td><s>OK</s></td>";
       
   317 			}
       
   318 		$iRow .= "<td>&nbsp;</td></tr>";
       
   319 		$iFullRowSet .= $iRow;
       
   320 			
       
   321 		if($iFlag == 1) # BRAG status mode
       
   322 			{
       
   323 			$iplatform_counter++; #Platform Failed to be smoketested
       
   324 			$iBragStatus = 1; # Amber
       
   325 			}
       
   326 	} # if ( -e $iSTPublishDir.$iTempPath)
       
   327 	}# end foreach my $iPlatform (@iProductList) 
       
   328 	
       
   329 	# Return result depending on what the calling mode was
       
   330 	if($iFlag == 1)#bragstatus mode
       
   331 		{
       
   332 		if($iplatform_counter > 0) 
       
   333 			{
       
   334 			$iBragStatus = -1; # not all platforms have been smoketested.
       
   335 			}
       
   336 		return $iBragStatus;
       
   337 		}
       
   338 	else #Smoketest HTML mode
       
   339 		{
       
   340 		return $iFullRowSet;
       
   341 		}
       
   342 } # end sub
       
   343 sub printDEVKITRow
       
   344 {
       
   345 #access log file - Devkit.log on Devbuilds/Buildnumber/logs
       
   346 #open Devkit log file
       
   347 #if there are no ERROR: lines then print OK in General Column
       
   348 #else print Failed in General column
       
   349 #for all tests print N/A'
       
   350 
       
   351 #my $iDevkitLogFileLocation   = $iSTPublishDir.$iDevkitFileName;
       
   352 
       
   353     open (DevkitLOGFILE, $iSTPublishDir.$iDevkitFileName);
       
   354     my @iDevkitLog = <DevkitLOGFILE>;
       
   355     my $iRow = "<tr><td>";
       
   356 
       
   357     $iRow .= "DEVKIT</td>";
       
   358     my $iErrorCount = 0;
       
   359     my $iLineOK = 0;
       
   360     foreach (@iDevkitLog) {
       
   361        if (m/ERROR:/) 
       
   362              {
       
   363 		$iErrorCount++;		 
       
   364         }
       
   365 	     else
       
   366 	      {
       
   367 		$iLineOK++;
       
   368 	}
       
   369     }
       
   370 	      if ($iErrorCount > 0)
       
   371 	      {
       
   372 		$iRow .= "<td>Failed</td>";
       
   373 	  }
       
   374 	     else
       
   375 	      {
       
   376 	      $iRow .= "<td>OK</td>";
       
   377 	      }
       
   378 	      
       
   379     
       
   380     
       
   381 
       
   382 foreach my $iTestName (sort { $iTests{$a} <=> $iTests{$b} } keys %iTests)
       
   383 		{
       
   384 			$iRow .= "<td>N/A</td>";
       
   385 		}
       
   386 		
       
   387 	$iRow .= "<td>&nbsp;</td></tr>";
       
   388 
       
   389 return $iRow	
       
   390 }
       
   391 
       
   392 
       
   393 1;