Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_App / run_test_detector.pl
blobb009e2f7e8b3fe11d7bfa5070f5b7d9993b0e71b
1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
3 if 0;
5 # -*- perl -*-
7 # Purpose:
8 # To test the FaultDetectorFactory and FaultDetectors
10 # Command line options:
11 # --debug_build use exes from this directory
12 # if not specified use exes from ./release
13 # -v display test progress messages (repeating option increases verbosity
15 # Process being tested:
16 # Fault_Detector
17 # implements FaultDetectorFactory interface
18 # implements PullMonitorable interface
20 # Processes used in test:
21 # FT_Replica
22 # implements TestReplica interface.
23 # implements PullMonitorable.
24 # StubNotifier
25 # implements FaultNotifier interface (as a stub.)
26 # implements PullMonitorable.
27 # client for FaultDetectorFactory interface.
28 # FT_Client
29 # client for TestReplica interface.
30 # client for PullMonitorable.
32 # Test Scenario ( ***Test: marks behavior being tested):
33 # Start two FT_Replicas
34 # FT_Replicas write TestReplica IORs (FR#1 and FR#2) to files
35 # Start the Fault_Detector
36 # Fault_Detector writes its IOR (FDF) to a file
37 # Wait for IORs: FR#1, FR#2, and FDF
38 # Start the StubNotifier giving it IORS: FR#1, FR#2 and FDF
39 # StubNotifier calls FDF to create a FaultDetector
40 # for each Replica.
41 # StubNotifier writes FaultNotifier IOR (FN) to a file.
42 # Wait for IOR: FN
43 # Start FT_Client giving it IORS: FR#1 and FR#2.
44 # FT_Client interacts with FR#1.
45 # FT_Client asks FR#1 to fault. It does so.
46 # FT_Client notices fault and switches to FR#2.
47 # ***Test: FD#1 notices fault and notifies StubNotifier
48 # ***Test: FD#1 terminates
49 # FT_Client interacts with FR#2.
50 # FT_Client asks FR#2 to shut down.
51 # FT_Client shuts down.
52 # ***Test: FD#2 notices FR2 is gone, interprets this
53 # as a fault, and notifies StubNotifier.
54 # ***Test: FD#2 terminates.
55 # Shut down
56 # ***Test: FDF is idle, so it terminates.
57 # StubNotifier sees FDF terminate, so it terminates
58 # Cleanup
59 # Wait for all processes to terminate.
60 # Check termination status.
61 # Delete temp files.
63 use lib "$ENV{ACE_ROOT}/bin";
64 use PerlACE::TestTarget;
66 ########################
67 #command line options
68 #set defaults:
69 my($status) = 0;
70 my($verbose) = 0; # 1: report perl actions before executing them; 2 display settings from command line
71 my($debug_builds) = 0; # 0: use exes from Release directories
72 my($simulated) = 1; # 1: use "client simulated" fault tolerance
74 foreach $i (@ARGV) {
75 if ($i eq "--debug_build"){
76 $debug_builds = 1;
78 elsif ($i eq "-v"){
79 $verbose += 1;
84 my($build_directory) = "/Release";
85 if ( $debug_builds ) {
86 $build_directory = "";
89 if ( $verbose > 1) {
90 print "verbose: $verbose\n";
91 print "debug_builds: $debug_builds -> $build_directory\n";
92 print "simulated: $simulated\n";
95 # List of the proccess which must be killed before exit with error
96 @kill_list = ();
98 sub add_to_kills{
99 $goal = shift;
100 @kill_list = (@kill_list, $goal);
102 sub exit_and_kill{
103 $status = shift;
104 foreach $goal (@kill_list){
105 $goal->Kill (); $goal->TimedWait (1);
107 exit $status;
110 my $ft_replica1 = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
111 my $ft_replica2 = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
112 my $fault_detector = PerlACE::TestTarget::create_target (3) || die "Create target 3 failed\n";
113 my $fault_notifier = PerlACE::TestTarget::create_target (4) || die "Create target 4 failed\n";
114 my $client = PerlACE::TestTarget::create_target (5) || die "Create target 5 failed\n";
117 $hostname = $fault_detector->HostName ();
118 $port = $fault_detector->RandomPort ();
120 #define temp files
121 my($factory1_ior) = "factory1.ior";
122 my($factory2_ior) = "factory2.ior";
123 my($replica1_ior) = "replica1.ior";
124 my($replica2_ior) = "replica2.ior";
125 my($detector_ior) = "detector.ior";
126 my($notifier_ior) = "notifier.ior";
127 my($client_data) = "persistent.dat";
129 # Files for ft_replica1
130 my $ft_replica1_factory1_ior = $ft_replica1->LocalFile ($factory1_ior);
131 my $ft_replica1_replica1_ior = $ft_replica1->LocalFile ($replica1_ior);
132 my $ft_replica1_client_data = $ft_replica1->LocalFile ($client_data);
134 $ft_replica1->DeleteFile ($factory1_ior);
135 $ft_replica1->DeleteFile ($replica1_ior);
136 $ft_replica1->DeleteFile ($client_data);
138 # Files for ft_replica2
139 my $ft_replica2_factory2_ior = $ft_replica2->LocalFile ($factory2_ior);
140 my $ft_replica2_replica2_ior = $ft_replica2->LocalFile ($replica2_ior);
141 my $ft_replica2_client_data = $ft_replica2->LocalFile ($client_data);
143 $ft_replica2->DeleteFile ($factory2_ior);
144 $ft_replica2->DeleteFile ($replica2_ior);
145 $ft_replica2->DeleteFile ($client_data);
147 # Files for fault_detector
148 my $fault_detector_ior = $fault_detector->LocalFile ($detector_ior);
149 $fault_detector->DeleteFile ($detector_ior);
151 # Files for fault_notifier
152 my $fault_notifier_ior = $fault_notifier->LocalFile ($notifier_ior);
153 my $notifier_replica1_ior = $fault_notifier->LocalFile ($replica1_ior);
154 my $notifier_replica2_ior = $fault_notifier->LocalFile ($replica2_ior);
155 my $notifier_detector_ior = $fault_notifier->LocalFile ($detector_ior);
157 $fault_notifier->DeleteFile ($notifier_ior);
158 $fault_notifier->DeleteFile ($replica1_ior);
159 $fault_notifier->DeleteFile ($replica2_ior);
160 $fault_notifier->DeleteFile ($detector_ior);
162 # Files for client
163 my $client_replica1_ior = $client->LocalFile ($replica1_ior);
164 my $client_replica2_ior = $client->LocalFile ($replica2_ior);
166 $client->DeleteFile ($replica1_ior);
167 $client->DeleteFile ($replica2_ior);
169 ### Create process
170 $REP1 = $ft_replica1->CreateProcess (".$build_directory/ft_replica" ,
171 "-o $ft_replica1_factory1_ior ".
172 "-f none -t $ft_replica1_replica1_ior " .
173 "-l loc1 -i type1 -q -p $ft_replica1_client_data");
175 $REP2 = $ft_replica2->CreateProcess (".$build_directory/ft_replica" ,
176 "-o $ft_replica2_factory2_ior ".
177 "-f none -t $ft_replica2_replica2_ior " .
178 "-l loc2 -i type1 -q -p $ft_replica2_client_data");
180 $DET = $fault_detector->CreateProcess ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Detector" .
181 "$build_directory/tao_fault_detector" ,
182 "-ORBInitRef ReplicationManager=corbaloc::$hostname:$port/ReplicationManager " .
183 "-o $fault_detector_ior -q");
185 $NOT = $fault_notifier->CreateProcess ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Notifier" .
186 "$build_directory/tao_fault_notifier" ,
187 "-ORBInitRef ReplicationManager=corbaloc::$hostname:$port/ReplicationManager " .
188 "-o $fault_notifier_ior -q " .
189 "-d file://$notifier_detector_ior " .
190 "-r file://$notifier_replica1_ior -r file://$notifier_replica2_ior");
192 $CL = $client->CreateProcess (".$build_directory/ft_client",
193 "-f file://$client_replica1_ior " .
194 "-f file://$client_replica2_ior " .
195 "-c testscript");
198 print "TEST: starting replica1 ". $REP1->CommandLine . "\n" if ($verbose);
199 $REP1->Spawn ();
201 add_to_kills ($REP1);
203 print "TEST: waiting for replica 1's IOR\n" if ($verbose);
204 if ($ft_replica1->WaitForFileTimed ($replica1_ior,
205 $ft_replica1->ProcessStartWaitInterval()) == -1) {
206 print STDERR "ERROR: cannot find file <$ft_replica1_replica1_ior>\n";
207 exit_and_kill (1);
209 # Get/Put $replica1_ior: notifier_replica1_ior $client_replica1_ior
210 if ($ft_replica1->GetFile ($replica1_ior) == -1) {
211 print STDERR "ERROR: cannot retrieve file <$ft_replica1_replica1_ior>\n";
212 exit_and_kill (1);
214 if ($fault_notifier->PutFile ($replica1_ior) == -1) {
215 print STDERR "ERROR: cannot set file <$notifier_replica1_ior>\n";
216 exit_and_kill (1);
218 if ($client->PutFile ($replica1_ior) == -1) {
219 print STDERR "ERROR: cannot set file <$client_replica1_ior>\n";
220 exit_and_kill (1);
223 print "\nTEST: starting replica2 " . $REP2->CommandLine . "\n" if ($verbose);
224 $REP2->Spawn ();
226 add_to_kills ($REP2);
228 print "TEST: waiting for replica 2's IOR\n" if ($verbose);
229 if ($ft_replica2->WaitForFileTimed ($replica2_ior,
230 $ft_replica2->ProcessStartWaitInterval()) == -1) {
231 print STDERR "TEST ERROR: cannot find file <$ft_replica2_replica2_ior>\n";
232 exit_and_kill (1);
234 # Get/Put $replica2_ior: notifier_replica2_ior $client_replica2_ior
235 if ($ft_replica2->GetFile ($replica2_ior) == -1) {
236 print STDERR "ERROR: cannot retrieve file <$ft_replica2_replica2_ior>\n";
237 exit_and_kill (1);
239 if ($fault_notifier->PutFile ($replica2_ior) == -1) {
240 print STDERR "ERROR: cannot set file <$notifier_replica2_ior>\n";
241 exit_and_kill (1);
243 if ($client->PutFile ($replica2_ior) == -1) {
244 print STDERR "ERROR: cannot set file <$client_replica2_ior>\n";
245 exit_and_kill (1);
248 print "\nTEST: starting detector factory " . $DET->CommandLine . "\n" if ($verbose);
249 $DET->Spawn ();
251 add_to_kills ($DET);
253 print "TEST: waiting for detector's IOR\n" if ($verbose);
254 if ($fault_detector->WaitForFileTimed ($detector_ior,
255 $fault_detector->ProcessStartWaitInterval()) == -1) {
256 print STDERR "ERROR: cannot find file <$fault_detector_ior>\n";
257 exit_and_kill (1);
260 # Get/Put $detector_ior: $notifier_detector_ior
261 if ($fault_detector->GetFile ($detector_ior) == -1) {
262 print STDERR "ERROR: cannot retrieve file <$fault_detector_ior>\n";
263 exit_and_kill (1);
265 if ($fault_notifier->PutFile ($detector_ior) == -1) {
266 print STDERR "ERROR: cannot set file <$notifier_detector_ior>\n";
267 exit_and_kill (1);
270 print "\nTEST: starting notifier " . $NOT->CommandLine . "\n" if ($verbose);
271 $NOT->Spawn ();
273 add_to_kills ($NOT);
275 print "TEST: waiting for notifier's IOR\n" if ($verbose);
276 if ($fault_notifier->WaitForFileTimed ($notifier_ior,
277 $fault_notifier->ProcessStartWaitInterval()) == -1) {
278 print STDERR "ERROR: cannot find file <$fault_notifier_ior>\n";
279 exit_and_kill (1);
282 print "\nTEST: starting client." . $CL->CommandLine . "\n" if ($verbose);
284 $status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval() + 45);
286 if ($status != 0) {
287 print STDERR "TEST ERROR: client returned $status\n";
288 $status = 1;
291 print "\nTEST: wait for replica 1.\n" if ($verbose);
292 $status_replica = $REP1->WaitKill ($ft_replica1->ProcessStopWaitInterval() + 45);
293 if ($status_replica != 0) {
294 print STDERR "TEST ERROR: replica returned $status_replica\n";
295 $status = 1;
297 print "\nTEST: wait for replica 2.\n" if ($verbose);
298 $status_replica = $REP2->WaitKill ($ft_replica2->ProcessStopWaitInterval() + 45);
299 if ($status_replica != 0) {
300 print STDERR "TEST ERROR: replica returned $status_replica\n";
301 $status = 1;
304 print "\nTEST: wait for detector factory to leave.\n" if ($verbose);
305 $status_det = $DET->WaitKill ($fault_detector->ProcessStopWaitInterval() + 45);
306 if ($status_det != 0) {
307 print STDERR "TEST ERROR: detector returned $status_det\n";
308 $status = 1;
311 print "\nTEST: wait for notifier to leave.\n" if ($verbose);
312 $status_not = $NOT->WaitKill ($fault_notifier->ProcessStopWaitInterval() + 45);
313 if ($status_not != 0) {
314 print STDERR "TEST ERROR: notifier returned $status_not\n";
315 $status = 1;
318 print "\nTEST: releasing scratch files.\n" if ($verbose);
319 # Files for ft_replica1
320 $ft_replica1->DeleteFile ($factory1_ior);
321 $ft_replica1->DeleteFile ($replica1_ior);
322 $ft_replica1->DeleteFile ($client_data);
324 # Files for ft_replica2
325 $ft_replica2->DeleteFile ($factory2_ior);
326 $ft_replica2->DeleteFile ($replica2_ior);
327 $ft_replica2->DeleteFile ($client_data);
329 # Files for fault_detector
330 $fault_detector->DeleteFile ($detector_ior);
332 # Files for fault_notifier
333 $fault_notifier->DeleteFile ($notifier_ior);
334 $fault_notifier->DeleteFile ($replica1_ior);
335 $fault_notifier->DeleteFile ($replica2_ior);
336 $fault_notifier->DeleteFile ($detector_ior);
338 # Files for client
339 $client->DeleteFile ($replica1_ior);
340 $client->DeleteFile ($replica2_ior);
342 exit $status;