sl@0: # sl@0: # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # sl@0: sl@0: use strict; sl@0: sl@0: ################################################################################## sl@0: # These variables can be customised as required sl@0: # define some global variables - customise as required sl@0: my $REPORTDIR; sl@0: my $MAINLINEZIPDIR; sl@0: my $RELSUBSYSROOT; sl@0: my $TECHVIEWROOT; sl@0: sl@0: # set variables which can be set from the environment. If no environment sl@0: # equivalent is found, it will set to the default sl@0: SetVariable(\$REPORTDIR, "REPORTDIR", "L:\\AutoSecTests"); sl@0: SetVariable(\$MAINLINEZIPDIR, "MAINLINEZIPDIR", "\\\\builds01\\Master"); sl@0: SetVariable(\$RELSUBSYSROOT, "RELSUBSYSROOT", "security"); sl@0: sl@0: # To include Techview in build set environment variable: sl@0: # TECHVIEWROOT=Techview sl@0: SetVariable(\$TECHVIEWROOT, "TECHVIEWROOT", ""); sl@0: sl@0: # host platforms define which platforms are to be built and tests to run. Target sl@0: # platforms are those where roms are build sl@0: my @HOSTPLATFORMS = ("wins", "winscw"); sl@0: my @TARGETPLATFORMS = ("arm4", "thumb"); sl@0: my @ROMPLATFORMS = ("lubbock", "assabet"); sl@0: my @BUILDTYPES = ("udeb", "urel"); sl@0: # sl@0: # END of customisable variables sl@0: #################################################################################### sl@0: sl@0: my $P4CLIENTNAME = ConfigureDefaultClient(); sl@0: my $TESTCONFIGFILE; sl@0: my $SUBSYSTEMROOT; sl@0: # beech or cedar sl@0: my $BUILDPLATFORM; sl@0: sl@0: # first get the date sl@0: my @DATEARRAY = split(/[ \/]/, `date /t`); sl@0: sl@0: # command line arguments sl@0: my %ARGS = (); sl@0: sl@0: # Parse command line parameters sl@0: ProcessCommandLine(); sl@0: sl@0: # now, DATEARRAY[0] will be day, 1 will be date of month, 2 will be month, 3 is year sl@0: my $RESULTDIR = "$REPORTDIR\\$DATEARRAY[3]$DATEARRAY[2]$DATEARRAY[1]"; sl@0: sl@0: # define the file where the config.txt file is post-processed sl@0: my $POSTPROCESSED = "$RESULTDIR\\postprocessed.txt"; sl@0: sl@0: # create a new directory for today sl@0: system("mkdir \"$RESULTDIR\""); sl@0: sl@0: # create a logfile and error file sl@0: open (LOGFILE, "> $RESULTDIR\\log.txt") || die "error opening for writing"; sl@0: open (ERRFILE, "> $RESULTDIR\\error.txt") || die "error opening for writing"; sl@0: sl@0: # Derive rootdrive from perforce client. Set up variables sl@0: # which required the root drive to be configured. Note that sl@0: # the test config file is only overwritten if not configured by sl@0: # the command line. By default it looks for config.txt in the current sl@0: # directory sl@0: my $ROOTDRIVE = "L:"; sl@0: GetRootDrive(); sl@0: if (!$TESTCONFIGFILE) sl@0: { sl@0: use Cwd; sl@0: my $dir = cwd(); sl@0: $TESTCONFIGFILE = "$dir\\config.txt"; sl@0: } sl@0: if (!$SUBSYSTEMROOT) sl@0: { sl@0: $SUBSYSTEMROOT = "$ROOTDRIVE\\$RELSUBSYSROOT"; sl@0: } sl@0: sl@0: if ($TECHVIEWROOT) sl@0: { sl@0: $TECHVIEWROOT = "$ROOTDRIVE\\$TECHVIEWROOT"; sl@0: } sl@0: sl@0: # epoc root directory sl@0: my $EPOCROOT = "$ROOTDRIVE\\epoc32"; sl@0: sl@0: # add techview to build if requested sl@0: my @BUILDDIRS = ""; sl@0: if ( $TECHVIEWROOT ) sl@0: { sl@0: @BUILDDIRS = ( $SUBSYSTEMROOT, "$TECHVIEWROOT\\toolkit\\startup\\group", "$TECHVIEWROOT\\apps\\appinstui\\group", "$TECHVIEWROOT\\apps\\secui\\group"); sl@0: } sl@0: else sl@0: { sl@0: @BUILDDIRS = ( $SUBSYSTEMROOT ); sl@0: } sl@0: sl@0: print "BUILDIRS = @BUILDDIRS\n"; sl@0: sl@0: # call main sl@0: main(); sl@0: sl@0: # main function sl@0: sub main() sl@0: { sl@0: print "REPORTDIR = $REPORTDIR\n"; sl@0: print "MAINLINEZIPDIR = $MAINLINEZIPDIR\n"; sl@0: print "SUBSYSTEMROOT = $SUBSYSTEMROOT\n"; sl@0: print "TESTCONFIGFILE = $TESTCONFIGFILE\n"; sl@0: print "TECHVIEWROOT = $TECHVIEWROOT\n"; sl@0: print "BUILDPLATFORM = $BUILDPLATFORM\n"; sl@0: sl@0: # Figure out the second-latest release if none had been specified on the sl@0: # command line - we do not want the latest in case it has not yet been released. sl@0: my $releasedir = ""; sl@0: my $platformsuffix = ""; sl@0: if ($BUILDPLATFORM) sl@0: { sl@0: $platformsuffix = "_$BUILDPLATFORM"; sl@0: } sl@0: sl@0: if (!$ARGS{"mainline"}) sl@0: { sl@0: my $filelist = `dir $MAINLINEZIPDIR\\0????$platformsuffix /ad /b | sort /r`; sl@0: my @filearray = split "\n", $filelist; sl@0: $releasedir = $filearray[1]; sl@0: } sl@0: else sl@0: { sl@0: $releasedir = "$ARGS{\"mainline\"}$platformsuffix"; sl@0: } sl@0: sl@0: # Display what's to be done sl@0: ReportToFiles("------ Script run on $DATEARRAY[1]/$DATEARRAY[2]/$DATEARRAY[3] with the following options\n"); sl@0: ReportToFiles("------ Report directory: $REPORTDIR\n"); sl@0: ReportToFiles("------ Subsystem root: $SUBSYSTEMROOT\n"); sl@0: ReportToFiles("------ Test config file: $TESTCONFIGFILE\n"); sl@0: ReportToFiles("------ Built against MCL platform: $BUILDPLATFORM\n"); sl@0: if ($ARGS{s}) { ReportToFiles("------ Perforce synchronisation using client spec \"$P4CLIENTNAME\" on drive \"$ROOTDRIVE\"\n"); } sl@0: if ($ARGS{u}) { ReportToFiles("------ Mainline unzip using build $releasedir\n"); } sl@0: if ($ARGS{b}) { ReportToFiles("------ Build of production and test code\n"); } sl@0: if ($ARGS{t}) { ReportToFiles("------ Running of test code on the host using $TESTCONFIGFILE\n"); } sl@0: if ($ARGS{f}) { ReportToFiles("------ Build rom first\n"); } sl@0: if ($ARGS{t}) { ReportToFiles("------ Running of test code on the host using $TESTCONFIGFILE\n"); } sl@0: sl@0: if ($ARGS{r}) sl@0: { sl@0: ReportToFiles("------ Building of target roms: "); sl@0: map { ReportToFiles("$_ "); } @ROMPLATFORMS; sl@0: ReportToFiles("\n"); sl@0: } sl@0: ReportToFiles("------ Host builds used: "); sl@0: map { ReportToFiles("$_ "); } @HOSTPLATFORMS; sl@0: ReportToFiles("\n------ Target processor builds used: "); sl@0: map { ReportToFiles("$_ "); } @TARGETPLATFORMS; sl@0: ReportToFiles("\n------ Build types used: "); sl@0: map { ReportToFiles("$_ "); } @BUILDTYPES; sl@0: ReportToFiles("\n\n"); sl@0: sl@0: # Do a perforce sync sl@0: if ($ARGS{s}) sl@0: { sl@0: DoPerforceSync(); sl@0: } sl@0: sl@0: # Now unzip the mainline sl@0: if ($ARGS{u}) sl@0: { sl@0: DoMainlineUnzip($releasedir); sl@0: } sl@0: sl@0: # Build the post-processed config file if the test flag is on sl@0: if ($ARGS{t}) sl@0: { sl@0: ParseTestConfigFile(); sl@0: } sl@0: sl@0: # Build the tools sl@0: if ($ARGS{o}) sl@0: { sl@0: foreach my $bt (@BUILDTYPES) sl@0: { sl@0: DoBuildTools($bt); sl@0: } sl@0: } sl@0: sl@0: # Build rom first? sl@0: if ( $ARGS{f} ) sl@0: { sl@0: # Now build the target platforms - no testing required sl@0: if ($ARGS{b}) sl@0: { sl@0: foreach my $platform (@TARGETPLATFORMS) sl@0: { sl@0: foreach my $bt (@BUILDTYPES) sl@0: { sl@0: # Must build dummy midp2installerclient for cedar sl@0: if ( $BUILDPLATFORM eq "cedar" ) sl@0: { sl@0: my @tempbuilddirs = @BUILDDIRS; sl@0: @BUILDDIRS = ("$SUBSYSTEMROOT\\appinst\\tsrc"); sl@0: print "Building dummy midp2installerclient....on $platform/$bt\n"; sl@0: DoBuild($platform, $bt); sl@0: # now build the rest sl@0: @BUILDDIRS = @tempbuilddirs; sl@0: } sl@0: DoBuild($platform, $bt); sl@0: } sl@0: } sl@0: } sl@0: # Now build the roms if required sl@0: if ($ARGS{r}) sl@0: { sl@0: DoBuildRoms(); sl@0: } sl@0: } sl@0: sl@0: # Build and test host platforms. They get built and then tested in order. sl@0: # This is required as the EPOC C drive is shared between udeb and urel. sl@0: # If the build/test is run together as a set, then the state of the C sl@0: # drive will be restored sl@0: foreach my $platform (@HOSTPLATFORMS) sl@0: { sl@0: foreach my $bt (@BUILDTYPES) sl@0: { sl@0: if ($ARGS{b}) sl@0: { sl@0: DoBuild($platform, $bt); sl@0: } sl@0: if ($ARGS{t}) sl@0: { sl@0: DoRunTests($platform, $bt); sl@0: } sl@0: } sl@0: } sl@0: sl@0: # Now build the target platforms (unless this has been done in advance) - no testing required sl@0: if ( !$ARGS{f} ) sl@0: { sl@0: if ($ARGS{b}) sl@0: { sl@0: foreach my $platform (@TARGETPLATFORMS) sl@0: { sl@0: foreach my $bt (@BUILDTYPES) sl@0: { sl@0: # Must build dummy midp2installerclient for cedar sl@0: if ( $BUILDPLATFORM eq "cedar" ) sl@0: { sl@0: my @tempbuilddirs = @BUILDDIRS; sl@0: @BUILDDIRS = ("$SUBSYSTEMROOT\\appinst\\tsrc"); sl@0: print "Building dummy midp2installerclient....on $platform/$bt\n"; sl@0: DoBuild($platform, $bt); sl@0: # now build the rest sl@0: @BUILDDIRS = @tempbuilddirs; sl@0: } sl@0: DoBuild($platform, $bt); sl@0: } sl@0: } sl@0: } sl@0: # Now build the roms if required sl@0: if ($ARGS{r}) sl@0: { sl@0: DoBuildRoms(); sl@0: } sl@0: } sl@0: sl@0: my $timeoutput = `time /t`; sl@0: ReportToFiles("\n------------------- Job finished at $timeoutput\n\n"); sl@0: sl@0: } sl@0: sub ConfigureDefaultClient sl@0: { sl@0: # this subroutine figures out what default perforce client to use sl@0: my $clientoutput = `p4 client -o`; sl@0: sl@0: if ($clientoutput =~ /\nClient:\s*([^\s]*)/ ) sl@0: { sl@0: return $1; sl@0: } sl@0: } sl@0: sl@0: sub GetRootDrive sl@0: { sl@0: # this subroutine derives the rootdrive from the perforce client sl@0: my $clientoutput = `p4 client -o`; sl@0: sl@0: if ($clientoutput =~ /\nRoot:\s*(.):/ ) sl@0: { sl@0: $ROOTDRIVE = "$1:" sl@0: } sl@0: } sl@0: sl@0: sub ProcessCommandLine sl@0: { sl@0: use Getopt::Long; sl@0: &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: sl@0: # if the -a option is specified, this means that sync, unzip, build, run sl@0: # tests, and rom options should be set sl@0: if ($ARGS{a}) sl@0: { sl@0: $ARGS{o} = $ARGS{s} = $ARGS{u} = $ARGS{b} = $ARGS{t} = $ARGS{r} = $ARGS{a}; sl@0: } sl@0: sl@0: # if the help option is specified, or none of the other arguments are specified, sl@0: # or both beech and cedar requested, then display the help sl@0: if ($ARGS{h} || (!$ARGS{s} && !$ARGS{u} && !$ARGS{b} && !$ARGS{t} && !$ARGS{r} && !$ARGS{o})) sl@0: { sl@0: print "Command line switches: \n"; sl@0: print " -s Do perforce synchronisation\n"; sl@0: print " -u Do unzipping from the mainline\n"; sl@0: print " -b Build the appropriate targets\n"; sl@0: print " -t Run the test suite\n"; sl@0: print " -r Build the roms\n"; sl@0: print " -o Build the tools\n"; sl@0: print " -a Do all of the above\n"; sl@0: print " -f Build rom First (before wins winscw)\n"; sl@0: print " -h Display this screen\n"; sl@0: print "\nOther options:\n"; sl@0: print " --wins Use the wins platform for building and running of host tests\n"; sl@0: print " --winscw Use the winscw platform for building and running of host tests\n"; sl@0: print " --nohost Do not use any host platform\n"; sl@0: print " --arm4 Use the arm4 processor for rom building\n"; sl@0: print " --thumb Use the thumb processor for rom building\n"; sl@0: print " --notgt Do not use any target platform\n"; sl@0: print " --assabet Build roms for assabet platform\n"; sl@0: print " --lubbock Build roms for lubbock platform\n"; sl@0: print " --udeb Build udeb version only\n"; sl@0: print " --urel Build urel version only\n"; sl@0: print "\nParameters:\n"; sl@0: print " --client= Specifies the perforce client to use (default: $P4CLIENTNAME)\n"; sl@0: print " --workdir= Specifies the working directory (default: $REPORTDIR)\n"; sl@0: print " --subsystemroot= Specifies the root directory to build\n"; sl@0: print " --configfile= Specifies the test config file\n"; sl@0: print " --mainline= Specifies the release number to use\n"; sl@0: print " --platform= Specifies MCL platform. Default is beech. Set to none for pre MCL builds\n"; sl@0: print "\nExamples:\n"; sl@0: print " perl -w RunTests.pl -b -t -r --wins --lubbock --thumb --platform=cedar --client=lon-julianl\n\n"; sl@0: print " Uses drive m, client lon-julianl, build against cedar and builds and runs tests on the wins\n"; sl@0: print " platform and builds roms for lubbock\n\n"; sl@0: print " perl -w RunTests.pl -u -b --winscw --urel --notgt --mainline=01038\n\n"; sl@0: print " Unzips mainline 01038_beech and builds only winscw/urel. Uses default client\n"; sl@0: print " perl -w RunTests.pl -u -b --winscw --urel --notgt --platform=none --mainline=01038\n\n"; sl@0: print " Unzips mainline 01038 and builds only winscw/urel. Uses default client\n"; sl@0: exit(0); sl@0: } sl@0: sl@0: # Now parse the client, drive, and working directory parameters sl@0: if ($ARGS{"client"}) sl@0: { sl@0: $P4CLIENTNAME = $ARGS{"client"}; sl@0: $ENV{"P4CLIENT"} = $P4CLIENTNAME; sl@0: } sl@0: if ($ARGS{"configfile"}) sl@0: { sl@0: $TESTCONFIGFILE = $ARGS{"configfile"}; sl@0: } sl@0: if ($ARGS{"workdir"}) sl@0: { sl@0: $REPORTDIR = $ARGS{"workdir"}; sl@0: } sl@0: if ($ARGS{"subsystemroot"}) sl@0: { sl@0: $SUBSYSTEMROOT = $ARGS{"subsystemroot"}; sl@0: } sl@0: sl@0: use Getopt::Long; sl@0: sl@0: # now parse the host options sl@0: if ($ARGS{"nohost"}) sl@0: { sl@0: @HOSTPLATFORMS = (); sl@0: } sl@0: else sl@0: { sl@0: ParseArguments(\@HOSTPLATFORMS); sl@0: } sl@0: sl@0: # now parse the target platforms sl@0: if ($ARGS{"notgt"}) sl@0: { sl@0: @TARGETPLATFORMS = (); sl@0: } sl@0: else sl@0: { sl@0: ParseArguments(\@TARGETPLATFORMS); sl@0: } sl@0: sl@0: # now parse the rom platforms and the build types sl@0: ParseArguments(\@ROMPLATFORMS); sl@0: ParseArguments(\@BUILDTYPES); sl@0: sl@0: if ($ARGS{"platform"}) sl@0: { sl@0: $BUILDPLATFORM=$ARGS{"platform"}; sl@0: if ($BUILDPLATFORM eq "none") sl@0: { sl@0: # set compatibity for pre MCL builds sl@0: $BUILDPLATFORM=""; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: # default sl@0: $BUILDPLATFORM="beech"; sl@0: } sl@0: } sl@0: sl@0: sub ParseArguments sl@0: { sl@0: # common parsing of arguments in an array - returns another array sl@0: # which have the options specified. sl@0: # If none specified, it returns ALL the options. sl@0: # sl@0: # eg. If -wins specified, and options = ("wins", "winscw"), then sl@0: # return array is just ("wins"). If neither wins or winscw specified, sl@0: # then returns both sl@0: (my $options) = @_; sl@0: my @retoptions = (); sl@0: sl@0: foreach my $opt (@$options) sl@0: { sl@0: if ($ARGS{$opt}) sl@0: { sl@0: push(@retoptions, $opt); sl@0: } sl@0: } sl@0: sl@0: # change if we have at least one option specified sl@0: if (scalar(@retoptions) > 0) sl@0: { sl@0: @$options = @retoptions; sl@0: } sl@0: } sl@0: sl@0: # subroutine to do a perforce sync sl@0: sub DoPerforceSync sl@0: { sl@0: print "Doing a Perforce synchronisation....\n"; sl@0: ExecAndOutputToLog("p4 sync -f $SUBSYSTEMROOT\\..."); sl@0: if ( $TECHVIEWROOT ) sl@0: { sl@0: ExecAndOutputToLog("p4 sync -f $TECHVIEWROOT\\..."); sl@0: } sl@0: } sl@0: sl@0: # subroutine to do the unzipping sl@0: sub DoMainlineUnzip sl@0: { sl@0: my ($dir) = @_; sl@0: print "Doing an unzip of mainline $MAINLINEZIPDIR\\$dir...\n"; sl@0: sl@0: my @zipfiles = ("techview"); sl@0: sl@0: # firstly, delete anything already there sl@0: ExecAndOutputToLog("del \/F \/S \/Q $EPOCROOT"); sl@0: sl@0: # unzip all the zipfiles sl@0: map { ExecAndOutputToLog("t:\\tools\\unzip -o $MAINLINEZIPDIR\\$dir\\zips\\$_.zip -d $ROOTDRIVE\\"); } @zipfiles; sl@0: } sl@0: sl@0: # subrountine to build or clean release or test build sl@0: # call RunAbld("", "", "", "test" or "") sl@0: sub RunAbld sl@0: { sl@0: my ($dir, $cmd, $target, $test, $bldtype) = @_; sl@0: chdir ($dir); sl@0: sl@0: my $bldcommand = "abld $test $cmd -k $target $bldtype"; sl@0: my $bldoutput = ExecAndOutputToLog($bldcommand); sl@0: sl@0: if ($cmd eq "build") sl@0: { sl@0: # match "error:" or "error(s)" or fatal error sl@0: my @errout = grep(/(error(\(s\)|\:))|fatal error/i, split("\n", $bldoutput)); sl@0: sl@0: if (scalar(@errout) > 0) sl@0: { sl@0: print ERRFILE "-------- Errors found when running $bldcommand\n"; sl@0: map { print ERRFILE "$_\n"; } @errout; sl@0: print ERRFILE "-------- End of errors for $bldcommand\n\n"; sl@0: } sl@0: } sl@0: } sl@0: sl@0: # builds the release and test code for a specified platform and mode sl@0: # eg WINS/UDEB sl@0: sub DoBuild sl@0: { sl@0: my ($platform, $bt) = @_; sl@0: sl@0: RemoveWatchers($platform, $bt); sl@0: sl@0: foreach my $bd (@BUILDDIRS) sl@0: { sl@0: sl@0: chdir ($bd); sl@0: system("bldmake bldfiles"); sl@0: sl@0: print "Building build targets.... $bd on $platform/$bt\n"; sl@0: ReportToFiles("\n------------------- Now building $bd on $platform/$bt\n\n"); sl@0: sl@0: RunAbld($bd, "clean", $platform, "", $bt); sl@0: RunAbld($bd, "clean", $platform, "test", $bt); sl@0: RunAbld($bd, "build", $platform, "", $bt); sl@0: RunAbld($bd, "build", $platform, "test", $bt); sl@0: } sl@0: } sl@0: sl@0: # builds the tools for deb or rel sl@0: sub DoBuildTools sl@0: { sl@0: my ($bt) = @_; sl@0: sl@0: #adjust for unicode sl@0: if ($bt eq "udeb") sl@0: { sl@0: $bt = "deb"; sl@0: } sl@0: if ($bt eq "urel") sl@0: { sl@0: $bt = "rel"; sl@0: } sl@0: sl@0: foreach my $bd (@BUILDDIRS) sl@0: { sl@0: chdir ($bd); sl@0: system("bldmake bldfiles"); sl@0: sl@0: print "Building tools.... $bd on $bt\n"; sl@0: ReportToFiles("\n------------------- Now building $bd for tools on $bt\n\n"); sl@0: sl@0: RunAbld($bd, "clean", "tools", "", $bt); sl@0: RunAbld($bd, "build", "tools", "", $bt); sl@0: } sl@0: } sl@0: sl@0: # this subroutine executes the given command and outputs to the log file sl@0: sub ExecAndOutputToLog sl@0: { sl@0: my ($cmd) = @_; sl@0: my $timeoutput = `time /t`; sl@0: my $cmdoutput = `$cmd 2>&1`; sl@0: sl@0: # capture output to log file sl@0: print LOGFILE "-------- Output of $cmd run at $timeoutput"; sl@0: if ($cmdoutput) sl@0: { sl@0: print LOGFILE "$cmdoutput\n"; sl@0: } sl@0: else sl@0: { sl@0: print LOGFILE "(NO OUTPUT)\n"; sl@0: } sl@0: sl@0: if ($? != 0) sl@0: { sl@0: print ERRFILE "\n-------- Error code $? returned when executing:\n"; sl@0: print ERRFILE "-------- \"$cmd\".\n"; sl@0: sl@0: if ($cmdoutput) sl@0: { sl@0: print ERRFILE "-------- Output:\n"; sl@0: print ERRFILE "$cmdoutput"; sl@0: } sl@0: } sl@0: return $cmdoutput; sl@0: } sl@0: sl@0: # this subroutine executes all the tests as specified in the configuration file. sl@0: # It will run the tests for the specified platform/built type sl@0: # sl@0: # The configuration file has the following valid commands: sl@0: # sl@0: # #include - includes another config file sl@0: # SYSTEMCMD - executes a DOS command eg SYSTEMCMD copy a.txt b.txt sl@0: # DOTEST ... - executes a test sl@0: # COMP - compares two files and logs result sl@0: # sl@0: # For SYSTEMCMD and COMP, the following variables get substituted sl@0: # - $C - the current EPOC C drive (eg o:\epoc32\wins\c) sl@0: # - $Z - the current EPOC Z drive (eg o:\epoc32\release\wins\udeb\z) sl@0: # - $RELEASE - the epoc release directory for this build (eg o:\epoc32\release\wins\udeb) sl@0: # - $EPOC - the epoc root (eg o:\epoc32) sl@0: # - $ROOT - the root drive (eg o:) sl@0: sub DoRunTests sl@0: { sl@0: # platform and build type sl@0: my ($p, $bt) = @_; sl@0: print "Running tests on platform $p/$bt\n"; sl@0: ReportToFiles("\n------------------- Now running tests on platform $p/$bt\n\n"); sl@0: sl@0: # set the default directory to be the subsystem root sl@0: chdir($SUBSYSTEMROOT); sl@0: sl@0: # Make the results directory sl@0: my $testlogs = "$RESULTDIR\\testlogs"; sl@0: system("mkdir $testlogs"); sl@0: system("mkdir $testlogs\\$p"); sl@0: system("mkdir $testlogs\\$p\\$bt"); sl@0: sl@0: # open the post processed file sl@0: open (POSTFILE, "< $POSTPROCESSED") || die "error opening $POSTPROCESSED for reading"; sl@0: # open a separate report file for test results sl@0: open (TESTREPFILE, "> $RESULTDIR\\testresults.$p.$bt.txt") || die "error opening for writing"; sl@0: sl@0: my $timeoutput = `time /t`; sl@0: print TESTREPFILE "-------- Test log file when running on platform $p/$bt at $timeoutput"; sl@0: sl@0: my $cdrive = "$EPOCROOT\\$p\\c"; sl@0: while () sl@0: { sl@0: my $line = $_; sl@0: sl@0: # check for a line with SYSTEMCMD sl@0: if ( $line =~ /^SYSTEMCMD[ ]+(.*)/ ) sl@0: { sl@0: # Substitute $C for the cdrive, $Z for the zdrive, and $RELEASE sl@0: # for the release path, etc sl@0: my $cmd = $1; sl@0: SubstitutePaths($p, $bt, \$cmd); sl@0: sl@0: print " - executing system command: $cmd\n"; sl@0: ExecAndOutputToLog($cmd); sl@0: } sl@0: elsif ( $line =~ /^\s*$/ ) sl@0: { sl@0: # if we have an empty line then do nothing sl@0: } sl@0: elsif ( $line =~ /^DOTEST\s+([^\s]+)[\s]+([^\s]+)[\s]+([^\s]+)/ ) sl@0: { sl@0: # if this pattern matches DOTEST , sl@0: # then we execute this test - extra parameters can be supplied after the logfile sl@0: print " - running test: $1 $2 $3\n"; sl@0: ExecAndOutputToLog("$EPOCROOT\\release\\$p\\$bt\\$1 $2 $3 $'"); sl@0: sl@0: # log files are assumed to be stored in \epoc32\wins\c sl@0: my $outfile = "$cdrive\\$3"; sl@0: sl@0: print TESTREPFILE "\n---- Result of test \"$1 $2 $3\"\n"; sl@0: if (-e $outfile) sl@0: { sl@0: # also, copy the log file into the results dir sl@0: copy ($outfile, "$testlogs\\$p\\$bt\\$3"); sl@0: sl@0: # check to see if there is a failure sl@0: my $output = `type $outfile`; sl@0: if ($output =~ /(\d+) tests failed out of (\d+)/) sl@0: { sl@0: print TESTREPFILE " $1 tests failed out of $2\n"; sl@0: if ($1 ne "0") sl@0: { sl@0: # if there is a fail, then print it in the test log sl@0: print ERRFILE "-------- Logfile $outfile produced a failure result!\n"; sl@0: print ERRFILE "$output\n"; sl@0: print TESTREPFILE " There was a test FAILURE\n"; sl@0: } sl@0: else sl@0: { sl@0: print TESTREPFILE " All tests SUCCEEDED\n"; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: # if it doesn't conform to standard format, then need to notify sl@0: print TESTREPFILE " WARNING: non-standard log file format - check log\n"; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: # if we get here, the output file didn't exist sl@0: print ERRFILE "-------- Logfile $outfile does not exist - did $1 fail to build?\n"; sl@0: print TESTREPFILE " ERROR! Log file $outfile does not exist\n"; sl@0: } sl@0: sl@0: } sl@0: elsif ( $line =~ /^COMP\s+([^\s]+)[\s]+([^\s]+)/ ) sl@0: { sl@0: # Parse our paths sl@0: my $file1 = $1; sl@0: my $file2 = $2; sl@0: sl@0: # substitute variables sl@0: SubstitutePaths($p, $bt, \$file1); sl@0: SubstitutePaths($p, $bt, \$file2); sl@0: sl@0: print " - doing comparison on $file1 and $file2\n"; sl@0: print TESTREPFILE "\n---- Comparing $file1 and $file2\n"; sl@0: my $output = ExecAndOutputToLog("diff -q $file1 $file2"); sl@0: sl@0: if ( $output =~ /differ/ ) sl@0: { sl@0: print TESTREPFILE " Comparison FAILED\n"; sl@0: } sl@0: else sl@0: { sl@0: print TESTREPFILE " Comparison SUCCESSFUL\n"; sl@0: } sl@0: } sl@0: sl@0: else sl@0: { sl@0: ReportToFiles("**** Error test config line: $line"); sl@0: } sl@0: } sl@0: close (POSTFILE); sl@0: close (TESTREPFILE); sl@0: } sl@0: sl@0: # - $C - the current EPOC C drive (eg o:\epoc32\wins\c) sl@0: # - $Z - the current EPOC Z drive (eg o:\epoc32\release\wins\udeb\z) sl@0: # - $RELEASE - the epoc release directory for this build (eg o:\epoc32\release\wins\udeb) sl@0: # - $EPOC - the epoc root (eg o:\epoc32) sl@0: # - $ROOT - the root drive (eg o:) sl@0: # - $SUBSYSROOT - subsystem root e.g. security sl@0: sub SubstitutePaths sl@0: { sl@0: my ($platform, $buildtype, $cmdref) = @_; sl@0: sl@0: my $cdrive = "$EPOCROOT\\$platform\\c"; sl@0: my $releasedir = "$EPOCROOT\\release\\$platform\\$buildtype"; sl@0: my $zdrive = "$releasedir\\z"; sl@0: sl@0: ${$cmdref} =~ s/\$C/$cdrive/g; sl@0: ${$cmdref} =~ s/\$Z/$zdrive/g; sl@0: ${$cmdref} =~ s/\$RELEASE/$releasedir/g; sl@0: ${$cmdref} =~ s/\$EPOC/$EPOCROOT/g; sl@0: ${$cmdref} =~ s/\$ROOT/$ROOTDRIVE/g; sl@0: ${$cmdref} =~ s/\$SUBSYSROOT/$RELSUBSYSROOT/g; sl@0: } sl@0: sl@0: sl@0: # This subroutine acts as a preprocessor for a config file. It sl@0: # expands the test config file and produced a file in POSTPROCESSED sl@0: sub ParseTestConfigFile sl@0: { sl@0: use File::Copy; sl@0: sl@0: # Firstly, copy the configuration file into the postprocessed file sl@0: copy($TESTCONFIGFILE, $POSTPROCESSED); sl@0: sl@0: # set up boolean to indicate if preprocessing of #include is done sl@0: my $keepgoing = "1"; sl@0: sl@0: while ($keepgoing) sl@0: { sl@0: # reset the keepgoing flag sl@0: $keepgoing = ""; sl@0: sl@0: # if we have to keep going, copy the postprocessed file into a temp sl@0: my $tempfile = "$RESULTDIR\\temp.txt"; sl@0: move ($POSTPROCESSED, $tempfile); sl@0: sl@0: open (TEMPFILE, "< $tempfile") || die "error opening $tempfile for reading"; sl@0: open (POSTFILE, "> $POSTPROCESSED") || die "error opening $POSTPROCESSED for writing"; sl@0: sl@0: # Now search the temp file for instances of #include sl@0: while () sl@0: { sl@0: my $line = $_; sl@0: # check for comments - use C++ style // sl@0: if ( $line =~ /(.*)\/\/.*/ ) sl@0: { sl@0: # set the keepgoing flag sl@0: $keepgoing = "1"; sl@0: print POSTFILE "$1\n"; sl@0: } sl@0: elsif ( $line =~ /\#include[ ]+\"([^\"]*)\"/ ) sl@0: { sl@0: # set the keepgoing flag because a #include has been found sl@0: $keepgoing = "1"; sl@0: sl@0: # now write the entire contents of this file into the sl@0: # the postprocessed file sl@0: my $contents = `type $SUBSYSTEMROOT\\$1`; sl@0: print POSTFILE "$contents\n"; sl@0: } sl@0: elsif ( $line =~ /^\s*$/ ) sl@0: { sl@0: # remove if we have only whitespaces sl@0: } sl@0: else sl@0: { sl@0: print POSTFILE $line; sl@0: } sl@0: } sl@0: close (TEMPFILE); sl@0: close (POSTFILE); sl@0: sl@0: # delete the temp file sl@0: unlink($tempfile); sl@0: } sl@0: } sl@0: sl@0: sub ReportToFiles sl@0: { sl@0: # this function just prints a string to both the log file and the error file sl@0: my ($str) = @_; sl@0: sl@0: print LOGFILE $str; sl@0: print ERRFILE $str; sl@0: } sl@0: sl@0: sub DoBuildRoms sl@0: { sl@0: ReportToFiles("\n------------------- Now building roms\n\n"); sl@0: sl@0: chdir ("$EPOCROOT\\rom"); sl@0: sl@0: # create a new directory for the roms sl@0: my $romdir = "$RESULTDIR\\roms"; sl@0: system("mkdir \"$romdir\""); sl@0: sl@0: # define the oby file to use sl@0: my $oby_file = "techview.oby"; sl@0: sl@0: # firstly, make sure the SecurityTests.iby file has been included from the techview.oby sl@0: if (open(OBY, ">> include\\$oby_file")) sl@0: { sl@0: print OBY "\n#include \n"; sl@0: close(OBY); sl@0: } sl@0: sl@0: # Now go through the list of rom targets and build sl@0: foreach my $rom (@ROMPLATFORMS) sl@0: { sl@0: ExecAndOutputToLog("tools\\buildrom -D__NOWATCHER__ -o$romdir\\$rom.img $rom $oby_file"); sl@0: } sl@0: } sl@0: sl@0: sub SetVariable sl@0: { sl@0: # Sets a variable from an environment variable or a default value if the sl@0: # environment variable has not been set sl@0: my ($variable, $env_name, $default) = @_; sl@0: sl@0: ${$variable} = $ENV{$env_name}; sl@0: if (!${$variable}) sl@0: { sl@0: ${$variable} = $default; sl@0: } sl@0: } sl@0: sl@0: # remove the watchers (prevents connection intermittently to NTRas) sl@0: sub RemoveWatchers sl@0: { sl@0: my ($platform, $bt) = @_; sl@0: sl@0: ReportToFiles("------------------- Removing watchers\n"); sl@0: sl@0: if ( ($platform eq "wins") or ($platform eq "winscw") ) sl@0: { sl@0: # emulator build, delete the dlls for beech and exes for cedar sl@0: system("del $EPOCROOT\\release\\$platform\\$bt\\watcher.dll"); sl@0: system("del $EPOCROOT\\release\\$platform\\$bt\\z\\system\\libs\\watcher.dll"); sl@0: system("del $EPOCROOT\\release\\$platform\\$bt\\watcher.exe"); sl@0: system("del $EPOCROOT\\release\\$platform\\$bt\\z\\system\\libs\\watcher.exe"); sl@0: } sl@0: else sl@0: { sl@0: # hardware. remove the watchers from startup script sl@0: if ( $TECHVIEWROOT ) sl@0: { sl@0: system("attrib -r $TECHVIEWROOT\\toolkit\\startup\\group\\start.rss"); sl@0: system("copy $SUBSYSTEMROOT\\testframework\\test\\autotesting\\startnowatchers.rss $TECHVIEWROOT\\toolkit\\startup\\group\\start.rss"); sl@0: } sl@0: } sl@0: }