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