Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / EventServices / RTEC_MCast_Federated / run_test.pl
blob91fb406bb6ab3bd1000a736aafed214e08e03c9d
2 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
3 & eval 'exec perl -S $0 $argv:q'
4 if 0;
6 use lib "$ENV{ACE_ROOT}/bin";
7 use PerlACE::TestTarget;
9 $status = 0;
11 if (!defined $ENV{TAO_ROOT}) {
12 $ENV{TAO_ROOT} = "$ENV{ACE_ROOT}/TAO";
15 sub usage() {
16 print "Usage:\n";
17 print " run_test [-h] [-debug]\n\n";
18 print " -udp -- Federate using udp\n";
19 print " -mcast -- Federate using multicast (the default)\n";
20 print " -h -- Prints this information\n";
21 print " -debug -- Sets the debug flag for the test\n";
22 exit;
25 my $udp = 0;
26 my $i = 0;
27 my $flags = "";
28 while ($i <= $#ARGV) {
29 if ($ARGV[$i] eq "-h" || $ARGV[$i] eq "-help" ||
30 $ARGV[$i] eq "--help" || $ARGV[$i] eq "-?") {
31 usage ();
32 } elsif ($ARGV[$i] eq "-debug") {
33 $flags .= " -ORBDebugLevel 10 ";
34 } elsif ($ARGV[$i] eq "-udp") {
35 $udp = 1;
36 } elsif ($ARGV[$i] eq "-mcast") {
37 $udp = 0;
38 } else {
39 print "ERROR: Unknown Option: ".$ARGV[$i]."\n\n";
40 usage ();
42 $i++;
45 if ($udp) {
46 print "Using UDP to link the event channels.\n\n";
47 } else {
48 print "Using multicast to link the event channels.\n\n";
51 my $ns = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
52 my $s1 = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
53 my $s2 = PerlACE::TestTarget::create_target (3) || die "Create target 3 failed\n";
54 my $c1 = PerlACE::TestTarget::create_target (4) || die "Create target 4 failed\n";
55 my $c2 = PerlACE::TestTarget::create_target (5) || die "Create target 5 failed\n";
57 my $nsiorfile = "ns.ior";
58 my $ec1iorfile = "ec1.ior";
59 my $ec2iorfile = "ec2.ior";
60 my $supplier_conf_file = "";
61 if ( -e "supplier.conf" ) {
62 $supplier_conf_file = "supplier.conf";
64 else{
65 $supplier_conf_file = "../supplier.conf";
68 my $ns_nsiorfile = $ns->LocalFile ($nsiorfile);
69 my $s1_ec1iorfile = $s1->LocalFile ($ec1iorfile);
70 my $s2_ec2iorfile = $s2->LocalFile ($ec2iorfile);
71 my $s1_nsiorfile = $s1->LocalFile ($nsiorfile);
72 my $s2_nsiorfile = $s2->LocalFile ($nsiorfile);
73 my $c1_nsiorfile = $c1->LocalFile ($nsiorfile);
74 my $c2_nsiorfile = $c2->LocalFile ($nsiorfile);
75 $ns->DeleteFile ($nsiorfile);
76 $s1->DeleteFile ($ec1iorfile);
77 $s2->DeleteFile ($ec2iorfile);
78 $s1->DeleteFile ($nsiorfile);
79 $s2->DeleteFile ($nsiorfile);
80 $c1->DeleteFile ($nsiorfile);
81 $c2->DeleteFile ($nsiorfile);
83 my $ns_hostname = $ns->HostName();
84 my $s1_hostname = $s1->HostName();
85 my $s2_hostname = $s2->HostName();
86 my $c1_hostname = $c1->HostName();
87 my $c2_hostname = $c2->HostName();
88 my $ns_port = $ns->RandomPort();
90 $NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/tao_cosnaming";
91 $NS = $ns->CreateProcess ($NameService, "$flags ".
92 " -o $ns_nsiorfile ".
93 "-ORBListenEndpoints iiop://$ns_hostname:$ns_port");
95 my($port1) = $s1->RandomPort() ;
96 my($port2) = $s1->RandomPort() ;
97 my($mport) = $s1->RandomPort() ;
99 $args1 = "$flags -ORBInitRef NameService=file://$s1_nsiorfile -ORBSvcConf $supplier_conf_file -ORBListenEndpoints iiop://$s1_hostname -iorfile $s1_ec1iorfile";
100 if ($udp) {
101 $args1 .= " -udp -ecname ec1 -port $port1 -listenport $port2 ";
102 } else {
103 $args1 .= " -ecname ec1 -address 224.9.9.2 -port $mport ";
105 $S1 = $s1->CreateProcess ("EchoEventSupplier", "$args1");
108 $args2 = "$flags -ORBInitRef NameService=file://$s2_nsiorfile -ORBSvcConf $supplier_conf_file -ORBListenEndpoints iiop://$s2_hostname -iorfile $s2_ec2iorfile";
109 if ($udp) {
110 $args2 .= " -udp -ecname ec2 -port $port2 -listenport $port1 ";
111 } else {
112 $args2 .= " -ecname ec2 -address 224.9.9.2 -port $mport ";
114 $S2 = $s2->CreateProcess ("EchoEventSupplier", "$args2");
116 $args3 = "$flags -ORBInitRef NameService=file://$c1_nsiorfile -ecname ec1 -ORBListenEndpoints iiop://$c1_hostname";
117 $C1 = $c1->CreateProcess ("EchoEventConsumer", "$args3");
120 $args4 = "$flags -ORBInitRef NameService=file://$c2_nsiorfile -ecname ec2 -ORBListenEndpoints iiop://$c2_hostname";
121 $C2 = $c2->CreateProcess ("EchoEventConsumer", "$args4");
123 # start Naming Service
124 $NS_status = $NS->Spawn ();
126 if ($NS_status != 0) {
127 print STDERR "ERROR: Name Service returned $NS_status\n";
128 exit 1;
131 if ($ns->WaitForFileTimed ($nsiorfile,$ns->ProcessStartWaitInterval()) == -1) {
132 print STDERR "ERROR: cannot find file <$ns_nsiorfile>\n";
133 $NS->Kill (); $NS->TimedWait (1);
134 exit 1;
137 if ($ns->GetFile ($nsiorfile) == -1) {
138 print STDERR "ERROR: cannot retrieve file <$ns_nsiorfile>\n";
139 $NS->Kill (); $NS->TimedWait (1);
140 exit 1;
142 if ($s1->PutFile ($nsiorfile) == -1) {
143 print STDERR "ERROR: cannot set file <$s1_nsiorfile>\n";
144 $NS->Kill (); $NS->TimedWait (1);
145 exit 1;
147 if ($s2->PutFile ($nsiorfile) == -1) {
148 print STDERR "ERROR: cannot set file <$s2_nsiorfile>\n";
149 $NS->Kill (); $NS->TimedWait (1);
150 exit 1;
152 if ($c1->PutFile ($nsiorfile) == -1) {
153 print STDERR "ERROR: cannot set file <$c1_nsiorfile>\n";
154 $NS->Kill (); $NS->TimedWait (1);
155 exit 1;
157 if ($c2->PutFile ($nsiorfile) == -1) {
158 print STDERR "ERROR: cannot set file <$c2_nsiorfile>\n";
159 $NS->Kill (); $NS->TimedWait (1);
160 exit 1;
163 # start EchoEventSupplier
164 $S1_status = $S1->Spawn ();
166 if ($S1_status != 0) {
167 print STDERR "ERROR: Supplier1 returned $S1_status\n";
168 exit 1;
171 $S2_status = $S2->Spawn ();
173 if ($S2_status != 0) {
174 print STDERR "ERROR: Supplier2 returned $S2_status\n";
175 exit 1;
178 if ($s1->WaitForFileTimed ($ec1iorfile, $s1->ProcessStartWaitInterval()+60) == -1) {
179 print STDERR "ERROR: cannot find file <$s1_ec1iorfile>\n";
180 $NS->Kill (); $NS->TimedWait (1);
181 $S1->Kill (); $S1->TimedWait (1);
182 exit 1;
185 if ($s2->WaitForFileTimed ($ec2iorfile, $s2->ProcessStartWaitInterval()) == -1) {
186 print STDERR "ERROR: cannot find file <$s2_ec2iorfile>\n";
187 $NS->Kill (); $NS->TimedWait (1);
188 $S1->Kill (); $S1->TimedWait (1);
189 $S2->Kill (); $S2->TimedWait (1);
190 exit 1;
193 $C1_status = $C1->Spawn ();
195 if ($C1_status != 0) {
196 print STDERR "ERROR: Consumer returned $C1_status\n";
197 exit 1;
200 $C2_status = $C2->Spawn ();
202 if ($C2_status != 0) {
203 print STDERR "ERROR: Consumer returned $C2_status\n";
204 exit 1;
207 $C1_status = $C1->WaitKill ($c1->ProcessStopWaitInterval()+30);
209 if ($C1_status != 0) {
210 print STDERR "ERROR: Consumer1 returned $C1_status\n";
211 $status = 1;
214 $C2_status = $C2->WaitKill ($c2->ProcessStopWaitInterval());
216 if ($C2_status != 0) {
217 print STDERR "ERROR: Consumer2 returned $C2_status\n";
218 $status = 1;
221 $NS_status = $NS->TerminateWaitKill ($ns->ProcessStopWaitInterval());
223 if ($NS_status != 0) {
224 print STDERR "ERROR: Name Service returned $NS_status\n";
225 $status = 1;
228 $S1_status = $S1->TerminateWaitKill ($s1->ProcessStopWaitInterval());
230 if ($S1_status != 0) {
231 print STDERR "ERROR: Supplier1 returned $S1_status\n";
232 $status = 1;
235 $S2_status = $S2->TerminateWaitKill ($s2->ProcessStopWaitInterval());
237 if ($S2_status != 0) {
238 print STDERR "ERROR: Supplier2 returned $S2_status\n";
239 $status = 1;
242 $ns->DeleteFile ($nsiorfile);
243 $s1->DeleteFile ($ec1iorfile);
244 $s2->DeleteFile ($ec2iorfile);
245 $s1->DeleteFile ($nsiorfile);
246 $s2->DeleteFile ($nsiorfile);
247 $c1->DeleteFile ($nsiorfile);
248 $c2->DeleteFile ($nsiorfile);
250 exit $status;