os/graphics/windowing/windowserver/group/runtest.pl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
# All rights reserved.
sl@0
     3
# This component and the accompanying materials are made available
sl@0
     4
# under the terms of "Eclipse Public License v1.0"
sl@0
     5
# which accompanies this distribution, and is available
sl@0
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
#
sl@0
     8
# Initial Contributors:
sl@0
     9
# Nokia Corporation - initial contribution.
sl@0
    10
#
sl@0
    11
# Contributors:
sl@0
    12
#
sl@0
    13
# Description:
sl@0
    14
#
sl@0
    15
sl@0
    16
use File::Copy;
sl@0
    17
use File::Path;
sl@0
    18
use FindBin;
sl@0
    19
use lib $FindBin::Bin;
sl@0
    20
use Win32::Process; 
sl@0
    21
use Win32; 
sl@0
    22
use Win32::Job;
sl@0
    23
sl@0
    24
my $platform = "winscw";
sl@0
    25
my $screens = 2;
sl@0
    26
sl@0
    27
# ------------------------------------------------------------------------------------------------------------------------------------- #
sl@0
    28
#             log-id				wins/winscw	executable	test-context					wsini selection					#of screens #
sl@0
    29
# ------------------------------------------------------------------------------------------------------------------------------------- #
sl@0
    30
&RunWservTest("normal",				$platform, "auto", 		"autou.cfg", 					"wservu.ini",					$screens);
sl@0
    31
&RunWservTest("sparse", 			$platform, "auto", 		"autou_sparse.cfg", 			"wservu_sparse.ini",			$screens);
sl@0
    32
&RunWservTest("sparse_nodefault", 	$platform, "auto", 		"autou_sparse_nodefault.cfg",	"wservu_sparse_nodefault.ini",	$screens);
sl@0
    33
exit;
sl@0
    34
sl@0
    35
sub RunWservTest()
sl@0
    36
{
sl@0
    37
  my $session = shift;
sl@0
    38
  my $plat = shift;
sl@0
    39
  my $exe = shift;
sl@0
    40
  my $cfg = shift;
sl@0
    41
  my $wservu = shift;
sl@0
    42
  my $nScreens = shift;
sl@0
    43
  
sl@0
    44
  my $epocDir = "\\epoc32\\release\\$plat\\udeb\\";
sl@0
    45
  my $epocEmulator = $epocDir."epoc.exe";
sl@0
    46
sl@0
    47
  my $wsini = $epocDir."z\\system\\data\\wsini.ini";
sl@0
    48
  my $wsiniBackup = $wsini.".bak";
sl@0
    49
  
sl@0
    50
  my $epocFile = "\\epoc32\\data\\epoc.ini";
sl@0
    51
  my $epocBackup = $epocFile.".bak";
sl@0
    52
sl@0
    53
  # backup original epoc.ini and wsini.ini	
sl@0
    54
  &DoCopy($epocFile, $epocBackup) if (!-f $epocBackup);
sl@0
    55
  &DoCopy($wsini, $wsiniBackup) if (!-f $wsiniBackup);
sl@0
    56
sl@0
    57
  print "Mnt install\n";
sl@0
    58
  my $wservDir = ".";
sl@0
    59
  &StartMntCommand($wservDir, $plat, $wservu, $cfg);
sl@0
    60
sl@0
    61
  $exeFile = $epocDir.$exe.".exe";
sl@0
    62
  if (-f $exeFile)
sl@0
    63
  {
sl@0
    64
	$epocEmulator = $exeFile;
sl@0
    65
  }
sl@0
    66
  else
sl@0
    67
  {
sl@0
    68
	&AddShellCmd($wsini, $exe);
sl@0
    69
  }
sl@0
    70
sl@0
    71
  if ($nScreens > 1)
sl@0
    72
  {
sl@0
    73
	&CreateEpocMultiScreen($epocFile, $wsini, $nScreens);
sl@0
    74
  }
sl@0
    75
  
sl@0
    76
  my $job = Win32::Job->new;
sl@0
    77
  if (!$job) { &ErrorReport(); next; }
sl@0
    78
sl@0
    79
  print "Running wserv test $session...";
sl@0
    80
  my $spawned = $job->spawn($epocEmulator, 'epoc.exe');
sl@0
    81
  if (!$spawned) { &ErrorReport(); next; }
sl@0
    82
sl@0
    83
  my $timeout = 45;
sl@0
    84
  my $ok = $job->run($timeout * 60); 
sl@0
    85
  warn "WARNING: Process \"$epocEmulator\" killed due to timeout.\n" if (!$ok);
sl@0
    86
	
sl@0
    87
  print "done\n";
sl@0
    88
  
sl@0
    89
  # save wserv.log
sl@0
    90
  my $logDir = "\\epoc32\\$plat\\c\\data\\";
sl@0
    91
  my $wservLog = $logDir."wserv.log";
sl@0
    92
  my $logBackup = $logDir."wserv_$session.log";
sl@0
    93
  &DoCopy($wservLog, $logBackup);
sl@0
    94
  
sl@0
    95
  
sl@0
    96
  # restore original epoc.ini and wsini.ini
sl@0
    97
  &DoCopy($wsiniBackup, $wsini);
sl@0
    98
  &DoCopy($epocBackup, $epocFile);
sl@0
    99
  
sl@0
   100
  # remove auto.cfg
sl@0
   101
  system("del /f /q \\epoc32\\release\\$plat\\udeb\\z\\system\\data\\auto.cfg");
sl@0
   102
}
sl@0
   103
