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