2 # ======================================================================
3 # ======================================================================
9 # ======================================================================
11 # ======================================================================
13 use constant START_BOOTLEG_TEST
=> "A";
14 use constant END_COMMUNICATION
=> "B";
15 use constant SUCCESSFUL_TEST
=> "C";
16 use constant UNSUCCESSFUL_TEST
=> "D";
17 use constant SERVER_READY
=> "E";
18 use constant BOOTLEG_MISMATCH
=> "F";
19 use constant CLIENT_KILL
=> "G";
20 use constant CLIENT_OK
=> "H";
21 use constant GOT_BUILD_CLUSTER_VERSION
=> "I";
22 use constant FAILED_GETTING_BUILD_CLUSTER_VERSION
=> "J";
23 use constant START_UPKEEP
=> "K";
24 use constant START_BOOTLEG_SEND
=> "L";
25 use constant BOOTLEG_SEND_DIRECTORY
=> "M";
26 use constant BOOTLEG_SEND_FILE
=> "N";
27 use constant END_BOOTLEG_SEND
=> "O";
28 use constant START_EMAIL
=> "P";
30 # ======================================================================
32 # ======================================================================
43 my $build_cluster = "lin-vthakkar.station.sony.com";
46 # ======================================================================
48 # ======================================================================
59 # find out where a perforce file resides on the local machine
62 open(P4
, "p4 where $_[0] |");
75 print STDERR
"Error with: $_[0]\n" if(defined $_[0]);
76 print STDERR
"Exiting this connection\n";
82 print "Installing bootleg...\n";
84 open(INSTALL
, "perl " . perforceWhere
("//depot/swg/current/tools/InstallBootleg.pl") . " --list --force_newest --client_only --no_database $branch |") or reloop
"Error running InstallBootleg.pl\n";
91 $bootlegnum = $1 if(/^Updating to build: (\d+)/);
92 $complete = 1 if(/^Update complete/);
97 print "Bootleg installation incomplete\n" if(!$complete);
98 print "Completed installing bootleg.\n" if($complete);
105 my $message = shift @_;
106 print SOCKET UNSUCCESSFUL_TEST
;
107 print STDERR
"$message\n";
113 my $message = shift @_;
114 print SOCKET UNSUCCESSFUL_TEST
;
122 @tok = split(/\\|\//, $_[0]);
124 $check = shift(@tok);
140 return 0 if (read(SOCKET
, $buffer, 4) != 4);
141 my $length = unpack("N", $buffer);
142 return 0 if(read(SOCKET
, $branch, $length) != $length);
143 return 0 if (read(SOCKET
, $buffer, 4) != 4);
144 $bootlegnum = unpack("N", $buffer);
146 print STDERR
"Recieving bootleg $branch/$bootlegnum...\n";
151 return 0 if (read(SOCKET
, $buffer, 1) != 1);
152 last if($buffer eq END_BOOTLEG_SEND
);
154 if($buffer eq BOOTLEG_SEND_DIRECTORY
)
156 return 0 if (read(SOCKET
, $buffer, 4) != 4);
157 $length = unpack("N", $buffer);
158 return 0 if (read(SOCKET
, $directory, $length) != $length);
159 makeDir
("$candela/SWO/swg_bootleg_builds/$branch/$bootlegnum/$directory");
160 chdir("$candela/SWO/swg_bootleg_builds/$branch/$bootlegnum/$directory") || reloop
"Cannot chdir to $branch/$bootlegnum/$directory - $!\n";
162 if($buffer eq BOOTLEG_SEND_FILE
)
164 return 0 if (read(SOCKET
, $buffer, 2*4) != 2*4);
165 my ($fileNameLength, $fileSize) = unpack("NN", $buffer);
167 return 0 if (read(SOCKET
, $localFileName, $fileNameLength) != $fileNameLength);
169 print STDERR
"Receiving $branch/$bootlegnum/$directory/$localFileName ($fileSize bytes)\n";
170 open(F
, ">$localFileName") || reloop
("could not open $localFileName for writing");
171 chmod (0755, $localFileName);
175 my $readSize = 16 * 1024;
176 $readSize = $fileSize if ($fileSize < $readSize);
177 my $readResult = read(SOCKET
, $buffer, $readSize);
178 reloop
"socket to controller machine abruptly terminated ($fileSize bytes remained)\n" if (!defined($readResult));
179 reloop
"read incorrect amount ($fileSize bytes remained)\n" if ($readResult == 0);
181 $fileSize -= $readResult;
183 endbootleginstall
("copied wrong number of bytes") if ($fileSize != 0);
188 chdir("$candela/SWO/swg_bootleg_builds") || reloop
"Cannot chdir to $candela - $!\n";;
190 print STDERR
"Completed recieving bootleg $branch/$bootlegnum...\n";
196 print STDERR
"Initializing communication...\n";
198 error
("problem reading from socket") if (read(SOCKET
, $buffer, 4) != 4);
199 my $length = unpack("N", $buffer);
200 error
("problem reading from socket") if(read(SOCKET
, $branch, $length) != $length);
202 print STDERR
"Testing bootleg for branch: $branch\n";
204 my $bootlegdir = perforceWhere
("//depot/swg/$branch/bootleg/win32/...");
205 $bootlegdir =~ s/\.{3}//;
207 chdir($bootlegdir) or reloop
"Cannot change to bootleg directory\n";
209 installBootleg
() || fatal
"Error installing bootleg";
211 print SOCKET
pack("N", $bootlegnum);
213 error
("problem reading from socket") if (read(SOCKET
, $buffer, 1) != 1);
214 error
("mismatch in client / server bootlegs")if($buffer eq BOOTLEG_MISMATCH
);
215 error
("server not ready") if ($buffer ne SERVER_READY
);
216 print STDERR
"Bootleg $bootlegnum verified with server - running client...\n";
219 my $swgpid = open(SWGCLIENT
, "SwgClient_o.exe -- -s ClientGame loginServerAddress=$build_cluster skipIntro=true skipSplash=true autoConnectToLoginServer=true loginClientID=bootleg loginClientPassword=bootleg avatarName=\"bootleg bootleg\" autoConnectToGameServer=true autoQuitAfterLoadScreen=true -s SharedFoundation demoMode=true |");
220 error
("problem reading from socket") if (read(SOCKET
, $buffer, 1) != 1);
221 if($buffer eq CLIENT_KILL
)
224 error
("Test unsuccessful - forced to kill client");
226 elsif($buffer eq CLIENT_OK
)
228 # make sure we give the client a chance to exit on its own, then attempt to kill
229 print "Waiting for $waittime seconds for the client to end on its own...\n";
231 $killresult = kill 1, $swgpid;
235 # clientResult = 1 if return value of SwgClient == 0 and we did not have to kill it ($killresult = 0)
236 my $clientResult = (!($?
>> 8) && !$killresult);
237 print "clientresult=$clientResult killresult=$killresult exitresult=$?\n";
239 print SOCKET
($clientResult == 1) ? SUCCESSFUL_TEST
: UNSUCCESSFUL_TEST
;
241 if($clientResult == 1)
243 open(BLESS
, ">$candela/SWO/swg_bootleg_builds/$branch/$bootlegnum/blessed.txt");
247 print STDERR
"Test was " . (($clientResult == 1) ?
"successful\n" : "unsuccessful\n") . "\n";
255 return 0 if (read(SOCKET
, $buffer, 4) != 4);
256 my $length = unpack("N", $buffer);
257 return 0 if(read(SOCKET
, $branch, $length) != $length);
259 print STDERR
"Performing upkeep on bootleg directory for $branch...\n";
262 my $removedbootlegs = 0;
265 print STDERR
"Getting bootleg version on build cluster...\n";
266 my $controller = perforceWhere
("//depot/swg/current/tools/build_cluster_controller.pl");
268 open(BUILD
, "perl $controller -bootleg-version 2>&1 |");
271 $buildcluster = $1 if(/^Build cluster bootleg version is: (\d+)/);
275 if(!defined $buildcluster)
277 print STDERR
"Could not get build cluster bootleg version.\n";
278 print SOCKET FAILED_GETTING_BUILD_CLUSTER_VERSION
;
283 print STDERR
"Build cluster bootleg version is $buildcluster.\n";
284 print SOCKET GOT_BUILD_CLUSTER_VERSION
;
285 print SOCKET
pack("N", $buildcluster);
288 opendir DH
, "$candela/SWO/swg_bootleg_builds/$branch" or fatal
"Cannot open $candela/SWO/swg_bootleg_builds/$branch: $!\n";
291 push @bootlegs, $_ if(/^\d+$/ && -d
("$candela/SWO/swg_bootleg_builds/$branch/$_"));
295 @bootlegs = sort { $a <=> $b } @bootlegs;
297 while(@bootlegs > $numbootlegs)
299 my $bootleg = shift @bootlegs;
300 next if($buildcluster == $bootleg);
302 print STDERR
"Removing bootleg $bootleg...\n";
303 system("rm -fr $candela/SWO/swg_bootleg_builds/$branch/$bootleg");
304 print SOCKET
pack("N", $bootleg);
307 print SOCKET
pack("N", 0);
308 print STDERR
"Completed upkeep on bootleg directory - removed $removedbootlegs bootlegs.\n";
311 print STDERR
"Performing upkeep on pdb directory...\n";
312 opendir DH
, "$candela/SWO/pdbs" or fatal
"Cannot open $candela/SWO/pdbs: $!\n";
313 foreach (sort readdir DH
)
316 if($pdbfile =~ /^\d+_0_$branch\.zip$/ && -M
"$candela/SWO/pdbs/$pdbfile" > $pdbtime)
318 print STDERR
"Deleting $pdbfile...\n";
319 #system("rm -f $candela/SWO/pdbs/$pdbfile");
320 print SOCKET
pack("N", length $pdbfile);
321 print SOCKET
$pdbfile;
326 print SOCKET
pack("N", 0);
328 print STDERR
"Completed upkeep on pdb directory - removed $removedpdbs pdbs.\n\n";
334 print SOCKET
pack("N", 0);
338 sub bootlegDirDescending
343 return $b <=> $a if($a =~ /^\d+$/ && $b =~ /^\d+$/);
345 # Both are not numbers
346 return $a cmp $b if(!($a =~ /^\d+$/) && !($b =~ /^\d+$/));
348 # $a is a number, $b is not
349 return -1 if($a =~ /^\d+$/);
351 # $a is not a number, $ b is
357 my $currentBootleg = "";
360 return endEmail
() if(read(SOCKET
, $buffer, 4) != 4);
361 my $currentBootlegLength = unpack("N", $buffer);
362 return endEmail
() if($currentBootlegLength == 0);
363 return endEmail
() if(read(SOCKET
, $currentBootleg, $currentBootlegLength) != $currentBootlegLength);
365 opendir DH
, "$candela/SWO/swg_bootleg_builds/$branch" or fatal
"Cannot open $candela/SWO/swg_bootleg_builds/$branch: $!\n";
366 foreach (sort { bootlegDirDescending
($b, $a) } readdir DH
)
368 # we want the 1st blessed one that is not the one we are looking at
369 next if($currentBootleg eq $_);
371 if(/^\d+$/ && -d
"$candela/SWO/swg_bootleg_builds/$branch/$_" && -f
"$candela/SWO/swg_bootleg_builds/$branch/$_/blessed.txt")
379 print SOCKET
pack("N", length $oldBootleg);
380 print SOCKET
$oldBootleg;
382 print STDERR
"Completed sending information to build_bootleg_linux.\n";
385 # ======================================================================
387 # ======================================================================
389 # open the daemon socket
390 print STDERR
"Opening socket\n";
391 socket(LISTEN
, PF_INET
, SOCK_STREAM
, getprotobyname('tcp')) || die "socket failed\n";
392 setsockopt(LISTEN
, SOL_SOCKET
, SO_REUSEADDR
, 1) || die "setsockopt failed\n";
393 my $addr = sockaddr_in
($port, INADDR_ANY
);
394 bind(LISTEN
, $addr) || die "bind failed\n";
395 listen(LISTEN
, 1) || die "listen failed\n";
400 print STDERR
"Waiting on a connection...\n";
402 accept(SOCKET
, LISTEN
) || reloop
"accept failed\n";
404 # make binary and unbuffer the socket
406 my $oldSelect = select(SOCKET
);
411 error
("problem reading from socket") if (read(SOCKET
, $buffer, 1) != 1);
413 if($buffer eq START_BOOTLEG_TEST
)
415 print "Got message to initiate bootleg test.\n";
418 elsif($buffer eq START_UPKEEP
)
420 print "Got message to perform upkeep.\n";
423 elsif($buffer eq START_BOOTLEG_SEND
)
425 print "Got message to start recieving bootleg.\n";
428 elsif($buffer eq START_EMAIL
)
430 print "Got message to start email.\n";