1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/autotesting/RunSecurityTests.pl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,882 @@
1.4 +#
1.5 +# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +# All rights reserved.
1.7 +# This component and the accompanying materials are made available
1.8 +# under the terms of the License "Eclipse Public License v1.0"
1.9 +# which accompanies this distribution, and is available
1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +#
1.12 +# Initial Contributors:
1.13 +# Nokia Corporation - initial contribution.
1.14 +#
1.15 +# Contributors:
1.16 +#
1.17 +# Description:
1.18 +#
1.19 +
1.20 +use strict;
1.21 +
1.22 +##################################################################################
1.23 +# These variables can be customised as required
1.24 +# define some global variables - customise as required
1.25 +my $REPORTDIR;
1.26 +my $MAINLINEZIPDIR;
1.27 +my $RELSUBSYSROOT;
1.28 +my $TECHVIEWROOT;
1.29 +
1.30 +# set variables which can be set from the environment. If no environment
1.31 +# equivalent is found, it will set to the default
1.32 +SetVariable(\$REPORTDIR, "REPORTDIR", "L:\\AutoSecTests");
1.33 +SetVariable(\$MAINLINEZIPDIR, "MAINLINEZIPDIR", "\\\\builds01\\Master");
1.34 +SetVariable(\$RELSUBSYSROOT, "RELSUBSYSROOT", "security");
1.35 +
1.36 +# To include Techview in build set environment variable:
1.37 +# TECHVIEWROOT=Techview
1.38 +SetVariable(\$TECHVIEWROOT, "TECHVIEWROOT", "");
1.39 +
1.40 +# host platforms define which platforms are to be built and tests to run. Target
1.41 +# platforms are those where roms are build
1.42 +my @HOSTPLATFORMS = ("wins", "winscw");
1.43 +my @TARGETPLATFORMS = ("arm4", "thumb");
1.44 +my @ROMPLATFORMS = ("lubbock", "assabet");
1.45 +my @BUILDTYPES = ("udeb", "urel");
1.46 +#
1.47 +# END of customisable variables
1.48 +####################################################################################
1.49 +
1.50 +my $P4CLIENTNAME = ConfigureDefaultClient();
1.51 +my $TESTCONFIGFILE;
1.52 +my $SUBSYSTEMROOT;
1.53 +# beech or cedar
1.54 +my $BUILDPLATFORM;
1.55 +
1.56 +# first get the date
1.57 +my @DATEARRAY = split(/[ \/]/, `date /t`);
1.58 +
1.59 +# command line arguments
1.60 +my %ARGS = ();
1.61 +
1.62 +# Parse command line parameters
1.63 +ProcessCommandLine();
1.64 +
1.65 +# now, DATEARRAY[0] will be day, 1 will be date of month, 2 will be month, 3 is year
1.66 +my $RESULTDIR = "$REPORTDIR\\$DATEARRAY[3]$DATEARRAY[2]$DATEARRAY[1]";
1.67 +
1.68 +# define the file where the config.txt file is post-processed
1.69 +my $POSTPROCESSED = "$RESULTDIR\\postprocessed.txt";
1.70 +
1.71 +# create a new directory for today
1.72 +system("mkdir \"$RESULTDIR\"");
1.73 +
1.74 +# create a logfile and error file
1.75 +open (LOGFILE, "> $RESULTDIR\\log.txt") || die "error opening for writing";
1.76 +open (ERRFILE, "> $RESULTDIR\\error.txt") || die "error opening for writing";
1.77 +
1.78 +# Derive rootdrive from perforce client. Set up variables
1.79 +# which required the root drive to be configured. Note that
1.80 +# the test config file is only overwritten if not configured by
1.81 +# the command line. By default it looks for config.txt in the current
1.82 +# directory
1.83 +my $ROOTDRIVE = "L:";
1.84 +GetRootDrive();
1.85 +if (!$TESTCONFIGFILE)
1.86 +{
1.87 + use Cwd;
1.88 + my $dir = cwd();
1.89 + $TESTCONFIGFILE = "$dir\\config.txt";
1.90 +}
1.91 +if (!$SUBSYSTEMROOT)
1.92 +{
1.93 + $SUBSYSTEMROOT = "$ROOTDRIVE\\$RELSUBSYSROOT";
1.94 +}
1.95 +
1.96 +if ($TECHVIEWROOT)
1.97 +{
1.98 + $TECHVIEWROOT = "$ROOTDRIVE\\$TECHVIEWROOT";
1.99 +}
1.100 +
1.101 +# epoc root directory
1.102 +my $EPOCROOT = "$ROOTDRIVE\\epoc32";
1.103 +
1.104 +# add techview to build if requested
1.105 +my @BUILDDIRS = "";
1.106 +if ( $TECHVIEWROOT )
1.107 +{
1.108 + @BUILDDIRS = ( $SUBSYSTEMROOT, "$TECHVIEWROOT\\toolkit\\startup\\group", "$TECHVIEWROOT\\apps\\appinstui\\group", "$TECHVIEWROOT\\apps\\secui\\group");
1.109 +}
1.110 +else
1.111 +{
1.112 + @BUILDDIRS = ( $SUBSYSTEMROOT );
1.113 +}
1.114 +
1.115 +print "BUILDIRS = @BUILDDIRS\n";
1.116 +
1.117 +# call main
1.118 +main();
1.119 +
1.120 +# main function
1.121 +sub main()
1.122 +{
1.123 + print "REPORTDIR = $REPORTDIR\n";
1.124 + print "MAINLINEZIPDIR = $MAINLINEZIPDIR\n";
1.125 + print "SUBSYSTEMROOT = $SUBSYSTEMROOT\n";
1.126 + print "TESTCONFIGFILE = $TESTCONFIGFILE\n";
1.127 + print "TECHVIEWROOT = $TECHVIEWROOT\n";
1.128 + print "BUILDPLATFORM = $BUILDPLATFORM\n";
1.129 +
1.130 + # Figure out the second-latest release if none had been specified on the
1.131 + # command line - we do not want the latest in case it has not yet been released.
1.132 + my $releasedir = "";
1.133 + my $platformsuffix = "";
1.134 + if ($BUILDPLATFORM)
1.135 + {
1.136 + $platformsuffix = "_$BUILDPLATFORM";
1.137 + }
1.138 +
1.139 + if (!$ARGS{"mainline"})
1.140 + {
1.141 + my $filelist = `dir $MAINLINEZIPDIR\\0????$platformsuffix /ad /b | sort /r`;
1.142 + my @filearray = split "\n", $filelist;
1.143 + $releasedir = $filearray[1];
1.144 + }
1.145 + else
1.146 + {
1.147 + $releasedir = "$ARGS{\"mainline\"}$platformsuffix";
1.148 + }
1.149 +
1.150 + # Display what's to be done
1.151 + ReportToFiles("------ Script run on $DATEARRAY[1]/$DATEARRAY[2]/$DATEARRAY[3] with the following options\n");
1.152 + ReportToFiles("------ Report directory: $REPORTDIR\n");
1.153 + ReportToFiles("------ Subsystem root: $SUBSYSTEMROOT\n");
1.154 + ReportToFiles("------ Test config file: $TESTCONFIGFILE\n");
1.155 + ReportToFiles("------ Built against MCL platform: $BUILDPLATFORM\n");
1.156 + if ($ARGS{s}) { ReportToFiles("------ Perforce synchronisation using client spec \"$P4CLIENTNAME\" on drive \"$ROOTDRIVE\"\n"); }
1.157 + if ($ARGS{u}) { ReportToFiles("------ Mainline unzip using build $releasedir\n"); }
1.158 + if ($ARGS{b}) { ReportToFiles("------ Build of production and test code\n"); }
1.159 + if ($ARGS{t}) { ReportToFiles("------ Running of test code on the host using $TESTCONFIGFILE\n"); }
1.160 + if ($ARGS{f}) { ReportToFiles("------ Build rom first\n"); }
1.161 + if ($ARGS{t}) { ReportToFiles("------ Running of test code on the host using $TESTCONFIGFILE\n"); }
1.162 +
1.163 + if ($ARGS{r})
1.164 + {
1.165 + ReportToFiles("------ Building of target roms: ");
1.166 + map { ReportToFiles("$_ "); } @ROMPLATFORMS;
1.167 + ReportToFiles("\n");
1.168 + }
1.169 + ReportToFiles("------ Host builds used: ");
1.170 + map { ReportToFiles("$_ "); } @HOSTPLATFORMS;
1.171 + ReportToFiles("\n------ Target processor builds used: ");
1.172 + map { ReportToFiles("$_ "); } @TARGETPLATFORMS;
1.173 + ReportToFiles("\n------ Build types used: ");
1.174 + map { ReportToFiles("$_ "); } @BUILDTYPES;
1.175 + ReportToFiles("\n\n");
1.176 +
1.177 + # Do a perforce sync
1.178 + if ($ARGS{s})
1.179 + {
1.180 + DoPerforceSync();
1.181 + }
1.182 +
1.183 + # Now unzip the mainline
1.184 + if ($ARGS{u})
1.185 + {
1.186 + DoMainlineUnzip($releasedir);
1.187 + }
1.188 +
1.189 + # Build the post-processed config file if the test flag is on
1.190 + if ($ARGS{t})
1.191 + {
1.192 + ParseTestConfigFile();
1.193 + }
1.194 +
1.195 + # Build the tools
1.196 + if ($ARGS{o})
1.197 + {
1.198 + foreach my $bt (@BUILDTYPES)
1.199 + {
1.200 + DoBuildTools($bt);
1.201 + }
1.202 + }
1.203 +
1.204 + # Build rom first?
1.205 + if ( $ARGS{f} )
1.206 + {
1.207 + # Now build the target platforms - no testing required
1.208 + if ($ARGS{b})
1.209 + {
1.210 + foreach my $platform (@TARGETPLATFORMS)
1.211 + {
1.212 + foreach my $bt (@BUILDTYPES)
1.213 + {
1.214 + # Must build dummy midp2installerclient for cedar
1.215 + if ( $BUILDPLATFORM eq "cedar" )
1.216 + {
1.217 + my @tempbuilddirs = @BUILDDIRS;
1.218 + @BUILDDIRS = ("$SUBSYSTEMROOT\\appinst\\tsrc");
1.219 + print "Building dummy midp2installerclient....on $platform/$bt\n";
1.220 + DoBuild($platform, $bt);
1.221 + # now build the rest
1.222 + @BUILDDIRS = @tempbuilddirs;
1.223 + }
1.224 + DoBuild($platform, $bt);
1.225 + }
1.226 + }
1.227 + }
1.228 + # Now build the roms if required
1.229 + if ($ARGS{r})
1.230 + {
1.231 + DoBuildRoms();
1.232 + }
1.233 + }
1.234 +
1.235 + # Build and test host platforms. They get built and then tested in order.
1.236 + # This is required as the EPOC C drive is shared between udeb and urel.
1.237 + # If the build/test is run together as a set, then the state of the C
1.238 + # drive will be restored
1.239 + foreach my $platform (@HOSTPLATFORMS)
1.240 + {
1.241 + foreach my $bt (@BUILDTYPES)
1.242 + {
1.243 + if ($ARGS{b})
1.244 + {
1.245 + DoBuild($platform, $bt);
1.246 + }
1.247 + if ($ARGS{t})
1.248 + {
1.249 + DoRunTests($platform, $bt);
1.250 + }
1.251 + }
1.252 + }
1.253 +
1.254 + # Now build the target platforms (unless this has been done in advance) - no testing required
1.255 + if ( !$ARGS{f} )
1.256 + {
1.257 + if ($ARGS{b})
1.258 + {
1.259 + foreach my $platform (@TARGETPLATFORMS)
1.260 + {
1.261 + foreach my $bt (@BUILDTYPES)
1.262 + {
1.263 + # Must build dummy midp2installerclient for cedar
1.264 + if ( $BUILDPLATFORM eq "cedar" )
1.265 + {
1.266 + my @tempbuilddirs = @BUILDDIRS;
1.267 + @BUILDDIRS = ("$SUBSYSTEMROOT\\appinst\\tsrc");
1.268 + print "Building dummy midp2installerclient....on $platform/$bt\n";
1.269 + DoBuild($platform, $bt);
1.270 + # now build the rest
1.271 + @BUILDDIRS = @tempbuilddirs;
1.272 + }
1.273 + DoBuild($platform, $bt);
1.274 + }
1.275 + }
1.276 + }
1.277 + # Now build the roms if required
1.278 + if ($ARGS{r})
1.279 + {
1.280 + DoBuildRoms();
1.281 + }
1.282 + }
1.283 +
1.284 + my $timeoutput = `time /t`;
1.285 + ReportToFiles("\n------------------- Job finished at $timeoutput\n\n");
1.286 +
1.287 +}
1.288 +sub ConfigureDefaultClient
1.289 +{
1.290 + # this subroutine figures out what default perforce client to use
1.291 + my $clientoutput = `p4 client -o`;
1.292 +
1.293 + if ($clientoutput =~ /\nClient:\s*([^\s]*)/ )
1.294 + {
1.295 + return $1;
1.296 + }
1.297 +}
1.298 +
1.299 +sub GetRootDrive
1.300 +{
1.301 + # this subroutine derives the rootdrive from the perforce client
1.302 + my $clientoutput = `p4 client -o`;
1.303 +
1.304 + if ($clientoutput =~ /\nRoot:\s*(.):/ )
1.305 + {
1.306 + $ROOTDRIVE = "$1:"
1.307 + }
1.308 +}
1.309 +
1.310 +sub ProcessCommandLine
1.311 +{
1.312 + use Getopt::Long;
1.313 + &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);
1.314 +
1.315 + # if the -a option is specified, this means that sync, unzip, build, run
1.316 + # tests, and rom options should be set
1.317 + if ($ARGS{a})
1.318 + {
1.319 + $ARGS{o} = $ARGS{s} = $ARGS{u} = $ARGS{b} = $ARGS{t} = $ARGS{r} = $ARGS{a};
1.320 + }
1.321 +
1.322 + # if the help option is specified, or none of the other arguments are specified,
1.323 + # or both beech and cedar requested, then display the help
1.324 + if ($ARGS{h} || (!$ARGS{s} && !$ARGS{u} && !$ARGS{b} && !$ARGS{t} && !$ARGS{r} && !$ARGS{o}))
1.325 + {
1.326 + print "Command line switches: \n";
1.327 + print " -s Do perforce synchronisation\n";
1.328 + print " -u Do unzipping from the mainline\n";
1.329 + print " -b Build the appropriate targets\n";
1.330 + print " -t Run the test suite\n";
1.331 + print " -r Build the roms\n";
1.332 + print " -o Build the tools\n";
1.333 + print " -a Do all of the above\n";
1.334 + print " -f Build rom First (before wins winscw)\n";
1.335 + print " -h Display this screen\n";
1.336 + print "\nOther options:\n";
1.337 + print " --wins Use the wins platform for building and running of host tests\n";
1.338 + print " --winscw Use the winscw platform for building and running of host tests\n";
1.339 + print " --nohost Do not use any host platform\n";
1.340 + print " --arm4 Use the arm4 processor for rom building\n";
1.341 + print " --thumb Use the thumb processor for rom building\n";
1.342 + print " --notgt Do not use any target platform\n";
1.343 + print " --assabet Build roms for assabet platform\n";
1.344 + print " --lubbock Build roms for lubbock platform\n";
1.345 + print " --udeb Build udeb version only\n";
1.346 + print " --urel Build urel version only\n";
1.347 + print "\nParameters:\n";
1.348 + print " --client=<client> Specifies the perforce client to use (default: $P4CLIENTNAME)\n";
1.349 + print " --workdir=<dir> Specifies the working directory (default: $REPORTDIR)\n";
1.350 + print " --subsystemroot=<dir> Specifies the root directory to build\n";
1.351 + print " --configfile=<file> Specifies the test config file\n";
1.352 + print " --mainline=<release number> Specifies the release number to use\n";
1.353 + print " --platform=<platform name> Specifies MCL platform. Default is beech. Set to none for pre MCL builds\n";
1.354 + print "\nExamples:\n";
1.355 + print " perl -w RunTests.pl -b -t -r --wins --lubbock --thumb --platform=cedar --client=lon-julianl\n\n";
1.356 + print " Uses drive m, client lon-julianl, build against cedar and builds and runs tests on the wins\n";
1.357 + print " platform and builds roms for lubbock\n\n";
1.358 + print " perl -w RunTests.pl -u -b --winscw --urel --notgt --mainline=01038\n\n";
1.359 + print " Unzips mainline 01038_beech and builds only winscw/urel. Uses default client\n";
1.360 + print " perl -w RunTests.pl -u -b --winscw --urel --notgt --platform=none --mainline=01038\n\n";
1.361 + print " Unzips mainline 01038 and builds only winscw/urel. Uses default client\n";
1.362 + exit(0);
1.363 + }
1.364 +
1.365 + # Now parse the client, drive, and working directory parameters
1.366 + if ($ARGS{"client"})
1.367 + {
1.368 + $P4CLIENTNAME = $ARGS{"client"};
1.369 + $ENV{"P4CLIENT"} = $P4CLIENTNAME;
1.370 + }
1.371 + if ($ARGS{"configfile"})
1.372 + {
1.373 + $TESTCONFIGFILE = $ARGS{"configfile"};
1.374 + }
1.375 + if ($ARGS{"workdir"})
1.376 + {
1.377 + $REPORTDIR = $ARGS{"workdir"};
1.378 + }
1.379 + if ($ARGS{"subsystemroot"})
1.380 + {
1.381 + $SUBSYSTEMROOT = $ARGS{"subsystemroot"};
1.382 + }
1.383 +
1.384 + use Getopt::Long;
1.385 +
1.386 + # now parse the host options
1.387 + if ($ARGS{"nohost"})
1.388 + {
1.389 + @HOSTPLATFORMS = ();
1.390 + }
1.391 + else
1.392 + {
1.393 + ParseArguments(\@HOSTPLATFORMS);
1.394 + }
1.395 +
1.396 + # now parse the target platforms
1.397 + if ($ARGS{"notgt"})
1.398 + {
1.399 + @TARGETPLATFORMS = ();
1.400 + }
1.401 + else
1.402 + {
1.403 + ParseArguments(\@TARGETPLATFORMS);
1.404 + }
1.405 +
1.406 + # now parse the rom platforms and the build types
1.407 + ParseArguments(\@ROMPLATFORMS);
1.408 + ParseArguments(\@BUILDTYPES);
1.409 +
1.410 + if ($ARGS{"platform"})
1.411 + {
1.412 + $BUILDPLATFORM=$ARGS{"platform"};
1.413 + if ($BUILDPLATFORM eq "none")
1.414 + {
1.415 + # set compatibity for pre MCL builds
1.416 + $BUILDPLATFORM="";
1.417 + }
1.418 + }
1.419 + else
1.420 + {
1.421 + # default
1.422 + $BUILDPLATFORM="beech";
1.423 + }
1.424 +}
1.425 +
1.426 +sub ParseArguments
1.427 +{
1.428 + # common parsing of arguments in an array - returns another array
1.429 + # which have the options specified.
1.430 + # If none specified, it returns ALL the options.
1.431 + #
1.432 + # eg. If -wins specified, and options = ("wins", "winscw"), then
1.433 + # return array is just ("wins"). If neither wins or winscw specified,
1.434 + # then returns both
1.435 + (my $options) = @_;
1.436 + my @retoptions = ();
1.437 +
1.438 + foreach my $opt (@$options)
1.439 + {
1.440 + if ($ARGS{$opt})
1.441 + {
1.442 + push(@retoptions, $opt);
1.443 + }
1.444 + }
1.445 +
1.446 + # change if we have at least one option specified
1.447 + if (scalar(@retoptions) > 0)
1.448 + {
1.449 + @$options = @retoptions;
1.450 + }
1.451 +}
1.452 +
1.453 +# subroutine to do a perforce sync
1.454 +sub DoPerforceSync
1.455 +{
1.456 + print "Doing a Perforce synchronisation....\n";
1.457 + ExecAndOutputToLog("p4 sync -f $SUBSYSTEMROOT\\...");
1.458 + if ( $TECHVIEWROOT )
1.459 + {
1.460 + ExecAndOutputToLog("p4 sync -f $TECHVIEWROOT\\...");
1.461 + }
1.462 +}
1.463 +
1.464 +# subroutine to do the unzipping
1.465 +sub DoMainlineUnzip
1.466 +{
1.467 + my ($dir) = @_;
1.468 + print "Doing an unzip of mainline $MAINLINEZIPDIR\\$dir...\n";
1.469 +
1.470 + my @zipfiles = ("techview");
1.471 +
1.472 + # firstly, delete anything already there
1.473 + ExecAndOutputToLog("del \/F \/S \/Q $EPOCROOT");
1.474 +
1.475 + # unzip all the zipfiles
1.476 + map { ExecAndOutputToLog("t:\\tools\\unzip -o $MAINLINEZIPDIR\\$dir\\zips\\$_.zip -d $ROOTDRIVE\\"); } @zipfiles;
1.477 +}
1.478 +
1.479 +# subrountine to build or clean release or test build
1.480 +# call RunAbld("<Directory>", "<Command>", "<Target>", "test" or "")
1.481 +sub RunAbld
1.482 +{
1.483 + my ($dir, $cmd, $target, $test, $bldtype) = @_;
1.484 + chdir ($dir);
1.485 +
1.486 + my $bldcommand = "abld $test $cmd -k $target $bldtype";
1.487 + my $bldoutput = ExecAndOutputToLog($bldcommand);
1.488 +
1.489 + if ($cmd eq "build")
1.490 + {
1.491 + # match "error:" or "error(s)" or fatal error
1.492 + my @errout = grep(/(error(\(s\)|\:))|fatal error/i, split("\n", $bldoutput));
1.493 +
1.494 + if (scalar(@errout) > 0)
1.495 + {
1.496 + print ERRFILE "-------- Errors found when running $bldcommand\n";
1.497 + map { print ERRFILE "$_\n"; } @errout;
1.498 + print ERRFILE "-------- End of errors for $bldcommand\n\n";
1.499 + }
1.500 + }
1.501 +}
1.502 +
1.503 +# builds the release and test code for a specified platform and mode
1.504 +# eg WINS/UDEB
1.505 +sub DoBuild
1.506 +{
1.507 + my ($platform, $bt) = @_;
1.508 +
1.509 + RemoveWatchers($platform, $bt);
1.510 +
1.511 + foreach my $bd (@BUILDDIRS)
1.512 + {
1.513 +
1.514 + chdir ($bd);
1.515 + system("bldmake bldfiles");
1.516 +
1.517 + print "Building build targets.... $bd on $platform/$bt\n";
1.518 + ReportToFiles("\n------------------- Now building $bd on $platform/$bt\n\n");
1.519 +
1.520 + RunAbld($bd, "clean", $platform, "", $bt);
1.521 + RunAbld($bd, "clean", $platform, "test", $bt);
1.522 + RunAbld($bd, "build", $platform, "", $bt);
1.523 + RunAbld($bd, "build", $platform, "test", $bt);
1.524 + }
1.525 +}
1.526 +
1.527 +# builds the tools for deb or rel
1.528 +sub DoBuildTools
1.529 +{
1.530 + my ($bt) = @_;
1.531 +
1.532 + #adjust for unicode
1.533 + if ($bt eq "udeb")
1.534 + {
1.535 + $bt = "deb";
1.536 + }
1.537 + if ($bt eq "urel")
1.538 + {
1.539 + $bt = "rel";
1.540 + }
1.541 +
1.542 + foreach my $bd (@BUILDDIRS)
1.543 + {
1.544 + chdir ($bd);
1.545 + system("bldmake bldfiles");
1.546 +
1.547 + print "Building tools.... $bd on $bt\n";
1.548 + ReportToFiles("\n------------------- Now building $bd for tools on $bt\n\n");
1.549 +
1.550 + RunAbld($bd, "clean", "tools", "", $bt);
1.551 + RunAbld($bd, "build", "tools", "", $bt);
1.552 + }
1.553 +}
1.554 +
1.555 +# this subroutine executes the given command and outputs to the log file
1.556 +sub ExecAndOutputToLog
1.557 +{
1.558 + my ($cmd) = @_;
1.559 + my $timeoutput = `time /t`;
1.560 + my $cmdoutput = `$cmd 2>&1`;
1.561 +
1.562 + # capture output to log file
1.563 + print LOGFILE "-------- Output of $cmd run at $timeoutput";
1.564 + if ($cmdoutput)
1.565 + {
1.566 + print LOGFILE "$cmdoutput\n";
1.567 + }
1.568 + else
1.569 + {
1.570 + print LOGFILE "(NO OUTPUT)\n";
1.571 + }
1.572 +
1.573 + if ($? != 0)
1.574 + {
1.575 + print ERRFILE "\n-------- Error code $? returned when executing:\n";
1.576 + print ERRFILE "-------- \"$cmd\".\n";
1.577 +
1.578 + if ($cmdoutput)
1.579 + {
1.580 + print ERRFILE "-------- Output:\n";
1.581 + print ERRFILE "$cmdoutput";
1.582 + }
1.583 + }
1.584 + return $cmdoutput;
1.585 +}
1.586 +
1.587 +# this subroutine executes all the tests as specified in the configuration file.
1.588 +# It will run the tests for the specified platform/built type
1.589 +#
1.590 +# The configuration file has the following valid commands:
1.591 +#
1.592 +# #include <filename> - includes another config file
1.593 +# SYSTEMCMD <command and parameters> - executes a DOS command eg SYSTEMCMD copy a.txt b.txt
1.594 +# DOTEST <testname> <scriptname> <logname> ... - executes a test
1.595 +# COMP <filea> <fileb> - compares two files and logs result
1.596 +#
1.597 +# For SYSTEMCMD and COMP, the following variables get substituted
1.598 +# - $C - the current EPOC C drive (eg o:\epoc32\wins\c)
1.599 +# - $Z - the current EPOC Z drive (eg o:\epoc32\release\wins\udeb\z)
1.600 +# - $RELEASE - the epoc release directory for this build (eg o:\epoc32\release\wins\udeb)
1.601 +# - $EPOC - the epoc root (eg o:\epoc32)
1.602 +# - $ROOT - the root drive (eg o:)
1.603 +sub DoRunTests
1.604 +{
1.605 + # platform and build type
1.606 + my ($p, $bt) = @_;
1.607 + print "Running tests on platform $p/$bt\n";
1.608 + ReportToFiles("\n------------------- Now running tests on platform $p/$bt\n\n");
1.609 +
1.610 + # set the default directory to be the subsystem root
1.611 + chdir($SUBSYSTEMROOT);
1.612 +
1.613 + # Make the results directory
1.614 + my $testlogs = "$RESULTDIR\\testlogs";
1.615 + system("mkdir $testlogs");
1.616 + system("mkdir $testlogs\\$p");
1.617 + system("mkdir $testlogs\\$p\\$bt");
1.618 +
1.619 + # open the post processed file
1.620 + open (POSTFILE, "< $POSTPROCESSED") || die "error opening $POSTPROCESSED for reading";
1.621 + # open a separate report file for test results
1.622 + open (TESTREPFILE, "> $RESULTDIR\\testresults.$p.$bt.txt") || die "error opening for writing";
1.623 +
1.624 + my $timeoutput = `time /t`;
1.625 + print TESTREPFILE "-------- Test log file when running on platform $p/$bt at $timeoutput";
1.626 +
1.627 + my $cdrive = "$EPOCROOT\\$p\\c";
1.628 + while (<POSTFILE>)
1.629 + {
1.630 + my $line = $_;
1.631 +
1.632 + # check for a line with SYSTEMCMD <command>
1.633 + if ( $line =~ /^SYSTEMCMD[ ]+(.*)/ )
1.634 + {
1.635 + # Substitute $C for the cdrive, $Z for the zdrive, and $RELEASE
1.636 + # for the release path, etc
1.637 + my $cmd = $1;
1.638 + SubstitutePaths($p, $bt, \$cmd);
1.639 +
1.640 + print " - executing system command: $cmd\n";
1.641 + ExecAndOutputToLog($cmd);
1.642 + }
1.643 + elsif ( $line =~ /^\s*$/ )
1.644 + {
1.645 + # if we have an empty line then do nothing
1.646 + }
1.647 + elsif ( $line =~ /^DOTEST\s+([^\s]+)[\s]+([^\s]+)[\s]+([^\s]+)/ )
1.648 + {
1.649 + # if this pattern matches DOTEST <cmd> <scriptfile> <logfile>,
1.650 + # then we execute this test - extra parameters can be supplied after the logfile
1.651 + print " - running test: $1 $2 $3\n";
1.652 + ExecAndOutputToLog("$EPOCROOT\\release\\$p\\$bt\\$1 $2 $3 $'");
1.653 +
1.654 + # log files are assumed to be stored in \epoc32\wins\c
1.655 + my $outfile = "$cdrive\\$3";
1.656 +
1.657 + print TESTREPFILE "\n---- Result of test \"$1 $2 $3\"\n";
1.658 + if (-e $outfile)
1.659 + {
1.660 + # also, copy the log file into the results dir
1.661 + copy ($outfile, "$testlogs\\$p\\$bt\\$3");
1.662 +
1.663 + # check to see if there is a failure
1.664 + my $output = `type $outfile`;
1.665 + if ($output =~ /(\d+) tests failed out of (\d+)/)
1.666 + {
1.667 + print TESTREPFILE " $1 tests failed out of $2\n";
1.668 + if ($1 ne "0")
1.669 + {
1.670 + # if there is a fail, then print it in the test log
1.671 + print ERRFILE "-------- Logfile $outfile produced a failure result!\n";
1.672 + print ERRFILE "$output\n";
1.673 + print TESTREPFILE " There was a test FAILURE\n";
1.674 + }
1.675 + else
1.676 + {
1.677 + print TESTREPFILE " All tests SUCCEEDED\n";
1.678 + }
1.679 + }
1.680 + else
1.681 + {
1.682 + # if it doesn't conform to standard format, then need to notify
1.683 + print TESTREPFILE " WARNING: non-standard log file format - check log\n";
1.684 + }
1.685 + }
1.686 + else
1.687 + {
1.688 + # if we get here, the output file didn't exist
1.689 + print ERRFILE "-------- Logfile $outfile does not exist - did $1 fail to build?\n";
1.690 + print TESTREPFILE " ERROR! Log file $outfile does not exist\n";
1.691 + }
1.692 +
1.693 + }
1.694 + elsif ( $line =~ /^COMP\s+([^\s]+)[\s]+([^\s]+)/ )
1.695 + {
1.696 + # Parse our paths
1.697 + my $file1 = $1;
1.698 + my $file2 = $2;
1.699 +
1.700 + # substitute variables
1.701 + SubstitutePaths($p, $bt, \$file1);
1.702 + SubstitutePaths($p, $bt, \$file2);
1.703 +
1.704 + print " - doing comparison on $file1 and $file2\n";
1.705 + print TESTREPFILE "\n---- Comparing $file1 and $file2\n";
1.706 + my $output = ExecAndOutputToLog("diff -q $file1 $file2");
1.707 +
1.708 + if ( $output =~ /differ/ )
1.709 + {
1.710 + print TESTREPFILE " Comparison FAILED\n";
1.711 + }
1.712 + else
1.713 + {
1.714 + print TESTREPFILE " Comparison SUCCESSFUL\n";
1.715 + }
1.716 + }
1.717 +
1.718 + else
1.719 + {
1.720 + ReportToFiles("**** Error test config line: $line");
1.721 + }
1.722 + }
1.723 + close (POSTFILE);
1.724 + close (TESTREPFILE);
1.725 +}
1.726 +
1.727 +# - $C - the current EPOC C drive (eg o:\epoc32\wins\c)
1.728 +# - $Z - the current EPOC Z drive (eg o:\epoc32\release\wins\udeb\z)
1.729 +# - $RELEASE - the epoc release directory for this build (eg o:\epoc32\release\wins\udeb)
1.730 +# - $EPOC - the epoc root (eg o:\epoc32)
1.731 +# - $ROOT - the root drive (eg o:)
1.732 +# - $SUBSYSROOT - subsystem root e.g. security
1.733 +sub SubstitutePaths
1.734 +{
1.735 + my ($platform, $buildtype, $cmdref) = @_;
1.736 +
1.737 + my $cdrive = "$EPOCROOT\\$platform\\c";
1.738 + my $releasedir = "$EPOCROOT\\release\\$platform\\$buildtype";
1.739 + my $zdrive = "$releasedir\\z";
1.740 +
1.741 + ${$cmdref} =~ s/\$C/$cdrive/g;
1.742 + ${$cmdref} =~ s/\$Z/$zdrive/g;
1.743 + ${$cmdref} =~ s/\$RELEASE/$releasedir/g;
1.744 + ${$cmdref} =~ s/\$EPOC/$EPOCROOT/g;
1.745 + ${$cmdref} =~ s/\$ROOT/$ROOTDRIVE/g;
1.746 + ${$cmdref} =~ s/\$SUBSYSROOT/$RELSUBSYSROOT/g;
1.747 +}
1.748 +
1.749 +
1.750 +# This subroutine acts as a preprocessor for a config file. It
1.751 +# expands the test config file and produced a file in POSTPROCESSED
1.752 +sub ParseTestConfigFile
1.753 +{
1.754 + use File::Copy;
1.755 +
1.756 + # Firstly, copy the configuration file into the postprocessed file
1.757 + copy($TESTCONFIGFILE, $POSTPROCESSED);
1.758 +
1.759 + # set up boolean to indicate if preprocessing of #include is done
1.760 + my $keepgoing = "1";
1.761 +
1.762 + while ($keepgoing)
1.763 + {
1.764 + # reset the keepgoing flag
1.765 + $keepgoing = "";
1.766 +
1.767 + # if we have to keep going, copy the postprocessed file into a temp
1.768 + my $tempfile = "$RESULTDIR\\temp.txt";
1.769 + move ($POSTPROCESSED, $tempfile);
1.770 +
1.771 + open (TEMPFILE, "< $tempfile") || die "error opening $tempfile for reading";
1.772 + open (POSTFILE, "> $POSTPROCESSED") || die "error opening $POSTPROCESSED for writing";
1.773 +
1.774 + # Now search the temp file for instances of #include
1.775 + while (<TEMPFILE>)
1.776 + {
1.777 + my $line = $_;
1.778 + # check for comments - use C++ style //
1.779 + if ( $line =~ /(.*)\/\/.*/ )
1.780 + {
1.781 + # set the keepgoing flag
1.782 + $keepgoing = "1";
1.783 + print POSTFILE "$1\n";
1.784 + }
1.785 + elsif ( $line =~ /\#include[ ]+\"([^\"]*)\"/ )
1.786 + {
1.787 + # set the keepgoing flag because a #include has been found
1.788 + $keepgoing = "1";
1.789 +
1.790 + # now write the entire contents of this file into the
1.791 + # the postprocessed file
1.792 + my $contents = `type $SUBSYSTEMROOT\\$1`;
1.793 + print POSTFILE "$contents\n";
1.794 + }
1.795 + elsif ( $line =~ /^\s*$/ )
1.796 + {
1.797 + # remove if we have only whitespaces
1.798 + }
1.799 + else
1.800 + {
1.801 + print POSTFILE $line;
1.802 + }
1.803 + }
1.804 + close (TEMPFILE);
1.805 + close (POSTFILE);
1.806 +
1.807 + # delete the temp file
1.808 + unlink($tempfile);
1.809 + }
1.810 +}
1.811 +
1.812 +sub ReportToFiles
1.813 +{
1.814 + # this function just prints a string to both the log file and the error file
1.815 + my ($str) = @_;
1.816 +
1.817 + print LOGFILE $str;
1.818 + print ERRFILE $str;
1.819 +}
1.820 +
1.821 +sub DoBuildRoms
1.822 +{
1.823 + ReportToFiles("\n------------------- Now building roms\n\n");
1.824 +
1.825 + chdir ("$EPOCROOT\\rom");
1.826 +
1.827 + # create a new directory for the roms
1.828 + my $romdir = "$RESULTDIR\\roms";
1.829 + system("mkdir \"$romdir\"");
1.830 +
1.831 + # define the oby file to use
1.832 + my $oby_file = "techview.oby";
1.833 +
1.834 + # firstly, make sure the SecurityTests.iby file has been included from the techview.oby
1.835 + if (open(OBY, ">> include\\$oby_file"))
1.836 + {
1.837 + print OBY "\n#include <SecurityTests.iby>\n";
1.838 + close(OBY);
1.839 + }
1.840 +
1.841 + # Now go through the list of rom targets and build
1.842 + foreach my $rom (@ROMPLATFORMS)
1.843 + {
1.844 + ExecAndOutputToLog("tools\\buildrom -D__NOWATCHER__ -o$romdir\\$rom.img $rom $oby_file");
1.845 + }
1.846 +}
1.847 +
1.848 +sub SetVariable
1.849 +{
1.850 + # Sets a variable from an environment variable or a default value if the
1.851 + # environment variable has not been set
1.852 + my ($variable, $env_name, $default) = @_;
1.853 +
1.854 + ${$variable} = $ENV{$env_name};
1.855 + if (!${$variable})
1.856 + {
1.857 + ${$variable} = $default;
1.858 + }
1.859 +}
1.860 +
1.861 +# remove the watchers (prevents connection intermittently to NTRas)
1.862 +sub RemoveWatchers
1.863 +{
1.864 + my ($platform, $bt) = @_;
1.865 +
1.866 + ReportToFiles("------------------- Removing watchers\n");
1.867 +
1.868 + if ( ($platform eq "wins") or ($platform eq "winscw") )
1.869 + {
1.870 + # emulator build, delete the dlls for beech and exes for cedar
1.871 + system("del $EPOCROOT\\release\\$platform\\$bt\\watcher.dll");
1.872 + system("del $EPOCROOT\\release\\$platform\\$bt\\z\\system\\libs\\watcher.dll");
1.873 + system("del $EPOCROOT\\release\\$platform\\$bt\\watcher.exe");
1.874 + system("del $EPOCROOT\\release\\$platform\\$bt\\z\\system\\libs\\watcher.exe");
1.875 + }
1.876 + else
1.877 + {
1.878 + # hardware. remove the watchers from startup script
1.879 + if ( $TECHVIEWROOT )
1.880 + {
1.881 + system("attrib -r $TECHVIEWROOT\\toolkit\\startup\\group\\start.rss");
1.882 + system("copy $SUBSYSTEMROOT\\testframework\\test\\autotesting\\startnowatchers.rss $TECHVIEWROOT\\toolkit\\startup\\group\\start.rss");
1.883 + }
1.884 + }
1.885 +}