secureswitools/swisistools/test/tinterpretsisinteg/swicheck.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 # 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 File::Copy;
       
    29 use Cwd;
       
    30 
       
    31 if (@ARGV <6)
       
    32 	{
       
    33 	print "Failed: Invalid parameters\n", join(", ",@ARGV);
       
    34 	exit();
       
    35 	}
       
    36 # setup Path
       
    37 my $CURR_WORK_DIR = getcwd();
       
    38 my $TEST_EXECUTE = "\\epoc32\\release\\WINSCW\\udeb\\testexecute.exe";
       
    39 my $CDRIVE_PATH =$CURR_WORK_DIR."\\cdrive";
       
    40 my $ROMDRIVE_PATH =$CURR_WORK_DIR."\\romdrive";
       
    41 my $DDRIVE_PATH ="\\ddrive";
       
    42 my $EDRIVE_PATH =$CURR_WORK_DIR."\\edrive";
       
    43 my $ORIGINAL_DATA_PATH = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\data";
       
    44 my $SWICDRIVE_PATH = "\\epoc32\\winscw\\c";
       
    45 my $PARAMS_PATH = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\parameters_file";
       
    46 my $testdata = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\sisfiles";
       
    47 my $TEF_LOGS_PATH= "\\epoc32\\winscw\\c\\logs\\testexecute\\";
       
    48 my $iniFile = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\parameters_file\\parameters.ini";
       
    49 my $logFile = "\\epoc32\\winscw\\c\\interpretsis_test_harness.txt";
       
    50 # Process Command line arguments
       
    51 my $logfilename		 =  shift @ARGV;
       
    52 my $testid			 =  shift @ARGV;
       
    53 my $param_filename	 =  shift @ARGV;# contains the file to be searched
       
    54 my $testing			 =  shift @ARGV;
       
    55 my $positivetc		 =  shift @ARGV;# positive/negative Test case
       
    56 my $removedrives	 =  shift @ARGV;# remove drives (both/c_only/rom_only/none)
       
    57 my $uid				 =  shift @ARGV;
       
    58 my $batchfile		 =  shift @ARGV;
       
    59 my $scriptfile		 =  shift @ARGV;
       
    60 my $htmlfile		 =  shift @ARGV;
       
    61 my $NRsearch		 =  shift @ARGV;
       
    62 my $errorcodesearch	 =  shift @ARGV;
       
    63 my $comparetext      =	shift @ARGV;# Text to be compared from file
       
    64 # flags
       
    65 my $passflag = 0;  # flag for pass or fail
       
    66 my $count;         # to keep track of results.
       
    67 my @searchedpath;
       
    68 my $searchresult;  # flag for searching file
       
    69 my $filename;
       
    70 my $debug = 0;     # flag to turn on debug log
       
    71 
       
    72 if($testing eq 1)
       
    73 {
       
    74 	check($CDRIVE_PATH);
       
    75 
       
    76 	if(!$passflag)
       
    77 	{
       
    78 		goto res;
       
    79 	}
       
    80 	&TefFunction($scriptfile);
       
    81 	&CompareIntSwi();
       
    82 }
       
    83 
       
    84 elsif($testing eq 2)
       
    85 {	
       
    86 	&TefFunction($scriptfile);
       
    87 	check($SWICDRIVE_PATH);
       
    88 }
       
    89 elsif($testing eq 3)
       
    90 {
       
    91 	&TefFunction($scriptfile); 
       
    92 	$passflag = 0;
       
    93 	&CheckTefLogs($htmlfile,$NRsearch,$errorcodesearch,$TEF_LOGS_PATH);
       
    94 }
       
    95 elsif($testing eq 4)
       
    96 {	
       
    97 	&TefFunction($scriptfile);
       
    98 	check($SWICDRIVE_PATH);
       
    99 	&CheckTefLogs($htmlfile,$NRsearch,$errorcodesearch,$TEF_LOGS_PATH);
       
   100 	&Cleanup();
       
   101 }
       
   102 elsif($testing eq 5)
       
   103 {	
       
   104 	&TefFunction($scriptfile);
       
   105 	check($SWICDRIVE_PATH);
       
   106 	my @file = &GetParams($param_filename);
       
   107 	&ReadText(@file);
       
   108 }
       
   109 
       
   110 res:
       
   111 &Result();
       
   112 
       
   113 if($removedrives eq "both")
       
   114 {
       
   115 	&RemoveDir($CDRIVE_PATH);
       
   116 	&RemoveDir($ROMDRIVE_PATH);
       
   117 }
       
   118 elsif($removedrives eq "c_only")
       
   119 {
       
   120 	&RemoveDir($CDRIVE_PATH);
       
   121 }
       
   122 elsif($removedrives eq "rom_only")
       
   123 {
       
   124 	&RemoveDir($ROMDRIVE_PATH);
       
   125 }
       
   126 elsif($removedrives eq "all")
       
   127 {
       
   128 	&RemoveDir($CDRIVE_PATH);
       
   129 	&RemoveDir($ROMDRIVE_PATH);
       
   130 	&RemoveDir($DDRIVE_PATH);
       
   131 	&RemoveDir($EDRIVE_PATH);
       
   132 }
       
   133 
       
   134 &RemoveDir($testdata);
       
   135 
       
   136 
       
   137 # Checks for file/files
       
   138 sub check($)
       
   139 {	
       
   140 	WriteLog("INFO: check($_[0])\n");
       
   141 
       
   142 	my $drive_path=$_[0];
       
   143 	my @param_array = &GetParams($param_filename); 
       
   144 
       
   145 	if ($param_filename eq 'PARAM_INI' && $#param_array == -1)
       
   146 	{
       
   147 	  $passflag = 1;
       
   148 	  return; 
       
   149 	}
       
   150 
       
   151 	my $temp;
       
   152 	my $filenotexist = 0;
       
   153 
       
   154 	$searchresult = 0;
       
   155 	foreach $temp (@param_array)											
       
   156 	{
       
   157 		# Rest flags
       
   158 		$searchresult = 0;
       
   159 		$filenotexist = 0;		
       
   160 		
       
   161 		$filename = trim($temp);
       
   162 		if($filename eq "")
       
   163 		{
       
   164 			# Blank line found - no file to check
       
   165 			$passflag = 1;
       
   166 			return; 
       
   167 		}
       
   168 
       
   169 		# if the filename has been prefixed with "*", the file should not be present on the system drive (C:\)
       
   170 		if(rindex($filename,"*") == 0)
       
   171 		{
       
   172 			$filenotexist = 1;
       
   173 			$filename = substr($filename,1);
       
   174 		}
       
   175 
       
   176 		find (\&scan,$drive_path);
       
   177 		if ($positivetc eq "positive") 
       
   178 		{	
       
   179 			# If the file is not found and the 'not exists' flag is not set OR the file is found 
       
   180 			# when the 'not exists' flag is set...Fail the test
       
   181 			if(($searchresult == 0 && $filenotexist == 0) || ($searchresult == 1 && $filenotexist == 1))
       
   182 			{
       
   183 			$passflag = 0;
       
   184 			return;
       
   185 			}
       
   186 		}
       
   187 	
       
   188 		# The "not exists" flag is not checked within negative tests to prevent ambiguity
       
   189 		if ($positivetc eq "negative" && $searchresult == 1)
       
   190 		{
       
   191 			$passflag = 0;
       
   192 			return;
       
   193 		}
       
   194 
       
   195 		$passflag = 1;					
       
   196 	}
       
   197 }
       
   198 
       
   199 sub scan
       
   200 {	
       
   201 	WriteLog("INFO: scan()\n");
       
   202 
       
   203 	my $path = $File::Find::name;
       
   204 		
       
   205 	if (-f $path && !($File::Find::name=~m/data/)) # Exclude the data folder path of harness
       
   206 	{	
       
   207 		chomp($filename);
       
   208 		if (basename($path) eq $filename)
       
   209 		{
       
   210 			$searchresult =  1;
       
   211 			$File::Find::name=~ s/\//\\/g;
       
   212 			push @searchedpath,$File::Find::name;
       
   213 			return;
       
   214 		}
       
   215 	}
       
   216 }
       
   217 
       
   218 # Get the files to be searched from the parameters files.
       
   219 sub GetParams($)
       
   220 {
       
   221 	WriteLog("INFO: GetParams($_[0]\)\n");
       
   222 
       
   223 	my $file = $_[0];
       
   224 	my $param_file = $PARAMS_PATH."/".$file;
       
   225 	my @param_list = ();
       
   226 	my $sectionFound = 0;
       
   227 	if ($file eq 'PARAM_INI')
       
   228 	{
       
   229 		# Read the parameter .ini file
       
   230 		my @iniText = ();
       
   231 
       
   232 		if (open(INI_FILE, $iniFile))
       
   233 		{
       
   234 			@iniText = <INI_FILE>;
       
   235 			close(INI_FILE);
       
   236 		}
       
   237 		
       
   238 		for (my $line = 0;  $line < @iniText;  $line++)
       
   239 		{
       
   240 			if ($iniText[$line] =~ /^\s*\[$testid\]\s*$/i)
       
   241 			{
       
   242 				$sectionFound = 1;
       
   243 				next;
       
   244 			}
       
   245 			
       
   246 			if ($sectionFound && ($iniText[$line] !~ /^\s*$/))
       
   247 			{
       
   248 				push (@param_list, trim($iniText[$line]));
       
   249 			}
       
   250 			else
       
   251 			{
       
   252 				if ($sectionFound == 1)
       
   253 				{
       
   254 					return @param_list;
       
   255 				}
       
   256 			}
       
   257 		}
       
   258 	}
       
   259 	else
       
   260 	{
       
   261 		opendir (FILE, $PARAMS_PATH) || die;
       
   262 		open(FILE, $param_file) || die;	
       
   263 		@param_list = <FILE>;
       
   264 		close(FILE);
       
   265 	}
       
   266 	
       
   267 	return @param_list;
       
   268 }
       
   269 
       
   270 
       
   271 
       
   272 # Executes the batch file passed as argument
       
   273 sub RunBatch($)
       
   274 {
       
   275   WriteLog("INFO: RunBatch($_[0])\n");
       
   276   my $batchfile = $_[0];
       
   277   `/epoc32/winscw/c/tswi/tinterpretsisinteg/$batchfile`;
       
   278 }
       
   279 
       
   280 
       
   281 
       
   282 # Cleans off all the files present in the folder passed as an argument.
       
   283 sub RemoveDir($)
       
   284 {
       
   285 	WriteLog("INFO: RemoveDir($_[0])\n");
       
   286 	my $dir  =  $_[0];
       
   287 	my $name;
       
   288 	opendir(DIRHANDLE, $dir) || die "can't open file $dir $!";
       
   289 	foreach $name (sort readdir(DIRHANDLE))
       
   290 		{
       
   291 		if ($name ne "." && $name ne ".." && $name ne "indir1" && $name ne "indir2") 
       
   292 			{
       
   293 			if (-d "$dir/$name")
       
   294 				{
       
   295 					&RemoveDir("$dir/$name");
       
   296 					rmdir("$dir/$name");
       
   297 				}
       
   298 			else 
       
   299 				{
       
   300 					unlink("$dir/$name");
       
   301 				}
       
   302 			}
       
   303 		}
       
   304 	closedir(DIRHANDLE);
       
   305 }
       
   306 
       
   307 sub trim($)
       
   308 {
       
   309 	WriteLog("INFO: trim($_[0])\n");
       
   310 	my $string = shift;
       
   311 	$string =~ s/\s+$//;
       
   312 	return $string;
       
   313 }
       
   314 sub CompareIntSwi()
       
   315 {	
       
   316   	WriteLog("INFO: CompareIntSwi()\n");
       
   317 	my @searchswi;
       
   318 	foreach my $interpretsisfilepath (@searchedpath)											
       
   319 	{
       
   320 		my $filenameswi = basename(trim($interpretsisfilepath));
       
   321 		if($filename eq "")
       
   322 		{
       
   323 			 return;
       
   324 		}
       
   325 		elsif($interpretsisfilepath=~/bin/)
       
   326 		{	
       
   327 			my $bin_path=$SWICDRIVE_PATH."\\sys\\bin\\".$filenameswi;	
       
   328 			$bin_path=~ s/ \/ / \\ /g;
       
   329 			push @searchswi,$bin_path;
       
   330 		}
       
   331 		elsif($interpretsisfilepath=~/hash/)
       
   332 		{	
       
   333 			my $hash_path=$SWICDRIVE_PATH."\\sys\\hash\\".$filenameswi;
       
   334 			$hash_path=~ s/\//\\/g;
       
   335 			push @searchswi,$hash_path;
       
   336 		}
       
   337 		elsif($interpretsisfilepath=~/$uid/)
       
   338 		{	
       
   339 			my $registry_path=$SWICDRIVE_PATH."\\sys\\install\\sisregistry\\".$uid."\\".$filenameswi;
       
   340 			$registry_path=~ s/\//\\/g;
       
   341 			push @searchswi,$registry_path;
       
   342 		}
       
   343 	}
       
   344     my $count=@searchswi;
       
   345     foreach my $interpretsisfilepath (@searchedpath)
       
   346 	{
       
   347 		foreach my $swifiles  (@searchswi)
       
   348 		{
       
   349 			if(compare($interpretsisfilepath,$swifiles) ==  0)
       
   350 			{
       
   351 				if(-s $interpretsisfilepath == -s $swifiles)
       
   352 				{	
       
   353 					$count--;
       
   354 				}
       
   355 			}
       
   356 			else
       
   357 			{
       
   358 				$passflag = 0;
       
   359 			}
       
   360 
       
   361 		
       
   362 		}	
       
   363 	}
       
   364 	if($count == 0)
       
   365 	{
       
   366 		$passflag = 1;
       
   367 	}
       
   368 }
       
   369 
       
   370 sub Result()
       
   371 {
       
   372 	if($passflag == 1)
       
   373 	{
       
   374 		print "Passed\n";
       
   375 	}
       
   376 	else
       
   377 	{
       
   378 		print "Failed\n";
       
   379 	}
       
   380 }
       
   381 sub TefFunction($)
       
   382 {
       
   383 	WriteLog("INFO: TefFunction($_[0])\n");
       
   384 	my $script=$_[0];
       
   385 	`$TEST_EXECUTE c:\\tswi\\tinterpretsisinteg\\scripts\\$script`;
       
   386 }
       
   387 
       
   388 
       
   389 sub CheckTefLogs
       
   390 {
       
   391 	WriteLog("INFO: CheckTefLogs($_[3].$_[0])\n");
       
   392 	my $LOGFILE=$_[3].$_[0];
       
   393 	opendir (FILE,$TEF_LOGS_PATH) || die;
       
   394 	open(FILE, $LOGFILE) or die("Could not open log file or directory $!");
       
   395 	foreach my $line (<FILE>)
       
   396 	{
       
   397 	my $NRvalue=$_[1];
       
   398 	my $Errocodevalue=$_[2];
       
   399 	if (($line =~/$NRvalue/) || ($line =~/$Errocodevalue/))
       
   400 	{
       
   401 	$passflag = 1;
       
   402 	}
       
   403 	}
       
   404 	close(LOGFILE);
       
   405 
       
   406 }
       
   407 
       
   408 # Searches for text in the file
       
   409 sub ReadText(@)
       
   410 {
       
   411 	WriteLog("INFO: ReadText($_[0])\n");
       
   412 
       
   413 	if($passflag eq 1)
       
   414 	{		
       
   415 		my $file  =  $_[0];
       
   416 		my @filepath  =  grep(/$file/,@searchedpath);
       
   417 		my $output_file  =  @filepath[0];
       
   418 		open(FILE,$output_file ) || die;	
       
   419 		my $param_list  =  <FILE>;
       
   420 		close(FILE );
       
   421 		if(trim($param_list) eq trim($comparetext))
       
   422 		{	
       
   423 			$passflag = 1;
       
   424 				if ($positivetc eq "negative") 
       
   425 				{
       
   426 					goto res;
       
   427 				}	
       
   428 		}
       
   429 		else
       
   430 		{
       
   431 			$passflag = 0;
       
   432 				if ($positivetc eq "positive") 
       
   433 				{
       
   434 					goto res;
       
   435 				}			
       
   436 		}
       
   437 	}
       
   438 	else
       
   439 	{
       
   440 		goto res;
       
   441 	}
       
   442 }
       
   443 
       
   444 #
       
   445 #Function to write log into file
       
   446 #
       
   447 sub WriteLog {
       
   448   if ($debug)
       
   449     {
       
   450       my ($log) = @_;
       
   451       my $fh;
       
   452 
       
   453       unless( open($fh, ">> $logFile"))
       
   454 	{
       
   455 	  printf STDERR "Can\'t open $logFile:$!\n";
       
   456 	  return;
       
   457 	}
       
   458       printf $fh $log;
       
   459       close $fh;
       
   460     }
       
   461 }
       
   462 
       
   463 # Performs any cleanup which needs to take place after a TEF script has been executed
       
   464 sub Cleanup()
       
   465 {
       
   466 	my $cr1027RomStub = "\\epoc32\\release\\WINSCW\\udeb\\z\\system\\install\\CR1027ROMUpgradeStub.sis";
       
   467 	my $cr1027RomStub_temp = "\\epoc32\\release\\WINSCW\\udeb\\z\\system\\CR1027ROMUpgradeStub.sis";
       
   468 	move($cr1027RomStub_temp, $cr1027RomStub);
       
   469 }
       
   470