sl@0
   104
sub StartMntCommand()
sl@0
   105
{
sl@0
   106
  my $wservDir = shift;
sl@0
   107
  my $plat = shift;
sl@0
   108
  my $wservu = shift;
sl@0
   109
  my $autou = shift;
sl@0
   110
sl@0
   111
  &DoCopy("$wservDir\\..\\group\\system.ini", "\\epoc32\\data\\");
sl@0
   112
  &MntDoInstall($wservDir, $plat, 'udeb', $wservu, $autou);
sl@0
   113
  &MntDoInstall($wservDir, $plat, 'urel', $wservu, $autou);
sl@0
   114
}
sl@0
   115
sl@0
   116
sub MntDoInstall()
sl@0
   117
{
sl@0
   118
  my $wservDir = shift;
sl@0
   119
  my $plat = shift;
sl@0
   120
  my $UrelUdeb = shift;
sl@0
   121
  my $whatFile = shift;
sl@0
   122
  my $autoCfg = shift;
sl@0
   123
sl@0
   124
  my $dataDir   = "\\epoc32\\release\\$plat\\$UrelUdeb\\z\\system\\data\\";
sl@0
   125
  mkpath($dataDir);
sl@0
   126
  &DoCopy("$wservDir\\..\\group\\$whatFile",    $dataDir.'wsini.ini');
sl@0
   127
  &DoCopy("$wservDir\\..\\group\\$autoCfg",     $dataDir.'auto.cfg');  
sl@0
   128
}
sl@0
   129
sl@0
   130
sub AddShellCmd
sl@0
   131
{
sl@0
   132
  my $file = shift;
sl@0
   133
  my $cmd = shift;
sl@0
   134
sl@0
   135
  my $string = &ascii_to_utf16("SHELLCMD $cmd");
sl@0
   136
sl@0
   137
  &Write_UTF16_Newline($file);
sl@0
   138
sl@0
   139
  open(FILE, ">>$file") or warn "WARNING: Could not open file: $!\n";
sl@0
   140
  print FILE $string;
sl@0
   141
  close FILE;
sl@0
   142
sl@0
   143
  &Write_UTF16_Newline($file);
sl@0
   144
}
sl@0
   145
sl@0
   146
sub Write_UTF16_Newline
sl@0
   147
{
sl@0
   148
  my $file = shift;
sl@0
   149
sl@0
   150
  open(BIN, ">>$file") or warn "WARNING: Could not open \"$file\": $!\n";
sl@0
   151
  binmode BIN;
sl@0
   152
  sysseek BIN, 0, SEEK_END;
sl@0
   153
  syswrite BIN, "\x0D\x00\x0A\x00" or warn "WARNING: Could not write to file\n";
sl@0
   154
  close BIN;
sl@0
   155
}
sl@0
   156
sl@0
   157
# Function that accepts an ASCII string and returns the same string in UTF16
sl@0
   158
