buildverification/smoketest/SmokeTestServer.pl
branchRCL_3
changeset 10 4ca382093dae
parent 5 6beaa9cf4752
child 11 493058e57c8c
equal deleted inserted replaced
5:6beaa9cf4752 10:4ca382093dae
     1 # Copyright (c) 2004-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 # TestServer.pl 
       
    15 # This script was born on 19/10/2004
       
    16 # 
       
    17 #
       
    18 
       
    19 use strict;
       
    20 
       
    21 my $jobsfolder = "d:\\Jobs\\";
       
    22 
       
    23 # Loop forever
       
    24 while (1)
       
    25 {
       
    26 	open LogFile, ">>d:\\SmokeTestServerLog.txt" or die "Cannot open log file: $!";
       
    27 	
       
    28 	print "\n***********************\n";
       
    29 	print "\n*** START PUBLISHER ***\n";
       
    30 	print "\n***********************\n";
       
    31 	print "\n";
       
    32 	print LogFile "\n***********************\n";
       
    33 	print LogFile "\n*** START PUBLISHER ***\n";
       
    34 	print LogFile "\n***********************\n";
       
    35 	print LogFile "\n";
       
    36 	
       
    37 	my $localtimes = localtime;
       
    38 	print "\n*** Current Time: $localtimes ***\n";
       
    39 	print LogFile "\n*** Current Time: $localtimes ***\n";
       
    40 	
       
    41 	# 
       
    42 	# Check if there are any results ready for publishing
       
    43 	#
       
    44 	print "\n";
       
    45 	print "#\n# Check if there are any results ready for publishing\n#\n"; 
       
    46 	print "\n";	
       
    47 	print LogFile "\n";
       
    48 	print LogFile "#\n# Check if there are any results ready for publishing\n#\n"; 
       
    49 	print LogFile "\n";	
       
    50 	
       
    51 	opendir JobDir, $jobsfolder or die "Cannot open jobs dir $jobsfolder: $!";
       
    52 		
       
    53 	my @jobs = readdir(JobDir);
       
    54 	
       
    55 	# to remove "." and ".." from this list
       
    56 	shift @jobs;
       
    57 	shift @jobs;
       
    58 	
       
    59 	if (!scalar(@jobs))
       
    60 	{
       
    61 		print "\nNo Jobs to publish\n";
       
    62 		print LogFile "\nNo Jobs to publish\n";
       
    63 	}
       
    64 	else
       
    65 	{
       
    66 		# 
       
    67 		# Loop though each directory and publish logs
       
    68 		#
       
    69 		print "\n";
       
    70 		print "#\n# Loop though each directory and publish logs\n#\n"; 
       
    71 		print "\n";
       
    72 		print LogFile "\n";
       
    73 		print LogFile "#\n# Loop though each directory and publish logs\n#\n"; 
       
    74 		print LogFile "\n";
       
    75 			
       
    76 		foreach my $name (sort { $a <=> $b } @jobs)
       
    77 		{
       
    78 			if ( -d $jobsfolder.$name)
       
    79 			{
       
    80 				print "\n*** Found Job: $name ***\n";
       
    81 				print LogFile "\n*** Found Job: $name ***\n";
       
    82 				
       
    83 				# Check to see if job has been completed.
       
    84 				if (isJobFinished($name))
       
    85 				{
       
    86 					# 
       
    87 					# Publish the results
       
    88 					#
       
    89 					print "\n";
       
    90 					print "#\n# Publish the results\n#\n"; 
       
    91 					print "\n";
       
    92 					print LogFile "\n";
       
    93 					print LogFile "#\n# Publish the results\n#\n"; 
       
    94 					print LogFile "\n";
       
    95 					
       
    96 					my $publishfile = $jobsfolder.$name."\\publish.txt";
       
    97 					
       
    98 					if (-r $publishfile)
       
    99 					{
       
   100 						open (PUBLISH, $publishfile) or GoNext("Cannot find publish details for $name");
       
   101 						my $count = 0;
       
   102 						my $index = 0;
       
   103 						while (my $publishlocation = <PUBLISH>)
       
   104 						{
       
   105 							chomp $publishlocation;
       
   106 							
       
   107 							$index++;
       
   108 							
       
   109 							print "\nPublish Location = $publishlocation\n";
       
   110 							print LogFile "\nPublish Location = $publishlocation\n";
       
   111 							
       
   112 							`mkdir $publishlocation`; # or GoNext("$publishlocation\\$name\\");
       
   113 							
       
   114 							my $lookIn = "$jobsfolder$name\\output";
       
   115 							my ($source,$runid,$buildname) = getSourceDir($lookIn);
       
   116 							
       
   117 							my $srcdir = $source."\\xml";
       
   118 							my $trgtdir= $publishlocation."xml\\";
       
   119 							
       
   120 							my $xcopycmd= "xcopy /C /Y /E $srcdir $trgtdir ";
       
   121 							print `$xcopycmd`;
       
   122 							
       
   123 							#
       
   124 							# Copy the contents of Output and reports -
       
   125 							#
       
   126 							# runXX_<snapshot>_SymbianOS_vYY.xml/html to <snapshot>_Symbian_OS_vYY.xml/html
       
   127 							#
       
   128 							
       
   129 							my $xmlfile   = "$source\\run".$runid."_".$buildname."\.xml";
       
   130 							my $htmlfile  = "$source\\run".$runid."_".$buildname."\.html";
       
   131 							
       
   132 							if (-e $xmlfile)  {
       
   133 								
       
   134 								print "copy $xmlfile to $buildname.xml";
       
   135 								system "copy $xmlfile $publishlocation\\$buildname.xml";
       
   136 							}
       
   137 							
       
   138 							if (-e $htmlfile)  {
       
   139 								
       
   140 								print "copy $htmlfile to $buildname.html";
       
   141 								system "copy $htmlfile $publishlocation\\$buildname.html";
       
   142 							}
       
   143 							
       
   144 							print "\nNumber of Files Copied = $1\n" if $xcopycmd =~ m/(\d+)\s\w+/;
       
   145 							print LogFile "\nNumber of Files Copied = $1\n" if $xcopycmd =~ m/(\d+)\s\w+/;
       
   146 							
       
   147 							$count += $1;
       
   148 							
       
   149 							# The input should be copied onto \\devbuilds\master\.. but not \\devbuilds\logs\master\..
       
   150 							if ($index < 2)
       
   151 							{
       
   152 								print "\n\nCopy the Input\n";
       
   153 								$source = "$jobsfolder$name\\input\\*";
       
   154 								
       
   155 								# Copy the contents of Input
       
   156 								print "\ncmd: xcopy /C /Y /E $source $publishlocation 2>&1\n";
       
   157 								print LogFile "\ncmd: xcopy /C /Y /E $source $publishlocation 2>&1\n";
       
   158 								my $xcopy = `xcopy /C /Y /E $source $publishlocation 2>&1`;
       
   159 								print $xcopy;
       
   160 								
       
   161 								print "\nNumber of Files Copied = $1\n" if $xcopy =~ m/(\d+)\s\w+/;
       
   162 								print LogFile "\nNumber of Files Copied = $1\n" if $xcopy =~ m/(\d+)\s\w+/;
       
   163 								$count += $1;
       
   164 							}
       
   165 						}						
       
   166 						close Publish;
       
   167 						
       
   168 						print "\nTotal Number of files copied = $count\n";
       
   169 						print LogFile "\nTotal Number of files copied = $count\n";
       
   170 						
       
   171 						# Minimum 3 files have to be copied - Trace.txt, sys$rom.bin and armX.tpkg
       
   172 						if ($count >= 3)
       
   173 						{
       
   174 							# it is fine to delete the jobs dir
       
   175 							print "\ncmd: rd $jobsfolder$name /Q /S  2>&1\n";
       
   176 							print LogFile "\ncmd: rd $jobsfolder$name /Q /S  2>&1\n";
       
   177 							print `rd $jobsfolder$name /Q /S  2>&1`;
       
   178 						}
       
   179 					}
       
   180 					else
       
   181 					{
       
   182 						print "\n*** Error publishing results ***\n Cannot open publish file: $jobsfolder"."$name"."\\publish.txt\n";
       
   183 						print LogFile "\n*** Error publishing results ***\n Cannot open publish file: $jobsfolder"."$name"."\\publish.txt\n";
       
   184 					}
       
   185 				}
       
   186 				else
       
   187 				{
       
   188 					print "\nThe Job $name is either still running or has encountered an error\n";				
       
   189 					print LogFile "\nThe Job $name is either still running or has encountered an error\n";				
       
   190 				}
       
   191 			}
       
   192 			else
       
   193 			{
       
   194 				print "*** Error ***\nDir does not exist! $jobsfolder.$name\n";
       
   195 				print LogFile "*** Error ***\nDir does not exist! $jobsfolder.$name\n";
       
   196 			}
       
   197 		}
       
   198 	}
       
   199 	close JobDir;
       
   200 	
       
   201 	my $localtimes = localtime;
       
   202 	print "\n*** Current Time: $localtimes ***\n";
       
   203 	print LogFile "\n*** Current Time: $localtimes ***\n";
       
   204 	
       
   205 	print "\n";
       
   206 	print "\n*********************\n";
       
   207 	print "\n*** END PUBLISHER ***\n";
       
   208 	print "\n*********************\n";
       
   209 	print "\n";
       
   210 	print "\n";
       
   211 	print LogFile "\n";
       
   212 	print LogFile "\n*********************\n";
       
   213 	print LogFile "\n*** END PUBLISHER ***\n";
       
   214 	print LogFile "\n*********************\n";
       
   215 	print LogFile "\n";
       
   216 	print LogFile "\n";
       
   217 	
       
   218 	close LogFile;
       
   219 	sleep 900;
       
   220 }
       
   221 
       
   222 sub GoNext
       
   223 {
       
   224 	print "\n*** Error in Publisher ***\n $_[0] $!\n";
       
   225 	print LogFile "\n*** Error in Publisher ***\n $_[0] $!\n";
       
   226 	next;
       
   227 }
       
   228 
       
   229 # identify if a job has finished
       
   230 sub isJobFinished($) {
       
   231 	
       
   232 	my $jobid = shift;
       
   233 	my @cmd_out = `testdriver.cmd jobstatus -j $jobid 2>&1`;
       
   234 	
       
   235 	foreach (@cmd_out) {
       
   236 		if (m/completed/) { return 1; }
       
   237 	}
       
   238 	
       
   239 	return 0;
       
   240 }
       
   241 
       
   242 sub getSourceDir($)
       
   243 {
       
   244 	my $source = shift;
       
   245 	my $runid  = 0;
       
   246 	my $buildname;
       
   247 	
       
   248 	#
       
   249 	# Find the correct directory to publish
       
   250 	#
       
   251 	
       
   252 	if (opendir RESULTS, $source)
       
   253 	{	
       
   254 		my @dirArray = readdir(RESULTS);
       
   255 		
       
   256 		#print "@results";	
       
   257 		# to remove "." and ".." from this list
       
   258 		shift @dirArray;
       
   259 		shift @dirArray;
       
   260 		
       
   261 		if (!scalar(@dirArray))
       
   262 		{
       
   263 			print "REMARK: The result for $_[0] has an empty $source directory";
       
   264 			return;
       
   265 		}
       
   266 		else
       
   267 		{
       
   268 			print "\nContents of $source = @dirArray\n";
       
   269 			$source .= "\\$dirArray[0]"; 
       
   270 			# dirArray should always have just the one subdir - 0XXXX_Symbian_OS_vX.X
       
   271 			
       
   272 			$buildname = $dirArray[0];
       
   273 	
       
   274 			if (opendir tempDir, "$source")
       
   275 			{
       
   276 				# to remove "." and ".." from this list
       
   277 				my @dirArray = readdir(tempDir);
       
   278 				shift @dirArray;
       
   279 				shift @dirArray;
       
   280 				
       
   281 				print "\nContents of $source = @dirArray\n";
       
   282 				
       
   283 				foreach my $directory (@dirArray)
       
   284 				{
       
   285 					if ($directory =~ /(?:$_[0])/i)
       
   286 					{
       
   287 						$source .= "\\$directory";
       
   288 						
       
   289 						# added this to remove udeb/xx
       
   290 						if (opendir tempDir, "$source")
       
   291 						{
       
   292 							# to remove "." and ".." from this list
       
   293 							@dirArray = readdir(tempDir);
       
   294 							shift @dirArray;
       
   295 							shift @dirArray;
       
   296 				
       
   297 							print "\nContents of $source = @dirArray\n";
       
   298 				
       
   299 							foreach my $directory (@dirArray)
       
   300 							{
       
   301 								if ($directory =~ /(udeb|urel)/i)
       
   302 								{
       
   303 									$source .= "\\$directory";
       
   304 									if (opendir tempDir, "$source")
       
   305 									{
       
   306 										# to remove "." and ".." from this list
       
   307 										@dirArray = readdir(tempDir);
       
   308 										shift @dirArray;
       
   309 										shift @dirArray;
       
   310 				
       
   311 										print "\nContents of $source = @dirArray\n";
       
   312 				
       
   313 										foreach my $directory (@dirArray)
       
   314 										{
       
   315 											if ($directory =~ /(^[0-9]+)/i)
       
   316 											{
       
   317 												$source .= "\\$directory";
       
   318 												$runid = $directory;
       
   319 												last;
       
   320 											}
       
   321 										}
       
   322 									}
       
   323 									last;
       
   324 								}
       
   325 							}
       
   326 						}
       
   327 						
       
   328 					}
       
   329 				}
       
   330 			}
       
   331 		}
       
   332 	}
       
   333 	return ($source, $runid, $buildname);
       
   334 }