common/tools/ats/smoketest/SmokeTest.pm
changeset 117 483f966c6335
child 872 17498133d9ad
equal deleted inserted replaced
113:7f0174848f99 117:483f966c6335
       
     1 # Copyright (c) 2004-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 the License "Symbian Foundation License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # SmokeTestSuite.pm 
       
    15 # The SmokeTestSuite package contains subroutines that are needed to build a 
       
    16 # testdriver test suite.
       
    17 # This script was born on 18/04/2005
       
    18 # 
       
    19 #
       
    20 
       
    21 #!/usr/bin/perl -w
       
    22 package SmokeTest;
       
    23 use SmokeTestROM;
       
    24 use SmokeTestSuite;
       
    25 use FindBin;
       
    26 use lib "$FindBin::Bin\\..\\..\\..\\..\\os\\buildtools\\bldsystemtools\\commonbldutils\\GenResult\\";
       
    27 use FileRead; #Need to include a Findbin::path
       
    28 use strict;
       
    29 
       
    30 #
       
    31 # Global Variables
       
    32 #
       
    33 our $BuildDir = $ENV{'BuildDir'}; # usually M:
       
    34 our $serverpool = $ENV{'SmokeTestServerPool'};
       
    35 our $buildNo = $ENV{'BuildShortName'}; # Eg. 9.1
       
    36 # The Client is run from the dir where SmokeTestClient.pl is located
       
    37 # This is to ensure that any ROMs and test packages created are stored there.
       
    38 our $sourceDir = "$BuildDir\\src\\common\\testtools";
       
    39 our $TestSuite = "SmokeTest";
       
    40 our $SmokeTestDir;
       
    41 our $NandDir;
       
    42 our $TestDriverLocation   = "\\epoc32\\tools\\TDEP";   # location for TD zips
       
    43 our $TestDriverDrive = "M:";
       
    44 our $TestDriverCmd = "$TestDriverDrive\\testdriver\\testdriver.cmd";
       
    45 our $TestDriverXML;
       
    46 
       
    47 # Publish details
       
    48 our $PublishServer = $ENV{'PublishLocation'};
       
    49 our $ProductType   = $ENV{'Type'};
       
    50 our $BuildNum      = $ENV{'BuildNumber'};
       
    51 our $LogsDir       = $ENV{'LogsDir'};
       
    52 
       
    53 # Epocwind.out
       
    54 my $tempDirLocation = $ENV{'TEMP'};
       
    55 
       
    56 #
       
    57 # CheckVars: ensures that the essential environment vars and directories exist
       
    58 #
       
    59 sub CheckVars
       
    60 {
       
    61 	print "\n** Settings **\n";
       
    62 	print "Build Drive                = $BuildDir\n";
       
    63 	print "Smoke Test Server Pool     = $serverpool\n";
       
    64 	print "Build Product              = $buildNo\n";
       
    65 	print "TestDriver Zip Location    = $TestDriverLocation\n";
       
    66 	print "TestDriver XML Location    = $TestDriverXML\n";
       
    67 	print "TestDriver Source Location = $sourceDir\n";
       
    68 	print "TestDriver Drive           = $TestDriverDrive\n";
       
    69 	print "SmokeTest working directory= $SmokeTestDir\n";
       
    70 	print "NAND build directory       = $NandDir\n";
       
    71 	
       
    72 	print "\n** Publishing Information **\n";
       
    73 	
       
    74 	print "Publish server = $PublishServer\n";
       
    75 	print "Product Type   = $ProductType\n";
       
    76 	print "Build Number   = $BuildNum\n";
       
    77 	
       
    78 	DieLog("CheckVars: \"Build Directory\" not defined") if !defined $BuildDir;
       
    79 	DieLog("CheckVars: \"Smoke Test Server Pool\" not defined") if !defined $serverpool;
       
    80 	DieLog("CheckVars: \"Build Product\" not defined") if !defined $buildNo;
       
    81 	DieLog("CheckVars: \"Publish server\" not defined") if !defined $PublishServer;
       
    82 	DieLog("CheckVars: \"Product Type\" not defined") if !defined $ProductType;
       
    83 	DieLog("CheckVars: \"Build Number\" not defined") if !defined $BuildNum;
       
    84 	DieLog("CheckVars: Directory \"SmokeTest working directory\" does not exist") if ! -e $SmokeTestDir;
       
    85 	DieLog("CheckVars: Directory \"TestDriver Zip Location\" does not exist") if ! -e $TestDriverLocation;
       
    86 }
       
    87 
       
    88 sub main
       
    89 {
       
    90 	print "\n\n*** START OF SMOKE TEST ***\n\n";
       
    91 
       
    92 	PrintDateTime();
       
    93 	
       
    94 	my ($iSourceDir,       $iTestSuite,   $iProduct, $iServerPool, $iProductType,
       
    95 	    $iPublishLocation, $iBuildNumber, $iXML,     $iUnzip,      $iBuildDrive, $iTDDrive) = @_;
       
    96 	
       
    97 	$TestSuite       = $iTestSuite           if defined $iTestSuite;
       
    98 	$BuildDir        = $iBuildDrive          if defined $iBuildDrive;
       
    99 	$sourceDir       = $BuildDir.$iSourceDir if defined $iSourceDir;
       
   100 	$buildNo         = $iProduct             if defined $iProduct;
       
   101 	$serverpool      = $iServerPool          if defined $iServerPool;
       
   102 	$ProductType     = $iProductType         if defined $iProductType;
       
   103 	$PublishServer   = $iPublishLocation     if defined $iPublishLocation;
       
   104 	$BuildNum        = $iBuildNumber         if defined $iBuildNumber;
       
   105 	$TestDriverDrive = $iTDDrive             if defined $iTDDrive;
       
   106 	
       
   107 	$SmokeTestDir    = "$sourceDir\\$TestSuite";
       
   108 	if (defined $iXML)
       
   109 	{
       
   110 		$TestDriverXML = $iXML;
       
   111 	}
       
   112 	else
       
   113 	{
       
   114 		$TestDriverXML = $SmokeTestDir."\\xml";
       
   115 	}
       
   116 	$NandDir = "$BuildDir\\src\\cedar\\generic\\base\\e32\\rombuild";
       
   117 	
       
   118 	CheckVars();
       
   119 	
       
   120 	# change dir to Smoketest dir
       
   121 	chdir "$SmokeTestDir" or DieLog("Can't cd to $SmokeTestDir");
       
   122 	
       
   123 	# unzip latest version of TD
       
   124 	if (defined $iUnzip)
       
   125 	{
       
   126 		unpackTestDriver2();
       
   127 	}
       
   128 	
       
   129 	# configure TD
       
   130 	configureTestDriver2();
       
   131 	
       
   132 	#
       
   133 	# Copy the correct configuration.cfg file
       
   134 	# But such source only exists for these products: 8.0a, 8.0b, 8.1a, 8.1b, 9.0, 9.1
       
   135 	#
       
   136 	print "\n#\n# Copy the correct configuration.cfg file\n#\n";
       
   137 	ExecCommand("COPY /Y $SmokeTestDir\\Group\\$buildNo\\configuration.cfg $SmokeTestDir\\Group\\configuration.cfg");
       
   138 	
       
   139 	#Read in hash of smoketests to be run for each product.
       
   140 	my ($iCfgFileLocation) = "$FindBin::Bin\\..\\..\\..\\..\\os\\buildtools\\bldsystemtools\\commonbldutils\\GenResult";
       
   141 	
       
   142 	#Read in the smoketest list from a cfg file
       
   143 	my $text = &FileRead::file_read ("$iCfgFileLocation\\Product.cfg");
       
   144 	#Search for an entry matching (At the beginning of line there should be 1 or more alphanumberic chars
       
   145 	#Followed by a "."(optional to allow codenames) followed by more alphanumberic chars followed by 0 or more spaces then an = then 0
       
   146 	#or more spaces then any amount of chars till the end of the line.
       
   147 	#8.1b = EMULATOR_WINSCW ARM4_LUBBOCK ARMV5_LUBBOCK
       
   148 	my %iProducts = $text =~ /^\s*(\w+\.?\w+)\s*=\s*(.+)$/mg ;
       
   149 	
       
   150 	#Get the list of platforms to be smoketested for the product.
       
   151 	#Need to turn the hash value into an array using split
       
   152 	my @iPlatforms = split (/ /,$iProducts{$buildNo});
       
   153 	#Build and Execute Test package for each platform as read from configuration file and create and zip rom.
       
   154 	ProcessPlatforms (@iPlatforms);
       
   155 	
       
   156 	#
       
   157 	# Build Test Package for ROMs
       
   158 	#
       
   159 	if ($buildNo eq '8.1a' || $buildNo eq '8.1b')
       
   160 	{
       
   161 		&SmokeTestSuite::BuildAndPackage("ARM4");
       
   162 	}
       
   163 	
       
   164 	if ($buildNo ne '8.1a')
       
   165 	{
       
   166 		&SmokeTestSuite::BuildAndPackage("ARMv5");
       
   167 	}
       
   168 	
       
   169 	#
       
   170 	# Find out which server to use
       
   171 	#
       
   172 	print "\n#\n# Find out which server to use\n#\n";
       
   173 	ProcessPlatformsforSmoketest(@iPlatforms);
       
   174 	
       
   175 	#
       
   176 	# End of Smoke Test
       
   177 	#
       
   178 	print "\n\n*** END OF SMOKE TEST ***\n\n";
       
   179 }
       
   180 	
       
   181 #
       
   182 # DieLog: Exits script and inserts a Remark in the build log, which will be picked up by htmlscanlog
       
   183 #
       
   184 sub DieLog
       
   185 {
       
   186 	die "\nREMARK: $_[0]\n $!\n\n\n";
       
   187 }
       
   188 
       
   189 
       
   190 #
       
   191 # Build and publish based on entries in the Product.cfg file
       
   192 #
       
   193 sub ProcessPlatforms 
       
   194 {
       
   195 
       
   196 my $i = 0;
       
   197 my @temp;
       
   198 my @iPlatforms = @_;
       
   199 
       
   200 foreach my $platform (@iPlatforms)
       
   201  {  
       
   202   undef @temp;
       
   203   @temp = split (/_/,$iPlatforms[$i]);
       
   204   $i++;
       
   205   
       
   206   if( $temp[0] eq "EMULATOR")
       
   207   {
       
   208 	&SmokeTestSuite::BuildAndPublish("$temp[1]");
       
   209 	CheckPlatsecErrors("$temp[1]");
       
   210   }
       
   211   else
       
   212   {
       
   213 		
       
   214 	if(3 == scalar(@temp)) # there are 3 arguments, so this will be a NAND ROM
       
   215 	{
       
   216 		if((lc($temp[1]) eq "h4hrp") && (lc($temp[2]) eq "nand\(dp\)" )) # H4HRP Demand Paging ROM options is -D_NAND2
       
   217 		{
       
   218 			&SmokeTestROM::CreateAndZipROM("$temp[0]", "$temp[1]", "pagedrom", "PlatSec", "$buildNo", "-D_NAND2" );
       
   219 		}
       
   220 		elsif((lc($temp[1]) eq "h4hrp") && (lc($temp[2]) eq "nand" )) # H4 options is -D_NAND2
       
   221 		{
       
   222 			&SmokeTestROM::CreateAndZipROM("$temp[0]", "$temp[1]", "-DRVCT", "PlatSec", "$buildNo", "-D_NAND2");
       
   223 		}
       
   224 		elsif(lc($temp[1]) eq "h2") # H2 options is -D_NAND# H2 option is NAND2 due to CR 0844 (Both H2 and H4 use -D_NAND2)
       
   225                 {
       
   226 			&SmokeTestROM::CreateAndZipROM("$temp[0]", "$temp[1]", "-DRVCT", "PlatSec", "$buildNo", "-D_NAND2");		
       
   227 		}
       
   228 		else	# Bad option entered
       
   229 		{
       
   230 			die "SmokeTest::ProcessPlatforms error: invalid board type entered: $temp[1]. Check that Product.cfg is correct.\n";
       
   231 		}		
       
   232 	}
       
   233 	else # This is the NOR ROM.
       
   234 	{
       
   235 		&SmokeTestROM::CreateAndZipROM("$temp[0]", "$temp[1]", "-DRVCT", "PlatSec", "$buildNo");
       
   236 	}
       
   237   }
       
   238   
       
   239  }
       
   240 
       
   241 }
       
   242 
       
   243 #
       
   244 # Build and publish based on entries in the Product.cfg file
       
   245 #
       
   246 sub ProcessPlatformsforSmoketest
       
   247 {
       
   248 
       
   249 my $i = 0;
       
   250 my @temp;
       
   251 my @iPlatforms = @_;
       
   252 
       
   253 foreach my $platform (@iPlatforms)
       
   254  {  
       
   255     undef @temp;
       
   256     @temp = split (/_/,$iPlatforms[$i]);
       
   257     $i++;
       
   258     if( $temp[0] eq "EMULATOR")
       
   259     {
       
   260         next;
       
   261     }
       
   262 	my $mServ = &SmokeTestSuite::PollServers("$temp[1]");
       
   263 	unless (defined $mServ)
       
   264     {
       
   265         next;
       
   266     }
       
   267 	if(3 == scalar(@temp))
       
   268 	{
       
   269 		if(lc($temp[2]) eq "nand\(dp\)" ) 
       
   270 		{
       
   271 		    &SmokeTestSuite::RunRemote("$temp[0]", "$temp[1]", $mServ, "NAND\(DP\)\\");
       
   272 		}
       
   273         elsif(lc($temp[2]) eq "nand") 
       
   274 	    {
       
   275 		    &SmokeTestSuite::RunRemote("$temp[0]", "$temp[1]", $mServ, "NAND\\");
       
   276 	    }
       
   277 	}
       
   278 	else
       
   279 	{
       
   280 		&SmokeTestSuite::RunRemote("$temp[0]", "$temp[1]", $mServ);
       
   281 	}
       
   282  }
       
   283 }
       
   284  
       
   285 #
       
   286 # Check for platsec errors - checks the epocwind.out on build machine
       
   287 #
       
   288 sub CheckPlatsecErrors
       
   289 {
       
   290 	print "\n";
       
   291 	print "#\n# Check for platsec errors\n#\n";
       
   292 	print "\n";
       
   293 	PrintDateTime();
       
   294 	
       
   295 	# open epocwind.out and parse for both errors and warnings
       
   296 	open EPOCWIND, "$tempDirLocation\\epocwind.out" or print "\nERROR: Cannot open EPOCWIND.OUT\n";
       
   297 	my @epocWind = <EPOCWIND>;
       
   298 	close EPOCWIND;
       
   299 	
       
   300 	foreach my $tempEW (@epocWind)
       
   301 	{
       
   302 		if ($tempEW =~ m/(\*PlatSec\* ERROR)(.*)/i)
       
   303 		{
       
   304 			print "\nERROR: $_[0] - $1$2";
       
   305 		}
       
   306 		elsif ($tempEW =~ m/(\*PlatSec\* WARNING)(.*)/i)
       
   307 		{
       
   308 			print "\nWARNING: $_[0] - $1$2";
       
   309 		}
       
   310 	}
       
   311 }
       
   312 
       
   313 #
       
   314 # Take TestDriver and unpack into a given location.
       
   315 #
       
   316 sub unpackTestDriver2()
       
   317 {
       
   318 	#
       
   319 	# Unzip TestDriver
       
   320 	#
       
   321 	print "\n#\n# Unzip TestDriver\n#\n";
       
   322 	PrintDateTime();
       
   323 	
       
   324 	# first remove the "old" version of test driver
       
   325 	print "\n";
       
   326 	ExecCommand("RMDIR $TestDriverDrive\\testdriver\\ /Q /S");
       
   327 	
       
   328 	# now unzip the latest version of testdriver which has been synced down
       
   329 	ExecCommand("%EPOCROOT%epoc32\\tools\\unzip.exe $TestDriverLocation\\TestDriver2.zip -d $TestDriverDrive\\testdriver\\");
       
   330 	
       
   331 	# now copy the latest version of testdriver_new.cmd which has been obtained
       
   332 	ExecCommand("COPY \\\\builds01\\devbuilds\\buildteam\\testdriverv2\\testdriver_new.cmd  $TestDriverCmd");
       
   333 	
       
   334 	# now copy the latest version of logging.properties which has been obtained
       
   335 	ExecCommand("COPY \\\\builds01\\devbuilds\\buildteam\\testdriverv2\\logging.properties  $TestDriverDrive\\testdriver\\");
       
   336 	
       
   337     # 11-08-08 - additional steps required for SITK1.2 version of TD2
       
   338     ExecCommand("MKDIR $TestDriverDrive\\testdriver\\eclipse\\links\\");
       
   339 
       
   340     ExecCommand("COPY \\\\builds01\\devbuilds\\buildteam\\testdriverv2\\testdriver.link $TestDriverDrive\\testdriver\\eclipse\\links\\");
       
   341 	
       
   342 	#
       
   343 	# Unzip JRE v1.5
       
   344 	#
       
   345 	print "\n";
       
   346 	print "#\n# Unzip JRE 1.5 required by TestDriver v2\n#\n";
       
   347 	print "\n";
       
   348 	
       
   349 	ExecCommand("%EPOCROOT%epoc32\\tools\\unzip.exe \\\\builds01\\devbuilds\\BuildPCs\\Software\\JDK1.5.0_13\\jre1.5.zip -d $TestDriverDrive\\testdriver\\");
       
   350 
       
   351 }
       
   352 
       
   353 sub configureTestDriver2()
       
   354 {
       
   355 	#
       
   356 	# Configure TestDriver
       
   357 	#
       
   358 	print "\n";
       
   359 	print "#\n# Configure TestDriver\n#\n";
       
   360 	print "\n";
       
   361 	my $localtimes = localtime;
       
   362 	PrintDateTime();
       
   363 	
       
   364 	ExecCommand("$TestDriverDrive\\testdriver\\testdriver.cmd config -e $BuildDir\\
       
   365 								-x $TestDriverXML
       
   366 								-l $TestDriverDrive\\TestDriver\\Results
       
   367 								--source $sourceDir
       
   368 								-s smoketest
       
   369 								-r $TestDriverDrive\\TestDriver\\Repos
       
   370 								-c $TestDriverDrive\\TestDriver\\Results");
       
   371 
       
   372 	ExecCommand("$TestDriverDrive\\testdriver\\testdriver.cmd config --commdb overwrite");
       
   373 	ExecCommand("$TestDriverDrive\\testdriver\\testdriver.cmd config --bldclean off");
       
   374 
       
   375 	# platsec for > 9.x only
       
   376 	if ($buildNo ne "8.1a" && $buildNo ne "8.1b")
       
   377 	{
       
   378 		ExecCommand("$TestDriverDrive\\testdriver\\testdriver.cmd config -p ON");
       
   379 	}
       
   380 	
       
   381 	# Setup commdb for WINSCW smoketest
       
   382 	print "\n*** Setup commdb for WINSCW to use WinTAP ***\n";
       
   383 	
       
   384 	# export smoketest_commdb.xml to a place that ced.exe can see it
       
   385 	ExecCommand("copy $SmokeTestDir\\smoketest_commdb.xml $BuildDir\\epoc32\\WINSCW\\c\\");
       
   386 	ExecCommand("$BuildDir\\epoc32\\release\\WINSCW\\udeb\\ced.exe c:\\smoketest_commdb.xml");
       
   387 	
       
   388 	print "\n*** Confirm TestDriver Config ***\n";
       
   389 	ExecCommand("$TestDriverDrive\\testdriver\\testdriver.cmd config");
       
   390 	print "\n";
       
   391 }
       
   392 
       
   393 # ExecCommand
       
   394 #
       
   395 # Execute a system command, having first echoed it. Display and return the output of the command.
       
   396 #
       
   397 # Input: Command string (without final newline)
       
   398 #
       
   399 # Output: Command output (including STDERR) to STDOUT
       
   400 #
       
   401 # Return: Command output (including STDERR)
       
   402 #
       
   403 sub ExecCommand
       
   404 {
       
   405     my $iCmd = shift;
       
   406     print "\n================================================================\n";
       
   407     print "Command: $iCmd\n";
       
   408     print   "----------------------------------------------------------------\n";
       
   409     my $iRet = `$iCmd 2>&1`;
       
   410     chomp $iRet;
       
   411     print "Return:  $iRet\n";
       
   412     print   "================================================================\n";
       
   413     return $iRet;
       
   414 }
       
   415 
       
   416 # PrintDateTime
       
   417 #
       
   418 # Print to STDOUT, Current Date and Time
       
   419 #
       
   420 # Input: none
       
   421 #
       
   422 # Output: text to STDOUT
       
   423 #
       
   424 sub PrintDateTime
       
   425 {
       
   426     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
       
   427     #### my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time);
       
   428     $year += 1900;
       
   429     $mon += 1;
       
   430 	printf "\n*** Current Time: %04d/%02d/%02d %02d:%02d:%02d ***\n", $year,$mon,$mday,$hour,$min,$sec;
       
   431 }
       
   432 
       
   433 1;