sub ascii_to_utf16 {
sl@0
   159
  my $utf16_string = "";
sl@0
   160
  my $ascii_string = shift;
sl@0
   161
  my $lengthofstring = length($ascii_string);
sl@0
   162
sl@0
   163
  for (my $count=1; $count<=$lengthofstring; $count++)
sl@0
   164
  {
sl@0
   165
    my $char = substr($ascii_string,$count-1,1);
sl@0
   166
    $utf16_string .= $char;
sl@0
   167
    $utf16_string .= "\x00";
sl@0
   168
  }
sl@0
   169
sl@0
   170
  return $utf16_string;
sl@0
   171
}
sl@0
   172
sl@0
   173
sub	ProduceWServResult()
sl@0
   174
{
sl@0
   175
	$plat = shift;
sl@0
   176
	$subDir = shift;
sl@0
   177
	$handleFileTable = shift;	
sl@0
   178
  $wservTestResStatistic = shift;
sl@0
   179
sl@0
   180
  $background = 0;
sl@0
   181
sl@0
   182
  $wservTestResStatistic = "";
sl@0
   183
  $duration = "";
sl@0
   184
  
sl@0
   185
	my $result = "PASS";
sl@0
   186
sl@0
   187
  open TEMPLOGFILE, ">>\\work.txt";
sl@0
   188
  print TEMPLOGFILE "Start ProduceWServResult: plat $plat,subDir $subDir,handleFileTable $handleFileTable,background $background\n";
sl@0
   189
  close TEMPLOGFILE;
sl@0
   190
sl@0
   191
	$logFile = "$ENV{EPOCROOT}epoc32\\$plat\\c\\data\\WSERV.LOG";
sl@0
   192
sl@0
   193
  open LOGFILEWSERV, "$logFile" or $logWSFileRes = -1;
sl@0
   194
  $CurWinServTestNumber = 0;
sl@0
   195
  $CurWinServTestName = "";
sl@0
   196
  $wservTestDuration = 0;
sl@0
   197
  $wservFullTestDuration = 0;
sl@0
   198
sl@0
   199
	print "result ws : $logWSFileRes\n";
sl@0
   200
sl@0
   201
  $fileLogWServDest = "$subDir\\1_wserv.htm";
sl@0
   202
  open FILELOGDEST, ">$fileLogWServDest";#	or die "Can't open file: $fileLogWServDest! \n";
sl@0
   203
  print FILELOGDEST  "<pre>";
sl@0
   204
sl@0
   205
  while($_ = <LOGFILEWSERV>)
sl@0
   206
	{
sl@0
   207
    if(/\s(\d+\.\d\d\d)/)
sl@0
   208
    {
sl@0
   209
      $wservTestDuration = $1;
sl@0
   210
    }
sl@0
   211
    else
sl@0
   212
    {
sl@0
   213
      $wservTestDuration = 0;
sl@0
   214
    }
sl@0
   215
    $wservFullTestDuration +=  $wservTestDuration;
sl@0
   216
sl@0
   217
    if(/AUTO New Test: /)
sl@0
   218
		{
sl@0
   219
      $wservFullTestDuration = $wservTestDuration;
sl@0
   220
sl@0
   221
      if($CurWinServTestNumber != 0) #previos test was inconclusive
sl@0
   222
      {
sl@0
   223
        $Inconclusive++;
sl@0
   224
        $result = "INCONCLUSIVE";
sl@0
   225
        OutputWServerTestResultToTable(FILERES, $background, $result,
sl@0
   226
           $CurWinServTestName, $fileLogWServDest, $wservFullTestDuration);
sl@0
   227
        $background = !$background;
sl@0
   228
        print FILELOGDEST  "</pre>";
sl@0
   229
        close FILELOGDEST;
sl@0
   230
      }
sl@0
   231
sl@0
   232
      if(/Test (\d+),(.+\w)(\s+\d\.)/)
sl@0
   233
      {
sl@0
   234
        $CurWinServTestNumber = $1;
sl@0
   235
        $CurWinServTestName = $2;
sl@0
   236
      }
sl@0
   237
      else
sl@0
   238
      {
sl@0
   239
        /Test (\d+),(.+)/;
sl@0
   240
        $CurWinServTestNumber = $1;
sl@0
   241
        $CurWinServTestName = $2;
sl@0
   242
      }
sl@0
   243
sl@0
   244
sl@0
   245
      if($CurWinServTestNumber > 1)
sl@0
   246
      {
sl@0
   247
          $fileLogWServDest = "$subDir\\$CurWinServTestNumber" . "_wserv.htm";
sl@0
   248
          open FILELOGDEST, ">$fileLogWServDest";#	or die "Can't open file: $fileLogWServDest! \n";
sl@0
   249
          print FILELOGDEST  "<pre>";
sl@0
   250
      }
sl@0
   251
    }
sl@0
   252
    elsif(/AUTO TEST RESULT: /)
sl@0
   253
		{
sl@0
   254
      $CurWinServTestNumber = 0;
sl@0
   255
sl@0
   256
      /AUTO TEST RESULT: (\w+)/;
sl@0
   257
      $TestResult = $1;
sl@0
   258
      if($TestResult eq "PASS")
sl@0
   259
      {
sl@0
   260
        $col = "#008000";
sl@0
   261
        $result = $TestResult;
sl@0
   262
        $Pass++;
sl@0
   263
      }
sl@0
   264
      elsif($TestResult eq "FAIL")
sl@0
   265
      {
sl@0
   266
        $col = "#ff0000";
sl@0
   267
        $result = $TestResult;
sl@0
   268
        $Failed++;
sl@0
   269
      }
sl@0
   270
      else
sl@0
   271
      {
sl@0
   272
        $col = "#0000ff";
sl@0
   273
        $Unknown++;
sl@0
   274
        $result = "N/A";
sl@0
   275
      }
sl@0
   276
      
sl@0
   277
      if($wservFullTestDuration =~ /(\d+\.\d{0,3})/)
sl@0
   278
      {
sl@0
   279
        $wservFullTestDuration = $1;
sl@0
   280
      }
sl@0
   281
sl@0
   282
      #output result to the file
sl@0
   283
      OutputWServerTestResultToTable(FILERES, $background, $result,
sl@0
   284
          $CurWinServTestName, $fileLogWServDest, $wservFullTestDuration);
sl@0
   285
      $background = !$background;
sl@0
   286
      print FILELOGDEST "<FONT COLOR=\"$col\">$_</FONT><br>";
sl@0
   287
sl@0
   288
      print FILELOGDEST  "</pre>";
sl@0
   289
      close FILELOGDEST;
sl@0
   290
		}
sl@0
   291
    if(/AUTO Testing Complete, (.*)(\d+\.\d{0,3})/)
sl@0
   292
    {
sl@0
   293
      $wservTestResStatistic = $1;
sl@0
   294
    }
sl@0
   295
sl@0
   296
    if(/AUTO Failed /)
sl@0
   297
    {
sl@0
   298
       print FILELOGDEST "<FONT COLOR=\"#ff0000\">$_</FONT><br>";
sl@0
   299
    }
sl@0
   300
    else
sl@0
   301
    {
sl@0
   302
        print FILELOGDEST "$_<br>";
sl@0
   303
    }
sl@0
   304
	} #while($_ = <LOGFILEWSERV>)
sl@0
   305
	
sl@0
   306
 #check if a test is inconclusive
sl@0
   307
  if($CurWinServTestNumber != 0)
sl@0
   308
  {
sl@0
   309
     $CurWinServTestNumber = 0;
sl@0
   310
     $wservFullTestDuration = $wservTestDuration;
sl@0
   311
sl@0
   312
      $wservTestResStatistic = "Inconclusive";
sl@0
   313
      $result = "INCONCLUSIVE";
sl@0
   314
      $Inconclusive++;
sl@0
   315
sl@0
   316
      #output result to the file
sl@0
   317
      OutputWServerTestResultToTable(FILERES, $background, $result,
sl@0
   318
          $CurWinServTestName, $fileLogWServDest, $wservFullTestDuration);
sl@0
   319
      $background = !$background;
sl@0
   320
sl@0
   321
      print FILELOGDEST  "</pre>";
sl@0
   322
      close FILELOGDEST;
sl@0
   323
  }
sl@0
   324
 
sl@0
   325
	close LOGFILEWSERV;
sl@0
   326
	close FILELOGDEST;
sl@0
   327
}
sl@0
   328
