os/security/cryptomgmtlibs/securitytestfw/test/autotesting/test_launcher.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#
sl@0
     2
# Copyright (c) 2008-2010 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
# This script runs security tests for chosen components on a local machine without DABS scripts and ONB. Follow the steps below
sl@0
    16
# in order to launch tests for a security component:
sl@0
    17
# 1. Choose a local drive to be used, e.g. p:
sl@0
    18
# 2. Download a CBR onto the chosen drive.
sl@0
    19
# 3. Download the security source tree onto the chosen drive, and ensure that your environment variable 
sl@0
    20
# SECURITYSOURCEDIR points to the relevant root directory.  It helps to use a drive independant value here 
sl@0
    21
# as this will allow concurrent builds and test runs on seperate drives (assuming the source code has the same path in each case).
sl@0
    22
# 4. Download ExecTimeOut.exe, which is stored at //PR/share/DABSRelease/buildscripts/, onto the relevant location
sl@0
    23
# (by default this is the chosen drive's root).  
sl@0
    24
# 5. Build the security code.  Note that builds require the SECURITYSOURCEDIR environment variable to be set.
sl@0
    25
# 6. Run or modify the relevant wrapper batch file for your component, which will be stored in the root of the test directory.
sl@0
    26
# Components Summary
sl@0
    27
# This script works fine with the following components: Asnpkcs, Caf2, Certman, Common, Crypto, Cryptospi, CryptoTokens,
sl@0
    28
# FileTokens, Sistools, Streamingcaf, Swi, Switools, Ups. Other components must be tested and therefore 
sl@0
    29
# further extensions may be needed.
sl@0
    30
#
sl@0
    31
sl@0
    32
use Cwd;
sl@0
    33
use Getopt::Long;
sl@0
    34
sl@0
    35
########################### Start of Input Reading Block ###########################
sl@0
    36
sl@0
    37
# Check environment variable SECURITYSOURCEDIR is correctly set
sl@0
    38
if ($ENV{'SECURITYSOURCEDIR'} eq "")
sl@0
    39
	{
sl@0
    40
	die "ERROR: The SECURITYSOURCEDIR environment variable has not been set.  Set this to point to the root of the security source tree on your drive and rebuild the components you want to test.  If you want to perform concurrent builds/tests use a drive relative value and use the same directory structure on each drive.";
sl@0
    41
	}
sl@0
    42
else
sl@0
    43
	{
sl@0
    44
	my $current_dir = getcwd();
sl@0
    45
	$current_dir =~ /^(\D):/;	# $1 = driveletter
sl@0
    46
	
sl@0
    47
	my $current_drive = lc $1;	
sl@0
    48
sl@0
    49
	$ENV{'SECURITYSOURCEDIR'} =~ /^(\D):/;	# $1 = driveletter if it exists
sl@0
    50
	my $sourcedir_drive =  lc $1;
sl@0
    51
sl@0
    52
	if (($sourcedir_drive ne "") && ($sourcedir_drive ne $current_drive))
sl@0
    53
		{
sl@0
    54
		print "WARNING: Your SECURITYSOURCEDIR environment variable is set to an absolute path and points to a different drive than the current one\n" . "SECURITYSOURCEDIR=  " . $ENV{'SECURITYSOURCEDIR'} . "\nAre you sure you want to continue (Y/N)?\n";
sl@0
    55
		my $user_decision = <STDIN>;
sl@0
    56
		$user_decision = lc $user_decision;
sl@0
    57
		$user_decision =~ /^(.*)\n/;
sl@0
    58
		if (($1 ne "y") && ($1 ne "yes"))
sl@0
    59
			{
sl@0
    60
			die "User decided not to continue, quiting...";
sl@0
    61
			}
sl@0
    62
		}
sl@0
    63
	}
sl@0
    64
sl@0
    65
# Read in command line arguments
sl@0
    66
my $testedComponentsRaw;
sl@0
    67
my @testedComponents;
sl@0
    68
my $testedReleasesRaw;
sl@0
    69
my @testedReleases;
sl@0
    70
my $ExecTimeOut;
sl@0
    71
my $resultsOutputDir;
sl@0
    72
my $skipCleanAfterFinalComponent;
sl@0
    73
my $suppressBrowserPopup;
sl@0
    74
my $displayHelp;
sl@0
    75
sl@0
    76
GetOptions("components=s" => \$testedComponentsRaw, 
sl@0
    77
	   "testReleases=s" => \$testedReleasesRaw,
sl@0
    78
	   "resultsoutput=s" => \$resultsOutputDir,
sl@0
    79
	   "exectimeout=s" => \$ExecTimeOut,
sl@0
    80
	   "suppressbrowser" => \$suppressBrowserPopup,
sl@0
    81
	   "skipfinalclean" => \$skipCleanAfterFinalComponent,
sl@0
    82
	   "help" => \$displayHelp);
sl@0
    83
sl@0
    84
if ($displayHelp)
sl@0
    85
{
sl@0
    86
	DisplayHelp();
sl@0
    87
}
sl@0
    88
sl@0
    89
# Ensure necessary arguments are present
sl@0
    90
$shouldIDie = 0;
sl@0
    91
sl@0
    92
