installationservices/switestfw/test/autotesting/cdrive.pl
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 #
       
     2 # Copyright (c) 2006-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 the License "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 # Created by Relja Arandjelovic
       
    16 # relja.arandjelovic@symbian.com
       
    17 # Used to check for occurrences of "C: , EDriveC and [<index>]='C' and report warnings about it into HTML file
       
    18 # USAGE:
       
    19 # cdrive.pl -exclude=exclude.txt -excludedir=/common/generic/security/caf2/ -log=logfilename.htm path1 path2 ...
       
    20 # log is created in $ENV{EPOCROOT}epoc32\\winscw\\c\\
       
    21 # add -mytest option if the log should be stored in the execution directory
       
    22 # (for example, if you are not using the script during overnight builds)
       
    23 # exclude contains items formated as as follows (new line corresponds to new line in file):
       
    24 # filename
       
    25 # line content
       
    26 # comment about why the warning should be excluded (may be in several lines, but with no line with only whice characters)
       
    27 # line with only white characters
       
    28 # NB: paths in cdrive.pl argumetns and filename in exclude list should be absolute paths
       
    29 #
       
    30 
       
    31 use strict;
       
    32 use Getopt::Std;
       
    33 use Getopt::Long;
       
    34 use File::Find;
       
    35 
       
    36 my @ListOfFiles=();
       
    37 my @FileIsTest=();
       
    38 my $nTests=0;
       
    39 my %Exclude=();
       
    40 
       
    41 my $exclude="";
       
    42 my $excludedir="_no_dir_";
       
    43 my $LogFileName="";
       
    44 
       
    45 
       
    46 
       
    47 ################
       
    48 ########
       
    49 sub TypeOfWarning($$$$){
       
    50 	my ($FileName,$FileIsTest,$linetext,$Warning)=@_;
       
    51 	
       
    52 	$linetext=~ s/^\s*//; $linetext=~ s/\s*$//;
       
    53 
       
    54 	$$Warning="warning";
       
    55 	
       
    56 	if ($FileIsTest==1){
       
    57 		$$Warning="test";
       
    58 	} else {
       
    59 		# check if in include list
       
    60 	
       
    61 		my $ExcludeLine;
       
    62 		foreach $ExcludeLine (@{$Exclude{$FileName}}){
       
    63 			if ($linetext eq $ExcludeLine) {
       
    64 				$$Warning="ignoredwarning";
       
    65 				last;
       
    66 			}
       
    67 		}		
       
    68 	}
       
    69 	
       
    70 }
       
    71 	
       
    72 	
       
    73 	
       
    74 ################
       
    75 ########
       
    76 
       
    77 
       
    78 my $FirstWarning=1;
       
    79 my $PrevFileName="_no_file_";
       
    80 
       
    81 sub printHTML($$$$){
       
    82 	my ($FileName,$linenumber,$linetext,$Warning)=@_;
       
    83 
       
    84 	
       
    85 	$linetext=~ s/^\s*//; $linetext=~ s/\s*$//;
       
    86 
       
    87 	# convert special characters to HTML format
       
    88 	$linetext=~ s/&/&amp;/sg;
       
    89 	$linetext=~ s/</&lt;/sg;
       
    90 	$linetext=~ s/>/&gt;/sg;
       
    91 	
       
    92 
       
    93 	if ($FileName ne $PrevFileName){
       
    94 		print HTML "
       
    95 <tr><td colspan=\"4\" height=\"20\">&nbsp;</td></tr>
       
    96 	<tr><td width=\"20\"></td><td colspan=\"3\">
       
    97 		$FileName
       
    98 	</td></tr>	
       
    99 ";
       
   100 	}
       
   101 	
       
   102 	print HTML "
       
   103 <tr><td colspan=\"4\" height=\"10\">&nbsp;</td></tr>
       
   104 		<tr class=\"$Warning\"><td width=\"20\"></td><td width=\"60\"></td><td colspan=\"2\">
       
   105 			Line number: $linenumber
       
   106 		</td></tr>
       
   107 			<tr class=\"$Warning\"><td width=\"20\"></td><td width=\"60\"></td><td width=\"80\"></td><td>
       
   108 $linetext
       
   109 			</td></tr>
       
   110 ";
       
   111 	
       
   112 	$PrevFileName=$FileName;
       
   113 	$FirstWarning=0;
       
   114 }
       
   115 
       
   116 ################
       
   117 ########
       
   118 my $prevDir="_no_previous_dir_";
       
   119 my $isTest=0;
       
   120 
       
   121 sub MakeList(){
       
   122 	
       
   123 
       
   124 	if (lc($File::Find::dir) =~ /^$excludedir/) { return; }
       
   125 	if (lc($File::Find::dir) =~ /test/i) { return; }
       
   126 	if (lc($File::Find::dir) =~ /examples/i) { return; }
       
   127 	if (lc($File::Find::dir) =~ /tpkcs10/i) { return; }
       
   128 	if (lc($File::Find::dir) =~ /tocsp/i) { return; }
       
   129 	if (lc($File::Find::dir) =~ /dumpswicertstoretool/i) { return; }
       
   130 	if (!(lc($File::Find::name) =~ /\.(cpp|cxx|c\+\+|c|h)$/)){ return; }
       
   131 	
       
   132 	# include in list of files to be searched only if not test code
       
   133 	# ie distribution policy doesn't include Reference/Test
       
   134 	if ($prevDir ne lc($File::Find::dir)){ # new dir => search for distribution.policy	
       
   135 		$isTest=0;
       
   136 		my $policy="".($File::Find::dir)."/distribution.policy";
       
   137 		
       
   138 		if (-e $policy){
       
   139 			open (POLICY , "<$policy" );
       
   140 			while (<POLICY>){
       
   141 				if ($_ =~ /Reference\/Test/){
       
   142 					$isTest=1;
       
   143 					last;
       
   144 				}
       
   145 			}
       
   146 			close (POLICY);
       
   147 		}
       
   148 	}
       
   149 	
       
   150 	push(@ListOfFiles,lc($File::Find::name));
       
   151 	push(@FileIsTest,$isTest);	
       
   152 	if ($isTest) { $nTests++; }
       
   153 	
       
   154 	$prevDir=lc($File::Find::dir);
       
   155 }
       
   156 
       
   157 ################
       
   158 ########
       
   159 sub FindC($$$$){
       
   160 	my ($FileName,$FileIsTest,$count,$countunique)=@_;
       
   161 			
       
   162 	open(SOURCE,"<$FileName") or die ("Could not open file: $FileName");
       
   163 	
       
   164 	my $prevCount=$$count;
       
   165 	my $line; my $templine; my $linenumber=1;
       
   166 	my $MultiLineComment=0;
       
   167 	my $MadeChangeDueToComments;
       
   168 	my $FirstLine=0;
       
   169 	
       
   170 	my $HTMLFirstWarning=1;
       
   171 	
       
   172 	while ($line=<SOURCE>){
       
   173 	
       
   174 		$templine=$line;
       
   175 		$linenumber++;
       
   176 		$FirstLine=0;
       
   177 		
       
   178 		# process comments
       
   179 		do {
       
   180 		
       
   181 			$MadeChangeDueToComments=0;
       
   182 		
       
   183 			if ($MultiLineComment==0){
       
   184 		
       
   185 				# remove text in // coments 
       
   186 				$templine=~ s/(.*?)\/\/.*$/$1/;
       
   187 				# remove /* */ comments found in one line
       
   188 				$templine=~ s/\/\*.*\*\///g;
       
   189 			
       
   190 				# if only /* then remove text after it and mark the start of comment
       
   191 				if ($templine=~ /^(.*?)\/\*/){
       
   192 					$templine=$1;
       
   193 					$MultiLineComment=1;
       
   194 					$MadeChangeDueToComments=1;
       
   195 					$FirstLine=1;
       
   196 				}
       
   197 			
       
   198 			} else {	# $MultiLineComment==1
       
   199 		
       
   200 				# if */ end comment
       
   201 				if ($templine=~ /\*\/(.*)$/){
       
   202 					$templine=$1;
       
   203 					$MultiLineComment=0;
       
   204 					$MadeChangeDueToComments=1;				
       
   205 				}
       
   206 			
       
   207 			}
       
   208 			
       
   209 		} while ($MadeChangeDueToComments==1);
       
   210 		# end of processing comments
       
   211 		
       
   212 		
       
   213 		if ($MultiLineComment==1 && $FirstLine==0) { next; } # skip checking if in comment
       
   214 	
       
   215 	
       
   216 		if (
       
   217 			$templine=~ /["'][cC]:/	|| # '" # need comment for correct highlighting in codewarrior
       
   218 			$templine=~ /EDriveC/		||
       
   219 			$templine=~ /\[.+\]\s*=\s*'[cC]':/
       
   220 			){
       
   221 			
       
   222 				my $Warning;
       
   223 				TypeOfWarning($FileName,$FileIsTest,$line,\$Warning);
       
   224 				printHTML($FileName,$linenumber,$line,$Warning);
       
   225 				if ($Warning eq "warning") { $$count++; }
       
   226 				
       
   227 			}
       
   228 		
       
   229 	}
       
   230 	
       
   231 	close(SOURCE);
       
   232 	
       
   233 	if ($prevCount<$$count) { $$countunique++; }
       
   234 }
       
   235 
       
   236 ################
       
   237 ########
       
   238 sub ReadExcludeList(){
       
   239 
       
   240 	#print "\n";
       
   241 	
       
   242 	
       
   243 	if ($exclude eq ""){
       
   244 		#print "Exclude list file not specified\nCarrying on without an exclude list\n";
       
   245 		return;
       
   246 	} elsif (!(-e $exclude)){
       
   247 		#print "Exclude list file doesn't exist!\nCarrying on without an exclude list\n";
       
   248 		return;
       
   249 	}
       
   250 	
       
   251 	
       
   252 	my $line; my $FileName; my $LineText; my $justification;
       
   253 	
       
   254 	open (EXCLUDE,"<$exclude");
       
   255 	while (1){
       
   256 	
       
   257 		$line=<EXCLUDE> or last;
       
   258 		$line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
       
   259 		$line=~ s/\\/\//g;
       
   260 		$FileName=lc($line);
       
   261 		
       
   262 		$line=<EXCLUDE>; $line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
       
   263 		$LineText=$line;
       
   264 		
       
   265 		$justification=0;
       
   266 		while($line=<EXCLUDE>){
       
   267 			$line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
       
   268 			if ($line eq "") { last;}
       
   269 			$justification=1;
       
   270 		}
       
   271 		
       
   272 		if ($justification==0){
       
   273 			#print "Not added to the excludion list since no justification found for:\n$FileName\n$LineText\n";
       
   274 		} else {		
       
   275 			push(@{$Exclude{$FileName}},$LineText);
       
   276 		}
       
   277 		
       
   278 	}
       
   279 	close(EXCLUDE);
       
   280 	
       
   281 }
       
   282 
       
   283 ################
       
   284 ######## Main
       
   285 
       
   286 	
       
   287 	my $MyTest=0;
       
   288 	
       
   289 	GetOptions(
       
   290 			"exclude=s" => \$exclude ,
       
   291 			"excludedir=s" => \$excludedir, # one dir to be excluded from scaning (along wih its subdirs)
       
   292 			"log=s" => \$LogFileName,
       
   293 			"mytest" => \$MyTest # inteded for my personal testing (so that path is not the one for overnight testing)
       
   294 				);
       
   295 	
       
   296 	$excludedir=~ s/\\/\//g; # convert \ into / so that it matches perl's path form
       
   297 	
       
   298 	ReadExcludeList();
       
   299 
       
   300 	
       
   301 	if ($MyTest==0){ # overnight
       
   302 		$LogFileName = "$ENV{EPOCROOT}epoc32\\winscw\\c\\".$LogFileName;
       
   303 	}
       
   304 
       
   305 			
       
   306 	my $iArgv;
       
   307 	for ($iArgv=0;$iArgv<@ARGV;$iArgv++){
       
   308 		$ARGV[$iArgv]=~ s/\\/\//g; # convert \ into / so that it matches perl's path form
       
   309 		find(\&MakeList, ($ARGV[$iArgv]) );
       
   310 	}
       
   311 
       
   312 	
       
   313 	open(HTML,">$LogFileName");
       
   314 	print HTML "
       
   315 <html>
       
   316 
       
   317 <head>
       
   318 	<title>CDrive warnings</title>
       
   319 	
       
   320 	<style type=\'text/css\'>
       
   321 .warning {
       
   322 	background-color: #FFAAAA;
       
   323 }
       
   324 .ignoredwarning {
       
   325 	background-color: #90ffff;
       
   326 }
       
   327 .test{
       
   328 	background-color: #ffc060;
       
   329 }
       
   330 	</style>
       
   331 </head>
       
   332 <body>	
       
   333 	<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">
       
   334 ";
       
   335 	
       
   336 
       
   337 	my $count=0; my $countunique=0;
       
   338 	my $iList; my $nList=@ListOfFiles;
       
   339 	for ($iList=0;$iList<$nList;$iList++){
       
   340 		FindC($ListOfFiles[$iList],$FileIsTest[$iList],\$count,\$countunique);
       
   341 	}
       
   342 
       
   343 	
       
   344 	print HTML "\n</table>\n";
       
   345 
       
   346 	my $total=$nList-$nTests;
       
   347 	# workaround in order to be reported to the standardised system	
       
   348 	print HTML "<br><center>$countunique tests failed out of $total\n</center>\n";	
       
   349 	
       
   350 	print HTML "
       
   351 </body>
       
   352 </html>	
       
   353 	";
       
   354 	
       
   355 	#print "\n\tNumber of files:\t$nList\n";
       
   356 	#print "\n\tNumber of warnings:\t$count\n";
       
   357 	#print "\n\tNumber of unique warnings:\t$countunique\n";
       
   358 	
       
   359 	close(HTML);
       
   360 
       
   361 ################
       
   362 ######## end-Main
       
   363