sl@0
   329
sub	OutputWServerTestResultToTable()
sl@0
   330
{
sl@0
   331
  my $handle = shift;
sl@0
   332
  my $background = shift;
sl@0
   333
  my $result = shift;
sl@0
   334
  my $TestName = shift;
sl@0
   335
  my $WServDest = shift;
sl@0
   336
  my $duration = shift;
sl@0
   337
sl@0
   338
  if($background == 1)
sl@0
   339
  {
sl@0
   340
		    print $handle "<TR BGCOLOR='#ECECE4'><TD WIDTH=\"33%\" VALIGN=\"TOP\">\n";
sl@0
   341
  }
sl@0
   342
  else
sl@0
   343
  {
sl@0
   344
		    print $handle "<TR><TD WIDTH=\"25%\" VALIGN=\"TOP\">\n";
sl@0
   345
  }
sl@0
   346
sl@0
   347
  print $handle "<FONT SIZE=2><P><a href=\"$WServDest\">$TestName</FONT></TD>\n";
sl@0
   348
sl@0
   349
  print $handle "<TD WIDTH=\"25%\" VALIGN=\"TOP\">\n";
sl@0
   350
  print $handle "<FONT SIZE=2><P>$duration</FONT></TD>\n";
sl@0
   351
sl@0
   352
  print $handle "<TD WIDTH=\"25%\" VALIGN=\"TOP\">\n";
sl@0
   353
  print $handle "<FONT SIZE=2><P>$result</FONT></TD>\n";
sl@0
   354
  print $handle "</TR>\n";
sl@0
   355
}
sl@0
   356