while ($testedComponentsRaw =~ s/([^,]*),//)
sl@0
    93
{
sl@0
    94
	push(@testedComponents, $1);
sl@0
    95
}			
sl@0
    96
if ($testedComponentsRaw =~ /\S/)
sl@0
    97
{	
sl@0
    98
	push(@testedComponents, $testedComponentsRaw);
sl@0
    99
}
sl@0
   100
else
sl@0
   101
{
sl@0
   102
	print "ERROR: Components to be tested not listed (e.g. -components caf2,streamingcaf).\n";
sl@0
   103
	$shouldIDie = 1;
sl@0
   104
}
sl@0
   105
sl@0
   106
while ($testedReleasesRaw =~ s/([^,]*),//)
sl@0
   107
{
sl@0
   108
	push(@testedReleases, $1);
sl@0
   109
}
sl@0
   110
if ($testedReleasesRaw =~ /\S/)
sl@0
   111
{
sl@0
   112
	push(@testedReleases, $testedReleasesRaw);
sl@0
   113
}
sl@0
   114
else
sl@0
   115
{			
sl@0
   116
	print "ERROR: Releases to be tested not listed (e.g. -testReleases udeb,urel).\n";
sl@0
   117
	$shouldIDie = 1;		
sl@0
   118
}
sl@0
   119
sl@0
   120
sl@0
   121
if (!defined $ExecTimeOut)
sl@0
   122
{
sl@0
   123
	print "ERROR: Location of ExecTimeOut.exe not specified (e.g. -exectimeout \\ExecTimeOut.exe).\n";
sl@0
   124
	$shouldIDie = 1;
sl@0
   125
}
sl@0
   126
if (!defined $resultsOutputDir)
sl@0
   127
{
sl@0
   128
	print "ERROR: Directory to place test results not specified (e.g. -resultsoutput \\logs\\winscw).\n";
sl@0
   129
	$shouldIDie = 1;
sl@0
   130
}
sl@0
   131
sl@0
   132
if ($shouldIDie)
sl@0
   133
{
sl@0
   134
	die "Input parameters incorrect, exiting.";
sl@0
   135
}
sl@0
   136
sl@0
   137
sl@0
   138
sl@0
   139
my $buildTarget = 'winscw';	# At the moment the script only works for winscw
sl@0
   140
my $testSpec = "$ENV{SECURITYSOURCEDIR}\\testframework\\test\\autotesting\\test_spec.txt";
sl@0
   141
my $testResultsPath = "$resultsOutputDir\\TestResults_Summary.html";
sl@0
   142
############################ End of Input Reading Block ############################
sl@0
   143
 
sl@0
   144
sl@0
   145
use Text::ParseWords;
sl@0
   146
use File::Path 'rmtree';
sl@0
   147
sl@0
   148
# helper functions
sl@0
   149
sub ExecCmd;
sl@0
   150
sl@0
   151
#  helper functions taken from the TestUtilities.pm perl module
sl@0
   152
sub FullWin32Path;
sl@0
   153
sub FullPathToCDrive;
sl@0
   154
sub FullPathToZDrive;
sl@0
   155
sub DigestSecurityTestLog;
sl@0
   156
sub DigestTestExecuteTestLog;
sl@0
   157
sl@0
   158
# create/empty directory for epoc window output files
sl@0
   159
ExecCmd("rmdir /s /q $resultsOutputDir");
sl@0
   160
ExecCmd("mkdir $resultsOutputDir");
sl@0
   161
sl@0
   162
# set the location of epoc window output
sl@0
   163
my $tempDir=$ENV{'TMP'};
sl@0
   164
my $epocWndPath = $tempDir.'\epocwind.out';
sl@0
   165
sl@0
   166
ExecCmd('mkdir \epoc32\drive_d');
sl@0
   167
ExecCmd('mkdir \epoc32\drive_e');
sl@0
   168
ExecCmd('mkdir \epoc32\drive_r');
sl@0
   169
sl@0
   170
if (!grep(/PlatSecDisabledCaps SwEvent/, ReadFile('\epoc32\data\epoc.ini')))
sl@0
   171
	{
sl@0
   172
	# set up drives for emulator	
sl@0
   173
	ExecCmd('echo _epoc_drive_d \epoc32\drive_d >> \epoc32\data\epoc.ini');
sl@0
   174
	ExecCmd('echo _epoc_drive_e \epoc32\drive_e >> \epoc32\data\epoc.ini');
sl@0
   175
	ExecCmd('echo _epoc_drive_r \epoc32\drive_r >> \epoc32\data\epoc.ini');
sl@0
   176
sl@0
   177
	# disable the SwEvent to test SWI's handling of loader grantable capabilities
sl@0
   178
	ExecCmd('echo PlatSecDisabledCaps SwEvent >> \epoc32\data\epoc.ini');
sl@0
   179
sl@0
   180
	# turn off panic dialogs requiring user interaction
sl@0
   181
	ExecCmd('echo JustInTime none >> \epoc32\data\epoc.ini');
sl@0
   182
	}
sl@0
   183
sl@0
   184
# remove watchers
sl@0
   185
ExecCmd('del /Q /F /S \epoc32\release\wins\*watcher.dll');
sl@0
   186
ExecCmd('del /Q /F /S \epoc32\release\winscw\*watcher.dll');
sl@0
   187
sl@0
   188
# replace custom Java Installer with test version
sl@0
   189
my $cmiPath = "\\epoc32\\release\\$buildTarget\\$testedRelease";
sl@0
   190
if ( -f "$cmiPath\\custommidletinstall.dll" && -f "$cmiPath\\tcustommidletinstall.dll" )
sl@0
   191
{
sl@0
   192
    ExecCmd("ren $path\\custommidletinstall.dll custommidletinstall.std");
sl@0
   193
    ExecCmd("copy $path\\tcustommidletinstall.dll $path\\custommidletinstall.dll");
sl@0
   194
}
sl@0
   195
sl@0
   196
rmtree("$ENV{'EPOCROOT'}backup\\wins\\c");
sl@0
   197
rmtree("$ENV{'EPOCROOT'}backup\\winscw\\c");
sl@0
   198
rmtree("$ENV{'EPOCROOT'}backup\\drive_d");
sl@0
   199
rmtree("$ENV{'EPOCROOT'}backup\\drive_e");
sl@0
   200
sl@0
   201
# create backups of the current drive states
sl@0
   202
ExecCmd("xcopy /y/e/i/q $ENV{'EPOCROOT'}epoc32\\wins\\c $ENV{'EPOCROOT'}backup\\wins\\c");	
sl@0
   203
ExecCmd("xcopy /y/e/i/q $ENV{'EPOCROOT'}epoc32\\winscw\\c $ENV{'EPOCROOT'}backup\\winscw\\c");	
sl@0
   204
ExecCmd("xcopy /y/e/i/q $ENV{'EPOCROOT'}epoc32\\drive_d $ENV{'EPOCROOT'}backup\\drive_d");
sl@0
   205
ExecCmd("xcopy /y/e/i/q $ENV{'EPOCROOT'}epoc32\\drive_e $ENV{'EPOCROOT'}backup\\drive_e");
sl@0
   206
sl@0
   207
# clean the results folder
sl@0
   208
rmtree("$resultsOutputDir");
sl@0
   209
ExecCmd("mkdir $resultsOutputDir");
sl@0
   210
sl@0
   211
# open test result file
sl@0
   212
if (!open(TESTRESULTS, ">$testResultsPath"))
sl@0
   213
{
sl@0
   214
    die "Can't open output file $testResultsPath";
sl@0
   215
}
sl@0
   216
sl@0
   217
# create HTML header
sl@0
   218
print TESTRESULTS "<html>\n<head>\n<title>Title of page</title>\n</head>";
sl@0
   219
print TESTRESULTS "\n<body>\n<h2 align=\"center\">Test Results</h2>\n";
sl@0
   220
print TESTRESULTS "<p><b>target:</b> $buildTarget<br>\n";
sl@0
   221
print TESTRESULTS "<b>security sources:</b> $ENV{SECURITYSOURCEDIR}<br>\n";
sl@0
   222
print TESTRESULTS "<b>test spec:</b> $testSpec<br>\n";
sl@0
   223
print TESTRESULTS "<b>tested components:</b> @testedComponents</p>\n";
sl@0
   224
print TESTRESULTS "<table border=\"1\">\n<tr bgcolor=\"gray\"><th>#</th><th>Component</th><th>Release</th><th>Program</th><th>Script</th><th>Results</th><th>Log file</th><th>Epoc window</th></tr>";
sl@0
   225
sl@0
   226
# for the first component being tested there is no need to perform a restore on the drives, this variable is used to make this optimisation
sl@0
   227
my $firstTestedComponent = 1;
sl@0
   228
sl@0
   229
my $i = 0;
sl@0
   230
sl@0
   231
foreach my $testedRelease (@testedReleases)
sl@0
   232
{
sl@0
   233
	$logSuffix = '';
sl@0
   234
	if ($testedRelease eq 'urel')
sl@0
   235
	{
sl@0
   236
		$logSuffix = '1';	# so that the udeb results aren't overwritten by urel ones, matches ONB labelling
sl@0
   237
	}
sl@0
   238
sl@0
   239
	# open test spec file
sl@0
   240
	if (!open(TESTSPEC, "<$testSpec"))
sl@0
   241
	{
sl@0
   242
    	die "Can't open input file $testSpec";
sl@0
   243
	}
sl@0
   244
sl@0
   245
	# set current directory
sl@0
   246
	chdir("$ENV{'EPOCROOT'}epoc32\\release\\$buildTarget\\$testedRelease");
sl@0
   247
sl@0
   248
	# walk through the test spec file line-by-line and execute matching tests
sl@0
   249
	my $curComponent = '';
sl@0
   250
sl@0
   251
	my $testingCurrentComponent = 0;
sl@0
   252
sl@0
   253
	while (<TESTSPEC>)
sl@0
   254
	{
sl@0
   255
    	# skip comment lines
sl@0
   256
    	my $line = $_;
sl@0
   257
    	if ($line =~ /^\s*#/)
sl@0
   258
    	{  
sl@0
   259
        	next;
sl@0
   260
    	}
sl@0
   261
    
sl@0
   262
    	# set current component
sl@0
   263
    	if ($line =~ /^\s*\[\s*(\w+)\s*\]/) #find [component name] line
sl@0
   264
		{
sl@0
   265
			$curComponent = $1;
sl@0
   266
			print "\n[$curComponent]\n";
sl@0
   267
		
sl@0
   268
			# determine if we are testing this component.
sl@0
   269
			if (!grep(/^$curComponent$/i,@testedComponents)) 
sl@0
   270
			{
sl@0
   271
				$testingCurrentComponent = 0;
sl@0
   272
				next;
sl@0
   273
			}
sl@0
   274
		
sl@0
   275
			$testingCurrentComponent = 1;		
sl@0
   276
			# clean the system and mmc drives if necessary
sl@0
   277
			if ($firstTestedComponent)
sl@0
   278
			{
sl@0
   279
				$firstTestedComponent = 0;
sl@0
   280
			}
sl@0
   281
			else
sl@0
   282
			{
sl@0
   283
				ExecCmd("$ENV{SECURITYSOURCEDIR}\\testframework\\test\\autotesting\\restoredrivesstates.bat");	# For some reason when these commands are executed directly from Perl the call to xcopy to backup winscw\c causes xcopy to halt after copying one of the kanji SIS files, as a call to a batch file the commands work correctly.
sl@0
   284
			}
sl@0
   285
			# setup ethernet support on the emulator
sl@0
   286
			ExecCmd("$ENV{SECURITYSOURCEDIR}\\testframework\\test\\autotesting\\useautocfg.bat");
sl@0
   287
			next;
sl@0
   288
		}
sl@0
   289
    
sl@0
   290
    	# execute the test if we are testing this component
sl@0
   291
    	if ($testingCurrentComponent) 
sl@0
   292
    	{
sl@0
   293
    		my $program = '';
sl@0
   294
        	my $log = '';
sl@0
   295
        	my $commdb = '';
sl@0
   296
        	my $script = '';
sl@0
   297
        	my $timeout = '';
sl@0
   298
        	my $release = '';
sl@0
   299
        	my $preCommand = '';
sl@0
   300
        	my $postCommand = '';
sl@0
   301
        
sl@0
   302
                
sl@0
   303
        	# parse line from the test spec file
sl@0
   304
        	($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = quotewords(',', 1, $line);
sl@0
   305
        
sl@0
   306
sl@0
   307
        
sl@0
   308
        	$program =~ s/^\s*//;
sl@0
   309
        	$program =~ s/\s*$//;
sl@0
   310
        	$script =~ s/^\s*//;
sl@0
   311
        	$script =~ s/\s*$//;
sl@0
   312
        	$preCommand =~ s/^\s*//;
sl@0
   313
        	$preCommand =~ s/\s*$//;
sl@0
   314
        	$preCommand =~ s/%SECURITYSOURCEDIR%/$ENV{SECURITYSOURCEDIR}/;
sl@0
   315
        	$postCommand =~ s/^\s*//;
sl@0
   316
        	$postCommand =~ s/\s*$//;
sl@0
   317
        	$postCommand =~ s/%SECURITYSOURCEDIR%/$ENV{SECURITYSOURCEDIR}/;
sl@0
   318
        	$log =~ s/^\s*//;
sl@0
   319
        	$log =~ s/\s*$//;
sl@0
   320
sl@0
   321
        
sl@0
   322
       		# check release
sl@0
   323
        	if($release =! /$testedRelease/i)
sl@0
   324
        	{
sl@0
   325
            	next;
sl@0
   326
        	}
sl@0
   327
        	$i++;
sl@0
   328
     
sl@0
   329
        	# execute the pre-test command
sl@0
   330
        	if($preCommand ne "")
sl@0
   331
        	{
sl@0
   332
            	ExecCmd($preCommand);
sl@0
   333
        	}
sl@0
   334
        
sl@0
   335
        	# execute the test command
sl@0
   336
        	ExecCmd("$ExecTimeOut \"$program $script\" $timeout");
sl@0
   337
        	print "\n\nExecution of $program $script";
sl@0
   338
sl@0
   339
       
sl@0
   340
        	# store test results and epoc window output files    
sl@0
   341
        	my $bEpocWnd = 0;
sl@0
   342
    
sl@0
   343
    		$trimmedLog = $log;
sl@0
   344
    		$trimmedLog =~ s/\\.*\\//;	# perl does greedy pattern matching so strips off all directories in the path of the form \....\....\
sl@0
   345
			$trimmedLog =~ s/.*\\//;	# in case the path is relative strip of the leading directory
sl@0
   346
			$trimmedLog =~ /(.*)\.([^\.]*)/;	# extract the filename and the extension
sl@0
   347
sl@0
   348
      		$epocwindName = $1 . $logSuffix . "_epocwind.txt";
sl@0
   349
      		$targetLogName = $1 . $logSuffix. "\." . $2;
sl@0
   350
      	
sl@0
   351
        	ExecCmd("copy $epocWndPath $resultsOutputDir\\$epocwindName");
sl@0
   352
        	ExecCmd("del $epocWndPath");
sl@0
   353
        	$bEpocWnd = 1;
sl@0
   354
     
sl@0
   355
        
sl@0
   356
        	# process log files
sl@0
   357
        	my $sText = "";
sl@0
   358
        	my $iPass = 0;
sl@0
   359
        	my $iFail = 0;
sl@0
   360
        	my $iPass_case = 0;	# not used
sl@0
   361
        	my $iFail_case = 0;	# not used
sl@0
   362
        	my $bLogFile = 0;
sl@0
   363
        	my $logPath = FullWin32Path($buildTarget, $release, $log);
sl@0
   364
        	if (-f $logPath)
sl@0
   365
        	{
sl@0
   366
            	$bLogFile = 1;
sl@0
   367
            	ExecCmd("copy $logPath $resultsOutputDir\\$targetLogName");
sl@0
   368
    			# Test Execute
sl@0
   369
    			if ($sText eq "")
sl@0
   370
    			{
sl@0
   371
    				($sText, $iPass, $iFail, $iPass_case, $iFail_case) = DigestTestExecuteTestLog($logPath);
sl@0
   372
    			}
sl@0
   373
    	
sl@0
   374
    			# Security Test Logs
sl@0
   375
    			if ($sText eq "" )
sl@0
   376
    			{
sl@0
   377
    				# Check to see if this is an Security RTest test log
sl@0
   378
    				($sText, $iPass, $iFail) = DigestSecurityTestLog($logPath);
sl@0
   379
    			}
sl@0
   380
        
sl@0
   381
            	# get rid of surrounding html tags
sl@0
   382
            	if ($sText)
sl@0
   383
            	{
sl@0
   384
                	if ($sText =~ /<td.*>(.+)<\/td>/)
sl@0
   385
                	{
sl@0
   386
                    	$sText = $1;
sl@0
   387
                	}
sl@0
   388
            	}
sl@0
   389
        	}
sl@0
   390
        
sl@0
   391
        	# generate HTML results
sl@0
   392
        	my $htmlEpocWnd = "<a href=\"$resultsOutputDir\\$epocwindName\">here</a>";
sl@0
   393
        	if(!$bEpocWnd)
sl@0
   394
        	{
sl@0
   395
            	$htmlEpocWnd = "not found";
sl@0
   396
        	}
sl@0
   397
        	my $htmlColor = "white";
sl@0
   398
        	my $htmlLog = "<a href=\"$resultsOutputDir\\$targetLogName\">$log</a>";
sl@0
   399
        
sl@0
   400
        	if($bLogFile)
sl@0
   401
        	{
sl@0
   402
            	if ($sText eq "" )
sl@0
   403
            	{
sl@0
   404
                	$htmlColor = 'blue';
sl@0
   405
                	$sText = 'log file not parsed';
sl@0
   406
            	}
sl@0
   407
            	elsif(!$iPass or $iFail)
sl@0
   408
            	{
sl@0
   409
                	$htmlColor = "red";
sl@0
   410
            	}
sl@0
   411
        	}
sl@0
   412
        	else
sl@0
   413
        	{
sl@0
   414
            	$htmlColor = 'yellow';
sl@0
   415
            	$sText = 'log file not found';
sl@0
   416
            	$htmlLog = '';
sl@0
   417
        	}
sl@0
   418
           
sl@0
   419
        	print TESTRESULTS "\n<tr bgcolor=\"$htmlColor\">";
sl@0
   420
        	print TESTRESULTS "<td>$i</td><td>$curComponent</td><td>$testedRelease</td><td>$program</td><td>$script</td>";
sl@0
   421
        	print TESTRESULTS "<td>$sText</td><td>$htmlLog</td><td>$htmlEpocWnd</td></tr>";
sl@0
   422
sl@0
   423
        	print "\nResults: $sText";
sl@0
   424
        
sl@0
   425
        	# execute the post-test command
sl@0
   426
        	if($postCommand ne "")
sl@0
   427
        	{
sl@0
   428
        	    ExecCmd($postCommand);
sl@0
   429
        	}
sl@0
   430
    	}
sl@0
   431
	}
sl@0
   432
	close TESTSPEC;
sl@0
   433
}
sl@0
   434
sl@0
   435
# restore the drives' states
sl@0
   436
if (!$skipCleanAfterFinalComponent)
sl@0
   437
{
sl@0
   438
	ExecCmd("$ENV{SECURITYSOURCEDIR}\\testframework\\test\\autotesting\\restoredrivesstates.bat");
sl@0
   439
}	
sl@0
   440
sl@0
   441
# final html stuff
sl@0
   442
print TESTRESULTS "\n</table></body></html>";
sl@0
   443
sl@0
   444
close TESTRESULTS;
sl@0
   445
sl@0
   446
if (!$suppressBrowserPopup)
sl@0
   447
{
sl@0
   448
	# open test results in browser, this will halt script execution until the browser is closed
sl@0
   449
	`$testResultsPath`;
sl@0
   450
}	
sl@0
   451
sl@0
   452
######################################################################################
sl@0
   453
#  helper functions
sl@0
   454
######################################################################################
sl@0
   455
sub ExecCmd
sl@0
   456
{
sl@0
   457
	my $cmd = $_[0];
sl@0
   458
    print "\n".`$cmd`;
sl@0
   459
}
sl@0
   460
sl@0
   461
sub DisplayHelp {
sl@0
   462
	print "\n\n\nHELP DIALOG:";
sl@0
   463
	print "\nThe following arguments are required:\n\n";
sl@0
   464
	print "-components: A comma separated (no spaces) list of component names.\n\n";
sl@0
   465
	print "-testreleases: A comma separated (no spaces) list of the releases tested.\n\n";
sl@0
   466
	print "-exectimeout: The path location of ExecTimeOut.exe relative to this drive.  This is downloaded via Perforce from //PR/share/DABSRelease/buildscripts/ExecTimeOut.exe.\n\n";
sl@0
   467
	print "-resultsoutput: Directory used to store the test results and epocwind.out files from running the tests.  Current contents will be deleted.  Use a value of \\logs\\winscw if you want it to be compatible with the panicscan test.\n\n";
sl@0
   468
	print "-skipfinalclean: The script will restore the drives to their original state after each component has been tested.  If you do not want the drives to be restored after the final component has been tested (typically used when debugging just one component's tests) then add this flag and before re-running the tests manually restore the drives from the contents of the \\backup\\ folder.\n\n";
sl@0
   469
	print "-suppressbrowser: Add this flag to prevent the halting of execution and presentation of the results in a browser window after the tests have been run.";
sl@0
   470
	print "Example usage:\n";
sl@0
   471
	print "test_launcher.pl -components caf2,streamingcaf,swi -testreleases udeb,urel -exectimeout \\ExecTimeOut.exe resultsoutput \\logs\\winscw -skipfinalclean -suppressbrowser\n\n";
sl@0
   472
	die;
sl@0
   473
}
sl@0
   474
sl@0
   475
######################################################################################
sl@0
   476
# helper functions taken from the TestUtilities.pm perl module
sl@0
   477
######################################################################################
sl@0
   478
sl@0
   479
sub DigestTestExecuteTestLog
sl@0
   480
# Arg: [0] output log from a TestExecute run
sl@0
   481
# Returns: small HTML summary string of the run
sl@0
   482
{
sl@0
   483
	my $filename = $_[0];
sl@0
   484
	my $TestConfirmed = $_[1];
sl@0
   485
	my $sHTML = "";
sl@0
   486
 
sl@0
   487
	$filename =~ s/\s+$//;
sl@0
   488
	return "" unless( -f $filename and open( TEST, $filename )); 
sl@0
   489
sl@0
   490
	$/ = "\n";
sl@0
   491
sl@0
   492
	my $iFail = 0;
sl@0
   493
	my $iPass = 0;
sl@0
   494
	my $iCheck = 0;
sl@0
   495
	my $bTestExecute = 0;
sl@0
   496
	my $TEST_STEP_SECTION = 0;
sl@0
   497
	my $iFail_case = 0;
sl@0
   498
	my $iPass_case = 0;
sl@0
   499
	my $iCheck_case = 0;
sl@0
   500
	my $TEST_CASE_SECTION = 0;
sl@0
   501
	
sl@0
   502
sl@0
   503
	while( <TEST> )
sl@0
   504
	{
sl@0
   505
		chomp;
sl@0
   506
		my $sLine = $_;
sl@0
   507
		if ( $sLine =~ /TEST STEP SUMMARY:<\/font>/i) 
sl@0
   508
		{
sl@0
   509
			$TEST_STEP_SECTION = 1;
sl@0
   510
			$TEST_CASE_SECTION = 0;
sl@0
   511
		}
sl@0
   512
		elsif ( $sLine =~ /RUN PROGRAM SUMMARY:<\/font>/i) 
sl@0
   513
		{
sl@0
   514
			$TEST_STEP_SECTION = 0;
sl@0
   515
		}
sl@0
   516
	        elsif( $sLine =~ /TEST CASE SUMMARY:<\/font>/i)
sl@0
   517
		{
sl@0
   518
			$TEST_CASE_SECTION = 1;
sl@0
   519
			$TEST_STEP_SECTION = 0;
sl@0
   520
		}		
sl@0
   521
		elsif ( $sLine =~ /SUMMARY:<\/font>/i ) # To Keep Last
sl@0
   522
		{
sl@0
   523
			$TEST_STEP_SECTION = 1;
sl@0
   524
		}
sl@0
   525
		if ( $TEST_STEP_SECTION )
sl@0
   526
		{
sl@0
   527
			$iPass += $1 if( $sLine =~ /<font.*color=00AF00> PASS = (\d+)<\/font>/i);
sl@0
   528
			$iPass += $1 if( $sLine =~ /<font.*color=00AF00>PASS = (\d+)<\/font>/i);
sl@0
   529
		
sl@0
   530
			$iFail += $1 if( $sLine =~ /<font.*color=FF0000>FAIL = (\d+)<\/font>/i);
sl@0
   531
			$iFail += $1 if( $sLine =~ /<font.*color=0000FF>ABORT = (\d+)<\/font>/i);
sl@0
   532
			$iFail += $1 if( $sLine =~ /<font.*color=0000FF>PANIC = (\d+)<\/font>/i);
sl@0
   533
			$iFail += $1 if( $sLine =~ /<font.*color=0000FF>INCONCLUSIVE = (\d+)<\/font>/i);
sl@0
   534
			$iFail += $1 if( $sLine =~ /<font.*color=0000FF>UNKNOWN = (\d+)<\/font>/i);
sl@0
   535
			$iFail += $1 if( $sLine =~ /<font.*color=0000FF>UNEXECUTED = (\d+)<\/font>/i);
sl@0
   536
		}
sl@0
   537
		if ( $TEST_CASE_SECTION )
sl@0
   538
		{
sl@0
   539
sl@0
   540
			$iPass_case += $1 if( $sLine =~ /<font.*color=00AF00> PASS = (\d+)<\/font>/i);
sl@0
   541
			$iPass_case += $1 if( $sLine =~ /<font.*color=00AF00>PASS = (\d+)<\/font>/i);
sl@0
   542
			$iFail_case += $1 if( $sLine =~ /<font.*color=FF0000>FAIL = (\d+)<\/font>/i);
sl@0
   543
			$iFail_case += $1 if( $sLine =~ /<font.*color=0000FF>ABORT = (\d+)<\/font>/i);
sl@0
   544
			$iFail_case += $1 if( $sLine =~ /<font.*color=0000FF>PANIC = (\d+)<\/font>/i);
sl@0
   545
			$iFail_case += $1 if( $sLine =~ /<font.*color=0000FF>INCONCLUSIVE = (\d+)<\/font>/i);
sl@0
   546
			$iFail_case += $1 if( $sLine =~ /<font.*color=0000FF>UNKNOWN = (\d+)<\/font>/i);
sl@0
   547
			$iFail_case += $1 if( $sLine =~ /<font.*color=0000FF>UNEXECUTED = (\d+)<\/font>/i);
sl@0
   548
			
sl@0
   549
		}
sl@0
   550
		$bTestExecute = 1 if( $sLine =~ /\*\*\*\s+TestExecute\s+Started/i);
sl@0
   551
sl@0
   552
	}
sl@0
   553
	close( TEST );
sl@0
   554
	
sl@0
   555
	if( $bTestExecute )
sl@0
   556
	{
sl@0
   557
		if(( $iPass == 0 and $iFail == 0) and ($TestConfirmed == 1))
sl@0
   558
		{
sl@0
   559
			$sHTML = "<td>$iPass passed, $iFail failed</td>";
sl@0
   560
		}
sl@0
   561
		elsif ( $iPass == 0 and $iFail == 0)
sl@0
   562
		{
sl@0
   563
			$sHTML = "<td $sFailedBGColor>test crashed</td>";
sl@0
   564
		}
sl@0
   565
		elsif( $iFail > 0 )
sl@0
   566
		{
sl@0
   567
			$sHTML = "<td $sFailedBGColor>$iPass passed, $iFail failed</td>";
sl@0
   568
		}
sl@0
   569
		else
sl@0
   570
		{
sl@0
   571
			$sHTML = "<td>$iPass passed, $iFail failed</td>";
sl@0
   572
		}
sl@0
   573
	}
sl@0
   574
	elsif( $iPass > 0 or $iFail > 0 )
sl@0
   575
	{
sl@0
   576
		#
sl@0
   577
		# Almost certainly a TEF log, but missing the "TestExecute Started" line.
sl@0
   578
		# Possibly because of a loss of part of the log from the hardware.
sl@0
   579
		#
sl@0
   580
		if( $iFail > 0 )
sl@0
   581
		{
sl@0
   582
			$sHTML = "<td $sFailedBGColor>$iPass passed, $iFail failed</td>";
sl@0
   583
		}
sl@0
   584
		else
sl@0
   585
		{
sl@0
   586
			$sHTML = "<td  $sWarningBCColor>$iPass passed, $iFail failed</td>";
sl@0
   587
		}
sl@0
   588
	}
sl@0
   589
	 	 
sl@0
   590
	return ($sHTML, $iPass, $iFail, $iPass_case, $iFail_case);
sl@0
   591
}
sl@0
   592
sl@0
   593
sl@0
   594
sub DigestSecurityTestLog
sl@0
   595
# Arg: [0] output log from an automated testcase run
sl@0
   596
# Returns: small HTML summary string of the run indicating test result extracted from log.
sl@0
   597
{	
sl@0
   598
	my $filename = $_[0];
sl@0
   599
sl@0
   600
	my $sHTML = "";
sl@0
   601
 
sl@0
   602
	my $sCmd = "type $filename |";
sl@0
   603
	$filename =~ s/\s+$//;
sl@0
   604
	return "" unless( -f $filename and open( TEST, $sCmd )); 
sl@0
   605
sl@0
   606
	$/ = "\n";
sl@0
   607
sl@0
   608
	# For these tests the result x tests failed out of y is displayed in the 2nd last line of the log file. 
sl@0
   609
    
sl@0
   610
	my $iFail = 0;
sl@0
   611
	my $iPass = 0;
sl@0
   612
	my $iTotal = 0;
sl@0
   613
sl@0
   614
	while( <TEST> )
sl@0
   615
	{
sl@0
   616
		chomp;
sl@0
   617
		my $sLine = $_;
sl@0
   618
		my $null = chr(0);
sl@0
   619
		$sLine =~ s/$null|\s//g;
sl@0
   620
		if( $sLine =~ /(\d+)testsfailedoutof(\d+)/i )
sl@0
   621
		{
sl@0
   622
			$iFail += $1;
sl@0
   623
			$iTotal += $2;
sl@0
   624
		}
sl@0
   625
	}
sl@0
   626
	close( TEST );
sl@0
   627
	
sl@0
   628
	if( $iTotal > 0 )
sl@0
   629
	{
sl@0
   630
		$sHTML = "<td>";
sl@0
   631
		$sHTML = "<td $sFailedBGColor>" if( $iFail > 0 );
sl@0
   632
sl@0
   633
		$iPass = $iTotal - $iFail;
sl@0
   634
		$sHTML .= "$iPass passed, $iFail failed</td>";
sl@0
   635
	}
sl@0
   636
	 	 
sl@0
   637
	return ($sHTML, $iPass, $iFail);
sl@0
   638
}
sl@0
   639
sl@0
   640
######################################################################################
sl@0
   641
# helper functions taken from the BuildSpecifications.pm perl module
sl@0
   642
######################################################################################
sl@0
   643
sl@0
   644
# Read the contents of a file into a string and return it
sl@0
   645
sub ReadFile ($)
sl@0
   646
{
sl@0
   647
	my ($file) = @_;
sl@0
   648
	open FILE, "<$file" or LogDie("Can't read file: $file", @StdLogs);
sl@0
   649
	local $/ = undef;
sl@0
   650
	my $data = <FILE>;
sl@0
   651
	close FILE;
sl@0
   652
	return $data;
sl@0
   653
}
sl@0
   654
sl@0
   655
sl@0
   656
###########################################################################
sl@0
   657
# Return Path to z Drive
sl@0
   658
# Arguments: [0] Build Target (e.g. arm4, wins, etc)
sl@0
   659
#            [1] Build Release (Optional) (e.g. UDEB/UREL)
sl@0
   660
# Returns Correspoonding Effective Z Drive
sl@0
   661
sub FullPathToZDrive
sl@0
   662
{
sl@0
   663
	my ($buildTarget, $buildRelease) = @_;
sl@0
   664
	$buildRelease="UDEB" unless( $buildRelease );
sl@0
   665
sl@0
   666
	return "$ENV{'EPOCROOT'}epoc32\\release\\$buildTarget\\$buildRelease\\z" if( $buildTarget =~ /wins/i );
sl@0
   667
	return "$ENV{'EPOCROOT'}epoc32\\data\\z";
sl@0
   668
}
sl@0
   669
sl@0
   670
sl@0
   671
###########################################################################
sl@0
   672
# Return Path to C Drive
sl@0
   673
# Arguments: [0] Build Target (e.g. arm4, wins, etc)
sl@0
   674
# Returns Correspoonding Effective C Drive
sl@0
   675
sub FullPathToCDrive
sl@0
   676
{
sl@0
   677
	my ($buildTarget) = @_;
sl@0
   678
sl@0
   679
	return "$ENV{'EPOCROOT'}epoc32\\$buildTarget\\c" if( $buildTarget =~ /wins/i );
sl@0
   680
	return "$ENV{'EPOCROOT'}epoc32\\data\\z";
sl@0
   681
}
sl@0
   682
sl@0
   683
sl@0
   684
###########################################################################
sl@0
   685
# EPOC paths can be drive-relative ("\scripts\bob") or absolute ("c:\scripts\bob"). 
sl@0
   686
# Return an appropriate Win32 path, where - an additional complication
sl@0
   687
# is that the EPOC c: and z: aren't sibling Win32 paths
sl@0
   688
# Arguments: [0] Build Target (e.g. arm4, wins, etc)
sl@0
   689
#            [1] Build Release (Optional) (e.g. UDEB/UREL)
sl@0
   690
#            [2] EPOC path
sl@0
   691
# Returns: full Win32 path
sl@0
   692
sub FullWin32Path
sl@0
   693
{
sl@0
   694
	my ($buildTarget, $buildRelease, $sPath) = @_;
sl@0
   695
sl@0
   696
	$sPath =~ s/^\s+//;
sl@0
   697
	if($sPath =~ /^(\w):(.*)/)
sl@0
   698
	{
sl@0
   699
		my $sDrive = uc($1);
sl@0
   700
		my $sDir = $2;
sl@0
   701
		$sDir =~ s/^\\//;
sl@0
   702
		if($sDrive eq "C")
sl@0
   703
		{
sl@0
   704
			return FullPathToCDrive($buildTarget) . "\\$sDir";
sl@0
   705
		}
sl@0
   706
		elsif($sDrive eq "Z")
sl@0
   707
		{
sl@0
   708
			return FullPathToZDrive($buildTarget,$buildRelease) . "\\$sDir";
sl@0
   709
		}
sl@0
   710
		else
sl@0
   711
		{
sl@0
   712
			# Maybe an actual pathname
sl@0
   713
			return $sPath;
sl@0
   714
		}
sl@0
   715
	}
sl@0
   716
	
sl@0
   717
	# Presumption is that path is relative to EPOC C:\
sl@0
   718
	$sPath =~ s/^\\//;
sl@0
   719
	return FullPathToCDrive($buildTarget) . "\\$sPath";
sl@0
   720
}