installationservices/switestfw/test/autotesting/RunSecurityTests.pl
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 #
       
     2 # Copyright (c) 2005-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 #
       
    16 
       
    17 use strict;
       
    18 
       
    19 ##################################################################################
       
    20 # These variables can be customised as required
       
    21 # define some global variables - customise as required
       
    22 my $REPORTDIR;
       
    23 my $MAINLINEZIPDIR;
       
    24 my $RELSUBSYSROOT;
       
    25 my $TECHVIEWROOT;
       
    26 
       
    27 # set variables which can be set from the environment. If no environment
       
    28 # equivalent is found, it will set to the default
       
    29 SetVariable(\$REPORTDIR, "REPORTDIR", "L:\\AutoSecTests");
       
    30 SetVariable(\$MAINLINEZIPDIR, "MAINLINEZIPDIR", "\\\\builds01\\Master");
       
    31 SetVariable(\$RELSUBSYSROOT, "RELSUBSYSROOT", "security");
       
    32 
       
    33 # To include Techview in build set environment variable:
       
    34 # TECHVIEWROOT=Techview
       
    35 SetVariable(\$TECHVIEWROOT, "TECHVIEWROOT", "");
       
    36 
       
    37 # host platforms define which platforms are to be built and tests to run. Target
       
    38 # platforms are those where roms are build
       
    39 my @HOSTPLATFORMS = ("wins", "winscw");
       
    40 my @TARGETPLATFORMS = ("arm4", "thumb");
       
    41 my @ROMPLATFORMS = ("lubbock", "assabet");
       
    42 my @BUILDTYPES = ("udeb", "urel");
       
    43 #
       
    44 # END of customisable variables
       
    45 ####################################################################################
       
    46 
       
    47 my $P4CLIENTNAME = ConfigureDefaultClient();
       
    48 my $TESTCONFIGFILE;
       
    49 my $SUBSYSTEMROOT;
       
    50 # beech or cedar 
       
    51 my $BUILDPLATFORM; 
       
    52 
       
    53 # first get the date
       
    54 my @DATEARRAY = split(/[ \/]/, `date /t`);
       
    55 
       
    56 # command line arguments
       
    57 my %ARGS = ();
       
    58 
       
    59 # Parse command line parameters
       
    60 ProcessCommandLine();
       
    61 
       
    62 # now, DATEARRAY[0] will be day, 1 will be date of month, 2 will be month, 3 is year
       
    63 my $RESULTDIR = "$REPORTDIR\\$DATEARRAY[3]$DATEARRAY[2]$DATEARRAY[1]";
       
    64 
       
    65 # define the file where the config.txt file is post-processed
       
    66 my $POSTPROCESSED = "$RESULTDIR\\postprocessed.txt";
       
    67 
       
    68 # create a new directory for today
       
    69 system("mkdir \"$RESULTDIR\"");
       
    70 
       
    71 # create a logfile and error file
       
    72 open  (LOGFILE, "> $RESULTDIR\\log.txt") || die "error opening for writing";
       
    73 open  (ERRFILE, "> $RESULTDIR\\error.txt") || die "error opening for writing";
       
    74 
       
    75 # Derive rootdrive from perforce client. Set up variables
       
    76 # which required the root drive to be configured. Note that
       
    77 # the test config file is only overwritten if not configured by
       
    78 # the command line. By default it looks for config.txt in the current
       
    79 # directory
       
    80 my $ROOTDRIVE = "L:";
       
    81 GetRootDrive();
       
    82 if (!$TESTCONFIGFILE)
       
    83 {
       
    84 	use Cwd;
       
    85 	my $dir = cwd();
       
    86 	$TESTCONFIGFILE = "$dir\\config.txt";
       
    87 }
       
    88 if (!$SUBSYSTEMROOT)
       
    89 { 
       
    90 	$SUBSYSTEMROOT = "$ROOTDRIVE\\$RELSUBSYSROOT";
       
    91 }
       
    92 
       
    93 if ($TECHVIEWROOT)
       
    94 {
       
    95 	$TECHVIEWROOT = "$ROOTDRIVE\\$TECHVIEWROOT";
       
    96 }
       
    97 
       
    98 # epoc root directory
       
    99 my $EPOCROOT = "$ROOTDRIVE\\epoc32";
       
   100 
       
   101 # add techview to build if requested
       
   102 my @BUILDDIRS = "";
       
   103 if ( $TECHVIEWROOT )
       
   104 {
       
   105 	@BUILDDIRS = ( $SUBSYSTEMROOT, "$TECHVIEWROOT\\toolkit\\startup\\group", "$TECHVIEWROOT\\apps\\appinstui\\group", "$TECHVIEWROOT\\apps\\secui\\group");
       
   106 }
       
   107 else
       
   108 {
       
   109 	@BUILDDIRS = ( $SUBSYSTEMROOT );
       
   110 }
       
   111 
       
   112 print "BUILDIRS = @BUILDDIRS\n";
       
   113 
       
   114 # call main
       
   115 main();
       
   116 
       
   117 # main function 
       
   118 sub main()
       
   119 {
       
   120 	print "REPORTDIR = $REPORTDIR\n";
       
   121 	print "MAINLINEZIPDIR = $MAINLINEZIPDIR\n";
       
   122 	print "SUBSYSTEMROOT = $SUBSYSTEMROOT\n";
       
   123 	print "TESTCONFIGFILE = $TESTCONFIGFILE\n";
       
   124 	print "TECHVIEWROOT = $TECHVIEWROOT\n";
       
   125 	print "BUILDPLATFORM = $BUILDPLATFORM\n";
       
   126 
       
   127 	# Figure out the second-latest release if none had been specified on the
       
   128 	# command line - we do not want the latest in case it has not yet been released. 
       
   129 	my $releasedir = "";
       
   130 	my $platformsuffix = "";
       
   131 	if ($BUILDPLATFORM)
       
   132 	{
       
   133 		$platformsuffix = "_$BUILDPLATFORM";
       
   134 	}
       
   135 
       
   136 	if (!$ARGS{"mainline"})
       
   137 	{
       
   138 		my $filelist = `dir $MAINLINEZIPDIR\\0????$platformsuffix /ad /b | sort /r`;
       
   139 		my @filearray = split "\n", $filelist;
       
   140 		$releasedir = $filearray[1];
       
   141 	}
       
   142 	else
       
   143 	{
       
   144 		$releasedir = "$ARGS{\"mainline\"}$platformsuffix";
       
   145 	}
       
   146 
       
   147 	# Display what's to be done
       
   148 	ReportToFiles("------ Script run on $DATEARRAY[1]/$DATEARRAY[2]/$DATEARRAY[3] with the following options\n");
       
   149 	ReportToFiles("------       Report directory: $REPORTDIR\n");
       
   150 	ReportToFiles("------       Subsystem root: $SUBSYSTEMROOT\n");
       
   151 	ReportToFiles("------       Test config file: $TESTCONFIGFILE\n");
       
   152 	ReportToFiles("------       Built against MCL platform: $BUILDPLATFORM\n");
       
   153 	if ($ARGS{s}) { ReportToFiles("------      Perforce synchronisation using client spec \"$P4CLIENTNAME\" on drive \"$ROOTDRIVE\"\n"); }
       
   154 	if ($ARGS{u}) { ReportToFiles("------      Mainline unzip using build $releasedir\n"); }
       
   155 	if ($ARGS{b}) { ReportToFiles("------      Build of production and test code\n"); }
       
   156 	if ($ARGS{t}) { ReportToFiles("------      Running of test code on the host using $TESTCONFIGFILE\n"); }
       
   157 	if ($ARGS{f}) { ReportToFiles("------      Build rom first\n"); }
       
   158 	if ($ARGS{t}) { ReportToFiles("------      Running of test code on the host using $TESTCONFIGFILE\n"); }
       
   159 
       
   160 	if ($ARGS{r}) 
       
   161 	{ 
       
   162 		ReportToFiles("------      Building of target roms: "); 
       
   163 		map { ReportToFiles("$_ "); } @ROMPLATFORMS;
       
   164 		ReportToFiles("\n");
       
   165 	}
       
   166 	ReportToFiles("------      Host builds used: ");
       
   167 	map { ReportToFiles("$_ "); } @HOSTPLATFORMS;
       
   168 	ReportToFiles("\n------      Target processor builds used: ");
       
   169 	map { ReportToFiles("$_ "); } @TARGETPLATFORMS;
       
   170 	ReportToFiles("\n------      Build types used: ");
       
   171 	map { ReportToFiles("$_ "); } @BUILDTYPES;
       
   172 	ReportToFiles("\n\n");
       
   173 
       
   174 	# Do a perforce sync
       
   175 	if ($ARGS{s})
       
   176 	{
       
   177 		DoPerforceSync();
       
   178 	}
       
   179 
       
   180 	# Now unzip the mainline
       
   181 	if ($ARGS{u})
       
   182 	{
       
   183 		DoMainlineUnzip($releasedir);
       
   184 	}
       
   185 
       
   186 	# Build the post-processed config file if the test flag is on
       
   187 	if ($ARGS{t})
       
   188 	{
       
   189 		ParseTestConfigFile();
       
   190 	}
       
   191 
       
   192     # Build the tools
       
   193 	if ($ARGS{o})
       
   194 	{
       
   195 		foreach my $bt (@BUILDTYPES)
       
   196 		{
       
   197 			DoBuildTools($bt);
       
   198 		}
       
   199 	}
       
   200 
       
   201 	# Build rom first?
       
   202 	if ( $ARGS{f} ) 
       
   203 	{
       
   204 		# Now build the target platforms - no testing required
       
   205 		if ($ARGS{b})
       
   206 		{
       
   207 			foreach my $platform (@TARGETPLATFORMS)
       
   208 			{
       
   209 				foreach my $bt (@BUILDTYPES)
       
   210 				{
       
   211 					# Must build dummy midp2installerclient for cedar
       
   212 					if ( $BUILDPLATFORM eq "cedar" )
       
   213 					{
       
   214 						my @tempbuilddirs = @BUILDDIRS;
       
   215 						@BUILDDIRS = ("$SUBSYSTEMROOT\\appinst\\tsrc");
       
   216 						print "Building dummy midp2installerclient....on $platform/$bt\n";
       
   217 						DoBuild($platform, $bt);
       
   218 						# now build the rest
       
   219 						@BUILDDIRS = @tempbuilddirs;
       
   220 					}
       
   221 					DoBuild($platform, $bt);
       
   222 				}
       
   223 			}	
       
   224 		}
       
   225 		# Now build the roms if required
       
   226 		if ($ARGS{r})
       
   227 		{
       
   228 			DoBuildRoms();
       
   229 		}
       
   230 	}
       
   231 
       
   232 	# Build and test host platforms. They get built and then tested in order.
       
   233 	# This is required as the EPOC C drive is shared between udeb and urel.
       
   234 	# If the build/test is run together as a set, then the state of the C
       
   235 	# drive will be restored
       
   236 	foreach my $platform (@HOSTPLATFORMS)
       
   237 	{
       
   238 		foreach my $bt (@BUILDTYPES)
       
   239 		{
       
   240 			if ($ARGS{b})
       
   241 			{
       
   242 				DoBuild($platform, $bt);
       
   243 			}
       
   244 			if ($ARGS{t})
       
   245 			{
       
   246 				DoRunTests($platform, $bt);
       
   247 			}
       
   248 		}
       
   249 	}
       
   250 
       
   251 	# Now build the target platforms (unless this has been done in advance) - no testing required
       
   252 	if ( !$ARGS{f} ) 
       
   253 	{
       
   254 		if ($ARGS{b})
       
   255 		{
       
   256 			foreach my $platform (@TARGETPLATFORMS)
       
   257 			{
       
   258 				foreach my $bt (@BUILDTYPES)
       
   259 				{
       
   260 					# Must build dummy midp2installerclient for cedar
       
   261 					if ( $BUILDPLATFORM eq "cedar" )
       
   262 					{
       
   263 						my @tempbuilddirs = @BUILDDIRS;
       
   264 						@BUILDDIRS = ("$SUBSYSTEMROOT\\appinst\\tsrc");
       
   265 						print "Building dummy midp2installerclient....on $platform/$bt\n";
       
   266 						DoBuild($platform, $bt);
       
   267 						# now build the rest
       
   268 						@BUILDDIRS = @tempbuilddirs;
       
   269 					}
       
   270 					DoBuild($platform, $bt);
       
   271 				}
       
   272 			}	
       
   273 		}
       
   274 		# Now build the roms if required
       
   275 		if ($ARGS{r})
       
   276 		{
       
   277 			DoBuildRoms();
       
   278 		}
       
   279 	}
       
   280 
       
   281 	my $timeoutput = `time /t`;
       
   282 	ReportToFiles("\n------------------- Job finished at $timeoutput\n\n");
       
   283 
       
   284 }
       
   285 sub ConfigureDefaultClient
       
   286 {
       
   287 	# this subroutine figures out what default perforce client to use
       
   288 	my $clientoutput = `p4 client -o`;
       
   289 
       
   290 	if ($clientoutput =~ /\nClient:\s*([^\s]*)/ )
       
   291 	{
       
   292 		return $1;
       
   293 	}
       
   294 }
       
   295 
       
   296 sub GetRootDrive
       
   297 {
       
   298 	# this subroutine derives the rootdrive from the perforce client
       
   299 	my $clientoutput = `p4 client -o`;
       
   300 
       
   301 	if ($clientoutput =~ /\nRoot:\s*(.):/ )
       
   302 	{
       
   303 		$ROOTDRIVE = "$1:"
       
   304 	}
       
   305 }
       
   306 
       
   307 sub ProcessCommandLine
       
   308 {
       
   309 	use Getopt::Long;
       
   310 	&GetOptions (\%ARGS, "a", "h", "s", "u", "b", "t", "r", "o", "f", "client=s", "configfile=s", "workdir=s", "mainline=s", "subsystemroot=s", "nohost", "notgt", "platform=s", @HOSTPLATFORMS, @TARGETPLATFORMS, @ROMPLATFORMS, @BUILDTYPES);
       
   311 
       
   312 	# if the -a option is specified, this means that sync, unzip, build, run
       
   313 	# tests, and rom options should be set
       
   314 	if ($ARGS{a})
       
   315 	{
       
   316 		$ARGS{o} = $ARGS{s} = $ARGS{u} = $ARGS{b} = $ARGS{t} = $ARGS{r} = $ARGS{a};
       
   317 	}
       
   318 
       
   319 	# if the help option is specified, or none of the other arguments are specified,
       
   320 	# or both beech and cedar requested, then display the help
       
   321 	if ($ARGS{h} || (!$ARGS{s} && !$ARGS{u} && !$ARGS{b} && !$ARGS{t} && !$ARGS{r} && !$ARGS{o}))
       
   322 	{
       
   323 		print "Command line switches: \n";
       
   324 		print "    -s        Do perforce synchronisation\n";
       
   325 		print "    -u        Do unzipping from the mainline\n";
       
   326 		print "    -b        Build the appropriate targets\n";
       
   327 		print "    -t        Run the test suite\n";
       
   328 		print "    -r        Build the roms\n";
       
   329         print "    -o        Build the tools\n";
       
   330 		print "    -a        Do all of the above\n";
       
   331 		print "    -f        Build rom First (before wins winscw)\n";
       
   332 		print "    -h        Display this screen\n";
       
   333 		print "\nOther options:\n";
       
   334 		print "    --wins    Use the wins platform for building and running of host tests\n";
       
   335 		print "    --winscw  Use the winscw platform for building and running of host tests\n";
       
   336 		print "    --nohost  Do not use any host platform\n";
       
   337 		print "    --arm4    Use the arm4 processor for rom building\n";
       
   338 		print "    --thumb   Use the thumb processor for rom building\n";
       
   339 		print "    --notgt   Do not use any target platform\n";
       
   340 		print "    --assabet Build roms for assabet platform\n";
       
   341 		print "    --lubbock Build roms for lubbock platform\n";
       
   342 		print "    --udeb    Build udeb version only\n";
       
   343 		print "    --urel    Build urel version only\n";
       
   344 		print "\nParameters:\n";
       
   345 		print "    --client=<client>   Specifies the perforce client to use (default: $P4CLIENTNAME)\n";
       
   346 		print "    --workdir=<dir>     Specifies the working directory (default: $REPORTDIR)\n";
       
   347 		print "    --subsystemroot=<dir> Specifies the root directory to build\n";
       
   348 		print "    --configfile=<file> Specifies the test config file\n";
       
   349 		print "    --mainline=<release number> Specifies the release number to use\n";
       
   350         print "    --platform=<platform name>  Specifies MCL platform. Default is beech. Set to none for pre MCL builds\n";
       
   351 		print "\nExamples:\n";
       
   352 		print "    perl -w RunTests.pl -b -t -r --wins --lubbock --thumb --platform=cedar --client=lon-julianl\n\n";
       
   353 		print "    Uses drive m, client lon-julianl, build against cedar and builds and runs tests on the wins\n";
       
   354 		print "    platform and builds roms for lubbock\n\n";
       
   355 		print "    perl -w RunTests.pl -u -b --winscw --urel --notgt --mainline=01038\n\n";
       
   356 		print "    Unzips mainline 01038_beech and builds only winscw/urel. Uses default client\n";
       
   357 		print "    perl -w RunTests.pl -u -b --winscw --urel --notgt --platform=none --mainline=01038\n\n";
       
   358 		print "    Unzips mainline 01038 and builds only winscw/urel. Uses default client\n";
       
   359 		exit(0);
       
   360 	}
       
   361 
       
   362 	# Now parse the client, drive, and working directory parameters
       
   363 	if ($ARGS{"client"})
       
   364 	{
       
   365 		$P4CLIENTNAME = $ARGS{"client"};
       
   366 		$ENV{"P4CLIENT"} = $P4CLIENTNAME;
       
   367 	}
       
   368 	if ($ARGS{"configfile"})
       
   369 	{
       
   370 		$TESTCONFIGFILE = $ARGS{"configfile"};
       
   371 	}
       
   372 	if ($ARGS{"workdir"})
       
   373 	{
       
   374 		$REPORTDIR = $ARGS{"workdir"};
       
   375 	}
       
   376 	if ($ARGS{"subsystemroot"})
       
   377 	{
       
   378 		$SUBSYSTEMROOT = $ARGS{"subsystemroot"};
       
   379 	}
       
   380 
       
   381 	use Getopt::Long;
       
   382 
       
   383 	# now parse the host options
       
   384 	if ($ARGS{"nohost"})
       
   385 	{
       
   386 		@HOSTPLATFORMS = ();
       
   387 	}
       
   388 	else
       
   389 	{
       
   390 		ParseArguments(\@HOSTPLATFORMS);
       
   391 	}
       
   392 
       
   393 	# now parse the target platforms
       
   394 	if ($ARGS{"notgt"})
       
   395 	{
       
   396 		@TARGETPLATFORMS = ();
       
   397 	}
       
   398 	else
       
   399 	{
       
   400 		ParseArguments(\@TARGETPLATFORMS);
       
   401 	}
       
   402 
       
   403 	# now parse the rom platforms and the build types
       
   404 	ParseArguments(\@ROMPLATFORMS);
       
   405 	ParseArguments(\@BUILDTYPES);
       
   406 
       
   407 	if ($ARGS{"platform"})
       
   408 	{
       
   409 		$BUILDPLATFORM=$ARGS{"platform"};
       
   410 		if ($BUILDPLATFORM eq "none")
       
   411 		{
       
   412 			# set compatibity for pre MCL builds
       
   413 			$BUILDPLATFORM="";
       
   414 		}
       
   415 	}
       
   416 	else
       
   417 	{
       
   418 		# default
       
   419 		$BUILDPLATFORM="beech"; 
       
   420 	}
       
   421 }
       
   422 
       
   423 sub ParseArguments
       
   424 {
       
   425 	# common parsing of arguments in an array - returns another array
       
   426 	# which have the options specified.
       
   427 	# If none specified, it returns ALL the options.
       
   428 	#
       
   429 	# eg. If -wins specified, and options = ("wins", "winscw"), then
       
   430 	# return array is just ("wins"). If neither wins or winscw specified,
       
   431 	# then returns both
       
   432 	(my $options) = @_;
       
   433 	my @retoptions = ();
       
   434 
       
   435 	foreach my $opt (@$options)
       
   436 	{
       
   437 		if ($ARGS{$opt})
       
   438 		{
       
   439 			push(@retoptions, $opt);
       
   440 		}
       
   441 	}
       
   442 
       
   443 	# change if we have at least one option specified
       
   444 	if (scalar(@retoptions) > 0)
       
   445 	{
       
   446 		@$options = @retoptions;
       
   447 	}
       
   448 }
       
   449 
       
   450 # subroutine to do a perforce sync 
       
   451 sub DoPerforceSync
       
   452 {
       
   453 	print "Doing a Perforce synchronisation....\n";
       
   454 	ExecAndOutputToLog("p4 sync -f $SUBSYSTEMROOT\\...");
       
   455     if ( $TECHVIEWROOT )
       
   456     {
       
   457         ExecAndOutputToLog("p4 sync -f $TECHVIEWROOT\\...");
       
   458     }
       
   459 }
       
   460 
       
   461 # subroutine to do the unzipping
       
   462 sub DoMainlineUnzip
       
   463 {
       
   464 	my ($dir) = @_;
       
   465 	print "Doing an unzip of mainline $MAINLINEZIPDIR\\$dir...\n";
       
   466 
       
   467 	my @zipfiles = ("techview");
       
   468 
       
   469 	# firstly, delete anything already there
       
   470 	ExecAndOutputToLog("del \/F \/S \/Q $EPOCROOT");
       
   471 
       
   472 	# unzip all the zipfiles
       
   473 	map { ExecAndOutputToLog("t:\\tools\\unzip -o $MAINLINEZIPDIR\\$dir\\zips\\$_.zip -d $ROOTDRIVE\\"); } @zipfiles;
       
   474 }
       
   475 
       
   476 # subrountine to build or clean release or test build
       
   477 # call RunAbld("<Directory>", "<Command>", "<Target>", "test" or "")
       
   478 sub RunAbld
       
   479 {
       
   480 	my ($dir, $cmd, $target, $test, $bldtype) = @_;
       
   481 	chdir ($dir);
       
   482 
       
   483 	my $bldcommand = "abld $test $cmd -k $target $bldtype";
       
   484 	my $bldoutput = ExecAndOutputToLog($bldcommand);	
       
   485 	
       
   486 	if ($cmd eq "build")
       
   487 	{
       
   488 		# match "error:" or "error(s)" or fatal error
       
   489 		my @errout = grep(/(error(\(s\)|\:))|fatal error/i,  split("\n", $bldoutput));
       
   490 
       
   491 		if (scalar(@errout) > 0)
       
   492 		{
       
   493 			print ERRFILE "-------- Errors found when running $bldcommand\n";
       
   494 			map { print ERRFILE "$_\n"; } @errout;
       
   495 			print ERRFILE "-------- End of errors for $bldcommand\n\n";
       
   496 		}
       
   497 	}
       
   498 }
       
   499 
       
   500 # builds the release and test code for a specified platform and mode
       
   501 # eg WINS/UDEB
       
   502 sub DoBuild
       
   503 {
       
   504 	my ($platform, $bt) = @_;
       
   505 
       
   506 	RemoveWatchers($platform, $bt);
       
   507 
       
   508 	foreach my $bd (@BUILDDIRS)
       
   509 	{
       
   510 
       
   511 		chdir ($bd);
       
   512 		system("bldmake bldfiles");
       
   513 
       
   514 		print "Building build targets.... $bd on $platform/$bt\n";
       
   515 		ReportToFiles("\n------------------- Now building $bd on $platform/$bt\n\n");
       
   516 
       
   517 		RunAbld($bd, "clean", $platform, "", $bt);
       
   518 		RunAbld($bd, "clean", $platform, "test", $bt);
       
   519 		RunAbld($bd, "build", $platform, "", $bt);
       
   520 		RunAbld($bd, "build", $platform, "test", $bt);
       
   521 	}
       
   522 }
       
   523 
       
   524 # builds the tools for deb or rel
       
   525 sub DoBuildTools
       
   526 {
       
   527 	my ($bt) = @_;
       
   528 
       
   529     #adjust for unicode
       
   530     if ($bt eq "udeb")
       
   531     {
       
   532         $bt = "deb";
       
   533     }
       
   534     if ($bt eq "urel")
       
   535     {
       
   536         $bt = "rel";
       
   537     }
       
   538 
       
   539 	foreach my $bd (@BUILDDIRS)
       
   540 	{
       
   541 		chdir ($bd);
       
   542 		system("bldmake bldfiles");
       
   543 
       
   544 		print "Building tools.... $bd on $bt\n";
       
   545 		ReportToFiles("\n------------------- Now building $bd for tools on $bt\n\n");
       
   546 
       
   547 		RunAbld($bd, "clean", "tools", "", $bt);
       
   548 		RunAbld($bd, "build", "tools", "", $bt);
       
   549 	}
       
   550 }
       
   551 
       
   552 # this subroutine executes the given command and outputs to the log file
       
   553 sub ExecAndOutputToLog
       
   554 {
       
   555 	my ($cmd) = @_;
       
   556 	my $timeoutput = `time /t`;
       
   557 	my $cmdoutput = `$cmd 2>&1`;
       
   558 
       
   559 	# capture output to log file
       
   560 	print LOGFILE "-------- Output of $cmd run at $timeoutput";
       
   561 	if ($cmdoutput) 
       
   562 	{
       
   563 		print LOGFILE "$cmdoutput\n";
       
   564 	}
       
   565 	else
       
   566 	{
       
   567 		print LOGFILE "(NO OUTPUT)\n";
       
   568 	}
       
   569 
       
   570 	if ($? != 0)
       
   571 	{
       
   572 		print ERRFILE "\n-------- Error code $? returned when executing:\n";
       
   573 		print ERRFILE "-------- \"$cmd\".\n";
       
   574 
       
   575 		if ($cmdoutput)
       
   576 		{
       
   577 			print ERRFILE "-------- Output:\n";
       
   578 			print ERRFILE "$cmdoutput";
       
   579 		}
       
   580 	}
       
   581 	return $cmdoutput;
       
   582 }
       
   583 
       
   584 # this subroutine executes all the tests as specified in the configuration file.
       
   585 # It will run the tests for the specified platform/built type
       
   586 #
       
   587 # The configuration file has the following valid commands:
       
   588 # 
       
   589 # #include <filename> - includes another config file
       
   590 # SYSTEMCMD <command and parameters> - executes a DOS command eg SYSTEMCMD copy a.txt b.txt
       
   591 # DOTEST <testname> <scriptname> <logname> ... - executes a test
       
   592 # COMP <filea> <fileb> - compares two files and logs result
       
   593 #
       
   594 # For SYSTEMCMD and COMP, the following variables get substituted
       
   595 # - $C - the current EPOC C drive (eg o:\epoc32\wins\c)
       
   596 # - $Z - the current EPOC Z drive (eg o:\epoc32\release\wins\udeb\z)
       
   597 # - $RELEASE - the epoc release directory for this build (eg o:\epoc32\release\wins\udeb)
       
   598 # - $EPOC - the epoc root (eg o:\epoc32)
       
   599 # - $ROOT - the root drive (eg o:)
       
   600 sub DoRunTests
       
   601 {
       
   602 	# platform and build type
       
   603 	my ($p, $bt) = @_; 
       
   604 	print "Running tests on platform $p/$bt\n";
       
   605 	ReportToFiles("\n------------------- Now running tests on platform $p/$bt\n\n");
       
   606 
       
   607 	# set the default directory to be the subsystem root
       
   608 	chdir($SUBSYSTEMROOT);
       
   609 
       
   610 	# Make the results directory
       
   611 	my $testlogs = "$RESULTDIR\\testlogs";
       
   612 	system("mkdir $testlogs");
       
   613 	system("mkdir $testlogs\\$p");
       
   614 	system("mkdir $testlogs\\$p\\$bt");
       
   615 
       
   616 	# open the post processed file
       
   617 	open (POSTFILE, "< $POSTPROCESSED") || die "error opening $POSTPROCESSED for reading";
       
   618 	# open a separate report file for test results
       
   619 	open (TESTREPFILE, "> $RESULTDIR\\testresults.$p.$bt.txt") || die "error opening for writing";
       
   620 
       
   621 	my $timeoutput = `time /t`;
       
   622 	print TESTREPFILE "-------- Test log file when running on platform $p/$bt at $timeoutput";
       
   623 
       
   624 	my $cdrive = "$EPOCROOT\\$p\\c";
       
   625 	while (<POSTFILE>)
       
   626 	{
       
   627 		my $line = $_;
       
   628 
       
   629 		# check for a line with SYSTEMCMD <command>
       
   630 		if ( $line =~ /^SYSTEMCMD[ ]+(.*)/ )
       
   631 		{
       
   632 			# Substitute $C for the cdrive, $Z for the zdrive, and $RELEASE
       
   633 			# for the release path, etc
       
   634 			my $cmd = $1;
       
   635 			SubstitutePaths($p, $bt, \$cmd);
       
   636 
       
   637 			print "  - executing system command: $cmd\n";
       
   638 			ExecAndOutputToLog($cmd);
       
   639 		}
       
   640 		elsif ( $line =~ /^\s*$/ )
       
   641 		{
       
   642 			# if we have an empty line then do nothing
       
   643 		}
       
   644 		elsif ( $line =~ /^DOTEST\s+([^\s]+)[\s]+([^\s]+)[\s]+([^\s]+)/ )
       
   645 		{
       
   646 			# if this pattern matches DOTEST <cmd> <scriptfile> <logfile>,
       
   647 			# then we execute this test - extra parameters can be supplied after the logfile
       
   648 			print "  - running test: $1 $2 $3\n";
       
   649 			ExecAndOutputToLog("$EPOCROOT\\release\\$p\\$bt\\$1 $2 $3 $'");
       
   650 
       
   651 			# log files are assumed to be stored in \epoc32\wins\c
       
   652 			my $outfile = "$cdrive\\$3";
       
   653 
       
   654 			print TESTREPFILE "\n---- Result of test \"$1 $2 $3\"\n";
       
   655 			if (-e $outfile)
       
   656 			{
       
   657 				# also, copy the log file into the results dir
       
   658 				copy ($outfile, "$testlogs\\$p\\$bt\\$3");
       
   659 				
       
   660 				# check to see if there is a failure
       
   661 				my $output = `type $outfile`;
       
   662 				if ($output =~ /(\d+) tests failed out of (\d+)/)
       
   663 				{
       
   664 					print TESTREPFILE "     $1 tests failed out of $2\n";
       
   665 					if ($1 ne "0") 
       
   666 					{
       
   667 						# if there is a fail, then print it in the test log
       
   668 						print ERRFILE "-------- Logfile $outfile produced a failure result!\n";
       
   669 						print ERRFILE "$output\n";
       
   670 						print TESTREPFILE "     There was a test FAILURE\n";
       
   671 					}
       
   672 					else
       
   673 					{
       
   674 						print TESTREPFILE "     All tests SUCCEEDED\n";
       
   675 					}
       
   676 				}
       
   677 				else
       
   678 				{
       
   679 					# if it doesn't conform to standard format, then need to notify
       
   680 					print TESTREPFILE "     WARNING: non-standard log file format - check log\n";
       
   681 				}
       
   682 			}
       
   683 			else
       
   684 			{
       
   685 				# if we get here, the output file didn't exist
       
   686 				print ERRFILE "-------- Logfile $outfile does not exist - did $1 fail to build?\n";
       
   687 				print TESTREPFILE "     ERROR! Log file $outfile does not exist\n";
       
   688 			}
       
   689 
       
   690 		}
       
   691 		elsif ( $line =~ /^COMP\s+([^\s]+)[\s]+([^\s]+)/ )
       
   692 		{
       
   693 			# Parse our paths
       
   694 			my $file1 = $1;
       
   695 			my $file2 = $2;
       
   696 
       
   697 			# substitute variables
       
   698 			SubstitutePaths($p, $bt, \$file1);
       
   699 			SubstitutePaths($p, $bt, \$file2);
       
   700 
       
   701 			print "  - doing comparison on $file1 and $file2\n";
       
   702 			print TESTREPFILE "\n---- Comparing $file1 and $file2\n";
       
   703 			my $output = ExecAndOutputToLog("diff -q $file1 $file2");
       
   704 
       
   705 			if ( $output =~ /differ/ )
       
   706 			{
       
   707 				print TESTREPFILE "     Comparison FAILED\n";
       
   708 			}
       
   709 			else
       
   710 			{
       
   711 				print TESTREPFILE "     Comparison SUCCESSFUL\n";
       
   712 			}
       
   713 		}
       
   714 
       
   715 		else
       
   716 		{
       
   717 			ReportToFiles("**** Error test config line: $line");
       
   718 		}
       
   719 	}
       
   720 	close (POSTFILE);
       
   721 	close (TESTREPFILE);
       
   722 }
       
   723 
       
   724 # - $C - the current EPOC C drive (eg o:\epoc32\wins\c)
       
   725 # - $Z - the current EPOC Z drive (eg o:\epoc32\release\wins\udeb\z)
       
   726 # - $RELEASE - the epoc release directory for this build (eg o:\epoc32\release\wins\udeb)
       
   727 # - $EPOC - the epoc root (eg o:\epoc32)
       
   728 # - $ROOT - the root drive (eg o:)
       
   729 # - $SUBSYSROOT - subsystem root e.g. security
       
   730 sub SubstitutePaths
       
   731 {
       
   732 	my ($platform, $buildtype, $cmdref) = @_;
       
   733 
       
   734 	my $cdrive = "$EPOCROOT\\$platform\\c";
       
   735 	my $releasedir = "$EPOCROOT\\release\\$platform\\$buildtype";
       
   736 	my $zdrive = "$releasedir\\z";
       
   737 
       
   738 	${$cmdref} =~ s/\$C/$cdrive/g;
       
   739 	${$cmdref} =~ s/\$Z/$zdrive/g;
       
   740 	${$cmdref} =~ s/\$RELEASE/$releasedir/g;
       
   741 	${$cmdref} =~ s/\$EPOC/$EPOCROOT/g;
       
   742 	${$cmdref} =~ s/\$ROOT/$ROOTDRIVE/g;
       
   743 	${$cmdref} =~ s/\$SUBSYSROOT/$RELSUBSYSROOT/g;
       
   744 }
       
   745 
       
   746 
       
   747 # This subroutine acts as a preprocessor for a config file. It
       
   748 # expands the test config file and produced a file in POSTPROCESSED
       
   749 sub ParseTestConfigFile
       
   750 {
       
   751 	use File::Copy;
       
   752 
       
   753 	# Firstly, copy the configuration file into the postprocessed file
       
   754 	copy($TESTCONFIGFILE, $POSTPROCESSED);
       
   755 
       
   756 	# set up boolean to indicate if preprocessing of #include is done
       
   757 	my $keepgoing = "1";
       
   758 
       
   759 	while ($keepgoing)
       
   760 	{
       
   761 		# reset the keepgoing flag
       
   762 		$keepgoing = "";
       
   763 
       
   764 		# if we have to keep going, copy the postprocessed file into a temp
       
   765 		my $tempfile = "$RESULTDIR\\temp.txt";
       
   766 		move ($POSTPROCESSED, $tempfile);
       
   767 
       
   768 		open  (TEMPFILE, "< $tempfile") || die "error opening $tempfile for reading";
       
   769 		open  (POSTFILE, "> $POSTPROCESSED") || die "error opening $POSTPROCESSED for writing";
       
   770 
       
   771 		# Now search the temp file for instances of #include
       
   772 		while (<TEMPFILE>)
       
   773 		{
       
   774 			my $line = $_;
       
   775 			# check for comments - use C++ style //
       
   776 			if ( $line =~ /(.*)\/\/.*/ )
       
   777 			{
       
   778 				# set the keepgoing flag
       
   779 				$keepgoing = "1";
       
   780 				print POSTFILE "$1\n";
       
   781 			}
       
   782 			elsif ( $line =~ /\#include[ ]+\"([^\"]*)\"/ )
       
   783 			{
       
   784 				# set the keepgoing flag because a #include has been found
       
   785 				$keepgoing = "1";
       
   786 
       
   787 				# now write the entire contents of this file into the
       
   788 				# the postprocessed file
       
   789 				my $contents = `type $SUBSYSTEMROOT\\$1`;
       
   790 				print POSTFILE "$contents\n";
       
   791 			}
       
   792 			elsif ( $line =~ /^\s*$/ )
       
   793 			{
       
   794 				# remove if we have only whitespaces
       
   795 			}
       
   796 			else 
       
   797 			{
       
   798 				print POSTFILE $line;
       
   799 			}
       
   800 		}
       
   801 		close (TEMPFILE);
       
   802 		close (POSTFILE);
       
   803 
       
   804 		# delete the temp file
       
   805 		unlink($tempfile);
       
   806 	}
       
   807 }
       
   808 
       
   809 sub ReportToFiles
       
   810 {
       
   811 	# this function just prints a string to both the log file and the error file
       
   812 	my ($str) = @_;
       
   813 
       
   814 	print LOGFILE $str;
       
   815 	print ERRFILE $str;
       
   816 }
       
   817 
       
   818 sub DoBuildRoms
       
   819 {
       
   820 	ReportToFiles("\n------------------- Now building roms\n\n");
       
   821 
       
   822 	chdir ("$EPOCROOT\\rom");
       
   823 
       
   824 	# create a new directory for the roms
       
   825 	my $romdir = "$RESULTDIR\\roms";
       
   826 	system("mkdir \"$romdir\"");
       
   827 
       
   828 	# define the oby file to use
       
   829 	my $oby_file = "techview.oby";
       
   830 
       
   831 	# firstly, make sure the SecurityTests.iby file has been included from the techview.oby
       
   832 	if (open(OBY, ">> include\\$oby_file"))
       
   833 	{
       
   834 		print OBY "\n#include <SecurityTests.iby>\n";
       
   835 		close(OBY);
       
   836 	}
       
   837 
       
   838 	# Now go through the list of rom targets and build
       
   839 	foreach my $rom (@ROMPLATFORMS)
       
   840 	{
       
   841 		ExecAndOutputToLog("tools\\buildrom -D__NOWATCHER__ -o$romdir\\$rom.img $rom $oby_file");
       
   842 	}
       
   843 }
       
   844 
       
   845 sub SetVariable
       
   846 {
       
   847 	# Sets a variable from an environment variable or a default value if the
       
   848 	# environment variable has not been set
       
   849 	my ($variable, $env_name, $default) = @_;
       
   850 
       
   851 	${$variable} = $ENV{$env_name};
       
   852 	if (!${$variable})
       
   853 	{
       
   854 		${$variable} = $default;
       
   855 	}
       
   856 }
       
   857 
       
   858 # remove the watchers (prevents connection intermittently to NTRas)
       
   859 sub RemoveWatchers
       
   860 {
       
   861 	my ($platform, $bt) = @_;
       
   862 
       
   863 	ReportToFiles("------------------- Removing watchers\n");
       
   864 
       
   865 	if ( ($platform eq "wins") or ($platform eq "winscw") )
       
   866 	{
       
   867 		# emulator build, delete the dlls for beech and exes for cedar
       
   868 		system("del $EPOCROOT\\release\\$platform\\$bt\\watcher.dll");
       
   869 		system("del $EPOCROOT\\release\\$platform\\$bt\\z\\system\\libs\\watcher.dll");
       
   870 		system("del $EPOCROOT\\release\\$platform\\$bt\\watcher.exe");
       
   871 		system("del $EPOCROOT\\release\\$platform\\$bt\\z\\system\\libs\\watcher.exe");
       
   872 	}
       
   873 	else
       
   874 	{
       
   875 		# hardware. remove the watchers from startup script
       
   876 		if ( $TECHVIEWROOT )
       
   877 		{
       
   878 			system("attrib -r $TECHVIEWROOT\\toolkit\\startup\\group\\start.rss");
       
   879 			system("copy $SUBSYSTEMROOT\\testframework\\test\\autotesting\\startnowatchers.rss $TECHVIEWROOT\\toolkit\\startup\\group\\start.rss");
       
   880 		}
       
   881 	}
       
   882 }