sl@0
   357
sub DoCopy
sl@0
   358
{
sl@0
   359
  my $source = shift;
sl@0
   360
  my $target = shift;
sl@0
   361
sl@0
   362
  my $out = `copy /y \"$source\" \"$target\" 2>&1`;
sl@0
   363
sl@0
   364
  if ($? && -e $target && $out =~ /Access is denied./)
sl@0
   365
  {
sl@0
   366
    # Target exists and is probably read only, so attempt an xcopy
sl@0
   367
    `xcopy /y /i /r /e \"$source\" \"$target\" 2>&1`;
sl@0
   368
  }
sl@0
   369
sl@0
   370
  warn "WARNING: Could not copy \"$source\" to \"$target\"\n" if $?;
sl@0
   371
}
sl@0
   372
sl@0
   373
sub CreateEpocMultiScreen()
sl@0
   374
{
sl@0
   375
  my $epocFile = shift;
sl@0
   376
  my $wsiniFile = shift;
sl@0
   377
  my $nScreens = shift;
sl@0
   378
sl@0
   379
  # epoc.ini
sl@0
   380
  open(FILE, ">>$epocFile") or warn "WARNING: Could not open file: $!\n";
sl@0
   381
  for (my $i=1; $i<$nScreens; $i++)
sl@0
   382
  {  
sl@0
   383
	  print FILE "_NewScreen_\n";
sl@0
   384
	  print FILE "ScreenWidth 640\n";
sl@0
   385
	  print FILE "ScreenHeight 240\n";
sl@0
   386
  }  
sl@0
   387
  close FILE
sl@0
   388
sl@0
   389
  # wsini.ini
sl@0
   390
  &AppendLineToFile($wsiniFile, "[SCREEN0]"); 
sl@0
   391
  for (my $i=1; $i<$nScreens; $i++)
sl@0
   392
  {
sl@0
   393
	&AppendLineToFile($wsiniFile, "[SCREEN$i]");   
sl@0
   394
  }
sl@0
   395
 }
sl@0
   396
 
sl@0
   397
 sub AppendLineToFile()
sl@0
   398
 {
sl@0
   399
   my $file = shift;
sl@0
   400
   my $line = shift;
sl@0
   401
 
sl@0
   402
   my $string = &ascii_to_utf16($line);
sl@0
   403
 
sl@0
   404
   &Write_UTF16_Newline($file);
sl@0
   405
 
sl@0
   406
   open(FILE, ">>$file") or warn "WARNING: Could not open file: $!\n";
sl@0
   407
   print FILE $string;
sl@0
   408
   close FILE;
sl@0
   409
 
sl@0
   410
   &Write_UTF16_Newline($file);
sl@0
   411
 }
sl@0
   412