secureswitools/swisistools/test/tinterpretsisinteg/check.pl
changeset 0 ba25891c3a9e
child 50 c6e8afe0ba85
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 # ARGV 1 : Log File Name
       
    16 # ARGV 2 : Test Id
       
    17 # ARGV 3 : parameter file name (files to be searched)
       
    18 # ARGV 4 : Testing (scenarios)
       
    19 # ARGV 5 : positivetc (positive test case or negative)
       
    20 # ARGV 6 : removedrives ("both" - remove C & Z drives, "c_only" - remove C drive only, "rom_only" - remove rom drive only, "none" - leave in current state)
       
    21 #
       
    22 
       
    23 
       
    24 use strict;
       
    25 use File::Find;
       
    26 use File::Compare;
       
    27 use File::Basename;
       
    28 use Cwd;
       
    29 
       
    30 if (@ARGV <6)
       
    31 	{
       
    32 	print "Failed: Invalid parameters\n", join(", ",@ARGV);
       
    33 	exit();
       
    34 	}
       
    35 # setup Path
       
    36 my $CURR_WORK_DIR = getcwd();
       
    37 my $CDRIVE_PATH =$CURR_WORK_DIR."\\cdrive";
       
    38 my $ROMDRIVE_PATH =$CURR_WORK_DIR."\\romdrive";
       
    39 my $ORIGINAL_DATA_PATH = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\data";
       
    40 my $PARAMS_PATH = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\parameters_file";
       
    41 my $TEST_DIR = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg";
       
    42 my $testdata = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\sisfiles";
       
    43 my $logs = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\logs";
       
    44 my $iniFile = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\parameters_file\\parameters.ini";
       
    45 my $logFile = "\\epoc32\\winscw\\c\\interpretsis_test_harness.txt";
       
    46 # Process Command line arguments
       
    47 my $logfilename		 =  shift @ARGV;
       
    48 my $testid			 =  shift @ARGV;
       
    49 my $param_filename	 =  shift @ARGV;# contains the file to be searched
       
    50 my $testing			 =  shift @ARGV;# 1 (only check) 2 (check and compare) 3 (check and get text)
       
    51 my $positivetc		 =  shift @ARGV;# positive/negative Test case
       
    52 my $removedrives	 =  shift @ARGV;# remove drives (both/c_only/rom_only/none)
       
    53 my $comparetext      =	shift @ARGV;# Text to be compared from file
       
    54 my $batchfile		 =  shift @ARGV;
       
    55 my $LogfileSearch	 =  shift @ARGV;# to search the logs gereated for H002 in logs folder.
       
    56 my $LogFilePresent	 = 	shift @ARGV;# to search the logs gereated for H002 in logs folder.
       
    57 
       
    58 
       
    59 # flags
       
    60 my $searchresult;  # flag for searching file
       
    61 my $passflag = 0;  # flag for pass or fail
       
    62 my $debug = 0;     # flag to turn on debug log
       
    63 
       
    64 # Variables needed by functions
       
    65 my $outputfileforcompare; 
       
    66 my $filename;
       
    67 my @searchedpath;
       
    68 
       
    69 if($testing eq 1)
       
    70 {
       
    71 	&Initialize();
       
    72 	&check();
       
    73 }
       
    74 elsif($testing eq 2)
       
    75 {
       
    76 	&Initialize();
       
    77 	&check();
       
    78 	&CompareFileWithOriginal($ORIGINAL_DATA_PATH);
       
    79 }
       
    80 elsif($testing eq 3)
       
    81 {
       
    82 	&Initialize();
       
    83 	&check();
       
    84 	CheckFileText();
       
    85 }
       
    86 
       
    87 # To check  sis files which are not supported by interpretsis are not processess through makesis "-c" also.
       
    88 elsif($testing eq 4)
       
    89 {
       
    90 	&Initialize();
       
    91 	&check();
       
    92 	&RemoveDir($testdata);
       
    93 	&RunBatch($batchfile);
       
    94 	&SisCheck();
       
    95 }
       
    96 # To check that Makesis will reject pre-installed packages marked as non-removable and of type PA and PP.
       
    97 elsif($testing eq 5)
       
    98 {
       
    99 	&RunBatch($batchfile);
       
   100 	&SisCheck();
       
   101 }
       
   102 elsif($testing eq 6)
       
   103 {
       
   104 	&Initialize();
       
   105 	&check();
       
   106 	if(!$passflag)
       
   107 	{
       
   108 		goto res;
       
   109 	}
       
   110 	
       
   111 	&SearchLog($LogfileSearch,$logs);
       
   112 	&RemoveDir($logs);					
       
   113 }
       
   114 
       
   115 elsif($testing eq 7)
       
   116 {
       
   117 	&Initialize();
       
   118 	&check();
       
   119 	&UnicodeFileCheck();
       
   120 }
       
   121 
       
   122 res:
       
   123 &Result();
       
   124 
       
   125 if($removedrives eq "both")
       
   126 {
       
   127 	&RemoveDir($CDRIVE_PATH);
       
   128 	&RemoveDir($ROMDRIVE_PATH);
       
   129 }
       
   130 elsif($removedrives eq "c_only")
       
   131 {
       
   132 	&RemoveDir($CDRIVE_PATH);
       
   133 }
       
   134 elsif($removedrives eq "rom_only")
       
   135 {
       
   136 	&RemoveDir($ROMDRIVE_PATH);
       
   137 }
       
   138 
       
   139 &RemoveDir($testdata);
       
   140 
       
   141 
       
   142 # Folder doesn't exist ,create it
       
   143 sub Initialize()
       
   144 {
       
   145 	WriteLog("INFO: Initialize()\n");
       
   146 	if(!-d $ROMDRIVE_PATH) 
       
   147 	{
       
   148 		my $dir = `mkdir $ROMDRIVE_PATH`;
       
   149 	}
       
   150 	if(!-d $CDRIVE_PATH) 
       
   151 	{
       
   152 		my $dir = `mkdir $CDRIVE_PATH`;
       
   153 	}
       
   154 }
       
   155 # Checks for file/files
       
   156 sub check()
       
   157 {
       
   158 	WriteLog("INFO: check($param_filename)\n");
       
   159 	my @param_array = &GetParams($param_filename); 
       
   160 	my $temp;
       
   161 	my $filenotexist = 0;
       
   162 
       
   163 	if ($param_filename eq 'PARAM_INI' && $#param_array == -1)
       
   164 	{
       
   165 	  $passflag = 1;
       
   166 	  return; 
       
   167 	}
       
   168 
       
   169 	foreach $temp (@param_array)
       
   170 	{		
       
   171 		# Rest flags
       
   172 		$searchresult = 0;
       
   173 		$filenotexist = 0;
       
   174 	
       
   175 		$filename = trim($temp);
       
   176 		if($filename eq "")
       
   177 		{
       
   178 			# Blank line found - no file to check
       
   179 			$passflag = 1;
       
   180 			return; 
       
   181 		}
       
   182 
       
   183 		# if the filename has been prefixed with "*", the file should not be present on the system drive (C:\)
       
   184 		if(rindex($filename,"*") == 0)
       
   185 		{
       
   186 			$filenotexist = 1;
       
   187 			$filename = substr($filename,1);
       
   188 		}
       
   189 		
       
   190 		find (\&scan, $CDRIVE_PATH);
       
   191 		if ($positivetc eq "positive") 
       
   192 		{	
       
   193 			# If the file is not found and the 'not exists' flag is not set OR the file is found 
       
   194 			# when the 'not exists' flag is set...Fail the test
       
   195 			if(($searchresult == 0 && $testing != 2 && $filenotexist == 0) || ($searchresult == 1 && $testing != 2 && $filenotexist == 1))
       
   196 			{
       
   197 			$passflag = 0;
       
   198 			return;
       
   199 			}
       
   200 		}
       
   201 
       
   202 		# The "not exists" flag is not checked within negative tests to prevent ambiguity
       
   203 		if ($positivetc eq "negative" && $searchresult == 1 && $testing != 2)
       
   204 		{
       
   205 			$passflag = 0;
       
   206 			return;
       
   207 		}
       
   208 
       
   209 		$passflag = 1;					
       
   210 	}
       
   211 }
       
   212 
       
   213 sub scan
       
   214 {	
       
   215 	WriteLog("INFO: scan()\n");
       
   216 	my $path = $File::Find::name;
       
   217 	
       
   218 	if (-f $path) 
       
   219 	{	
       
   220 		chomp($filename);
       
   221 		if (basename($path) eq $filename)
       
   222 		{
       
   223 			$searchresult =  1;
       
   224 			push @searchedpath,$File::Find::name;
       
   225 			return;
       
   226 		}
       
   227 	}
       
   228 }
       
   229 
       
   230 # Searches for text in the file
       
   231 sub CheckFileText()
       
   232 {
       
   233 	my @param_array = &GetParams($param_filename);
       
   234 	my $file;
       
   235 
       
   236 	WriteLog("INFO: CheckFileText($param_filename)\n");
       
   237 
       
   238 	if($passflag eq 1)
       
   239 	{
       
   240 	  foreach $file (@param_array)
       
   241 	    { 
       
   242 	      my $filename = trim($file);
       
   243 	      my @filepath  =  grep(/$filename/,@searchedpath);
       
   244 	      my $output_file  =  @filepath[0];
       
   245 	      WriteLog("INFO: CheckFileText $filename output ($output_file)\n");
       
   246 	      open(FILE,$output_file ) || die;	
       
   247 	      my $param_list  =  <FILE>;
       
   248 	      close(FILE );
       
   249 	      if(trim($param_list) eq trim($comparetext))
       
   250 		{
       
   251 		  $passflag = 1;
       
   252 		  if ($positivetc eq "negative") 
       
   253 		    {
       
   254 		      goto res;
       
   255 		    }	
       
   256 		}
       
   257 	      else
       
   258 		{
       
   259 		  $passflag = 0;
       
   260 		  if ($positivetc eq "positive") 
       
   261 		    {
       
   262 		      goto res;
       
   263 		    }			
       
   264 		}
       
   265 	    }
       
   266 	}
       
   267 	else
       
   268 	{
       
   269 		goto res;
       
   270 	}
       
   271 }
       
   272 
       
   273 
       
   274 
       
   275 sub trim($)
       
   276 {
       
   277 	WriteLog("INFO: trim()\n");
       
   278 	my $string = shift;
       
   279 	$string =~ s/\s+$//;
       
   280 	return $string;
       
   281 }
       
   282 # Compares the original data with the installed data
       
   283 sub CompareFileWithOriginal($) 
       
   284 {	
       
   285 	if($passflag == 1)
       
   286 	{
       
   287 		my @outfilespath;
       
   288 		my $originalfile  =  $_[0]."/".$filename;
       
   289 		$passflag = 0;
       
   290 		WriteLog("INFO: CompareFileWithOriginal() originalfile = $originalfile\n");
       
   291 		my $outputfileforcompare; 
       
   292 		@outfilespath  =  grep(-f, @searchedpath);
       
   293 		foreach $outputfileforcompare (@outfilespath)
       
   294 		{	
       
   295 			if(compare($outputfileforcompare,$originalfile) ==  0)
       
   296 			{ 
       
   297 		  		$passflag = 1;
       
   298 				if($positivetc eq "negative")
       
   299 				{
       
   300 					 $passflag = 0;
       
   301 				}
       
   302 			}
       
   303 			else
       
   304 			{
       
   305 				$passflag = 0;
       
   306 				if($positivetc eq "negative")
       
   307 				{
       
   308 					$passflag = 1;
       
   309 				}
       
   310 			}
       
   311 		}
       
   312 	}
       
   313 }
       
   314 
       
   315 
       
   316 # Get the files to be searched from the parameters files.
       
   317 sub GetParams($)
       
   318 {
       
   319 	WriteLog("INFO: GetParams($_[0])\n");
       
   320 	my $file = $_[0];
       
   321 	my $param_file = $PARAMS_PATH."/".$file;
       
   322 	my @param_list = ();
       
   323 	my $sectionFound = 0;
       
   324 	if ($file eq 'PARAM_INI')
       
   325 	{
       
   326 		# Read the parameter .ini file
       
   327 		my @iniText = ();
       
   328 
       
   329 		if (open(INI_FILE, $iniFile))
       
   330 		{
       
   331 			@iniText = <INI_FILE>;
       
   332 			close(INI_FILE);
       
   333 		}
       
   334 		
       
   335 		for (my $line = 0;  $line < @iniText;  $line++)
       
   336 		{
       
   337 			if ($iniText[$line] =~ /^\s*\[$testid\]\s*$/i)
       
   338 			{
       
   339 				$sectionFound = 1;
       
   340 				next;
       
   341 			}
       
   342 			
       
   343 			if ($sectionFound && ($iniText[$line] !~ /^\s*$/))
       
   344 			{
       
   345 				push (@param_list, trim($iniText[$line]));
       
   346 			}
       
   347 			else
       
   348 			{
       
   349 				if ($sectionFound == 1)
       
   350 				{
       
   351 					return @param_list;
       
   352 				}
       
   353 			}
       
   354 		}
       
   355 	}
       
   356 	else
       
   357 	{
       
   358 		opendir (FILE, $PARAMS_PATH) || die;
       
   359 		open(FILE, $param_file) || die "can't open file $param_file $!";	
       
   360 		@param_list = <FILE>;
       
   361 		close(FILE);
       
   362 	}
       
   363 	
       
   364 	return @param_list;
       
   365 }
       
   366 # Cleans off all the files present in the folder passed as an argument.
       
   367 sub RemoveDir($)
       
   368 {
       
   369 	WriteLog("INFO: RemoveDir($_[0])\n");
       
   370 	my $dir  =  $_[0];
       
   371 	my $name;
       
   372 	opendir(DIRHANDLE, $dir) || die "can't open dir $dir $!";
       
   373 	foreach $name (sort readdir(DIRHANDLE))
       
   374 		{
       
   375 		if ($name ne "." && $name ne ".." && $name ne "indir1" && $name ne "indir2") 
       
   376 			{
       
   377 			if (-d "$dir/$name")
       
   378 				{
       
   379 					&RemoveDir("$dir/$name");
       
   380 					rmdir("$dir/$name");
       
   381 				} 
       
   382 			else 
       
   383 				{
       
   384 					unlink("$dir/$name");
       
   385 				}
       
   386 			}
       
   387 		}
       
   388 	closedir(DIRHANDLE);
       
   389 }
       
   390 
       
   391 # Checks for the presence of the sis files in test data folder
       
   392 sub SisCheck()
       
   393 {
       
   394 	WriteLog("INFO: SisCheck()\n");
       
   395 opendir FILE, $testdata || die ;
       
   396 my $sis = grep (/\.sis$/, readdir(FILE));
       
   397 if($testing eq 5)
       
   398 	{
       
   399 	if ($sis == 1) 
       
   400 		{
       
   401 			$passflag = 1;
       
   402 			return;
       
   403 		}
       
   404 			$passflag = 0;
       
   405 			return;
       
   406 	}
       
   407 if ($sis)
       
   408 	{ 
       
   409 		$passflag = 0;
       
   410 		goto res;
       
   411 	}
       
   412 else
       
   413 	{
       
   414 		$passflag = 1;
       
   415 	}
       
   416 }
       
   417 
       
   418 # Executes the batch file passed as argument
       
   419 sub RunBatch($)
       
   420 {
       
   421 my $batchfile = $_[0];
       
   422 `/epoc32/winscw/c/tswi/tinterpretsisinteg/$batchfile`;
       
   423 }
       
   424 
       
   425 sub Result()
       
   426 {
       
   427 	if($passflag == 1)
       
   428 	{
       
   429 		print "Passed\n";
       
   430 	}
       
   431 	else
       
   432 	{
       
   433 		print "Failed\n";
       
   434 	}
       
   435 }
       
   436 
       
   437 sub SearchLog($$)# testcase H002
       
   438 {
       
   439 	WriteLog("INFO: SearchLog($_[0])\n");
       
   440 my $searchfile = $_[0];
       
   441 my $path = $_[1];
       
   442 if ($searchfile eq "")
       
   443 	{
       
   444 	return;
       
   445 	}
       
   446 opendir(D,$path) or die "Could not read directory $path!\n";
       
   447 my @files = readdir(D);
       
   448 closedir(D);
       
   449 $passflag = 0;
       
   450 while (@files) 
       
   451 	{
       
   452 	my $files = shift @files;
       
   453 	if( $files =~ m/$searchfile/i)
       
   454 		{
       
   455 		$passflag = 1;
       
   456 		}
       
   457 	}
       
   458 
       
   459 if($LogFilePresent eq "absent" && $passflag == 1)
       
   460 	{
       
   461 	$passflag = 0;
       
   462 	}
       
   463 if($LogFilePresent eq "absent" && $passflag == 0)
       
   464 	{
       
   465 	$passflag = 1;
       
   466 	}
       
   467 }
       
   468 
       
   469 #
       
   470 #Function to write log into file
       
   471 #
       
   472 sub WriteLog {
       
   473   if ($debug)
       
   474     {
       
   475       my ($log) = @_;
       
   476       my $fh;
       
   477 
       
   478       unless( open($fh, ">> $logFile"))
       
   479 	{
       
   480 	  printf STDERR "Can\'t open $logFile:$!\n";
       
   481 	  return;
       
   482 	}
       
   483       printf $fh $log;
       
   484       close $fh;
       
   485     }
       
   486 }
       
   487 
       
   488 
       
   489 sub UnicodeFileCheck()# INC124436
       
   490 {
       
   491 my $testval=system("WScript.exe //B //Nologo $TEST_DIR\\inc124436.vbs");
       
   492 if($testval == 0)
       
   493 	{
       
   494 		$passflag = 0;
       
   495 	}
       
   496 	else
       
   497 	{
       
   498 		$passflag = 1;
       
   499 	}
       
   500 }
       
   501