Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / ImplRepo / Activator / run_test.pl
blobb4f541a7a2a6057fe79a99f0954ae062dc41e3b0
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;
10 $debug_level = '0';
12 foreach $i (@ARGV) {
13 if ($i eq '-debug') {
14 $debug_level = '10';
18 my $c1 = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
19 my $imr = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
20 my $act = PerlACE::TestTarget::create_target (3) || die "Create target 3 failed\n";
21 my $ti = PerlACE::TestTarget::create_target (4) || die "Create target 4 failed\n";
23 my $WAIT_TIMEOUT = 2;
24 my $DEBUG_LEVEL = 1;
25 my $OBJ_REF_STYLE = "-orbobjrefstyle url";
27 my $implrepo_server = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_locator";
28 my $imr_activator = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_activator";
29 my $tao_imr = "$ENV{ACE_ROOT}/bin/tao_imr";
31 my $implrepo_ior = "imr.ior";
32 my $activator_ior = "activator.ior";
33 my $messenger_ior = "messenger.ior";
35 my $imr_imriorfile = $imr->LocalFile ($implrepo_ior);
36 my $act_imriorfile = $act->LocalFile ($implrepo_ior);
37 my $ti_imriorfile = $ti->LocalFile ($implrepo_ior);
38 my $act_actiorfile = $act->LocalFile ($activator_ior);
39 my $imr_srviorfile = $imr->LocalFile ($messenger_ior);
40 my $c1_srviorfile = $c1->LocalFile ($messenger_ior);
43 sub CleanupOutput {
44 $imr->DeleteFile ($implrepo_ior);
45 $act->DeleteFile ($implrepo_ior);
46 $ti->DeleteFile ($implrepo_ior);
47 $act->DeleteFile ($activator_ior);
48 $imr->DeleteFile ($messenger_ior);
49 $c1->DeleteFile ($messenger_ior);
52 sub SpawnWait {
53 my $process = shift;
54 my $file = shift;
55 my $target = shift;
57 print ">>> " . $process->CommandLine () . "\n";
58 my $status = $process->Spawn ();
59 if ($status != 0) {
60 print STDERR "ERROR: Process returned $status\n";
61 return 1;
63 my $ret = $target->WaitForFileTimed ($file,$target->ProcessStartWaitInterval());
64 if ($ret == -1) {
65 print STDERR "ERROR: Cannot find file <$file>\n";
67 return $ret;
71 $Srv = $imr->CreateProcess ("../Basic/MessengerServer", "-ORBdebuglevel $debug_level ".
72 "-orbuseimr 1 ".
73 "$OBJ_REF_STYLE ".
74 "-ORBInitRef ImplRepoService=file://$imr_imriorfile");
75 $C1 = $c1->CreateProcess ("../Basic/MessengerClient", "-k file://$c1_srviorfile ");
76 my $server_cmd = $Srv->Executable();
77 my $srv_server_cmd = $imr->LocalFile ($server_cmd);
79 # Use url object reference style for readability, and startup timeout of 2 seconds.
80 # Unlike the chapter we'll forgo using -m, because we want to be able to run this
81 # as a test in our nightly builds, and multicast could interfere with other machines.
82 $ImR = $imr->CreateProcess ($implrepo_server, "-d $DEBUG_LEVEL ".
83 "$OBJ_REF_STYLE ".
84 "-t 2 ".
85 "-o $imr_imriorfile");
86 $Act = $act->CreateProcess ($imr_activator, "-d $DEBUG_LEVEL ".
87 "$OBJ_REF_STYLE ".
88 "-o $act_actiorfile ".
89 "-ORBInitRef ImplRepoService=file://$act_imriorfile");
91 $TI = $ti->CreateProcess ($tao_imr);
92 # We want the tao_imr executable to be found exactly in the path
93 # given, without being modified by the value of -ExeSubDir.
94 # So, we tell its Process object to ignore the setting of -ExeSubDir.
95 $TI->IgnoreExeSubDir(1);
97 sub RunImRUtil {
98 my $cmd = shift;
100 print ">>> " . $TI->CommandLine() . "\n";
101 $TI->Arguments("-ORBInitRef ImplRepoService=file://$ti_imriorfile $cmd");
102 return $TI->SpawnWaitKill($ti->ProcessStartWaitInterval());
105 CleanupOutput();
107 #### Start the example
109 if (SpawnWait($ImR, $implrepo_ior, $imr) != 0) {
110 $ImR->Kill(); $ImR->TimedWait(1);
111 exit 1;
113 if ($imr->GetFile ($implrepo_ior) == -1) {
114 print STDERR "ERROR: cannot retrieve file <$imr_imriorfile>\n";
115 $ImR->Kill (); $ImR->TimedWait (1);
116 exit 1;
118 if ($act->PutFile ($implrepo_ior) == -1) {
119 print STDERR "ERROR: cannot set file <$act_imriorfile>\n";
120 $ImR->Kill (); $ImR->TimedWait (1);
121 exit 1;
123 if ($ti->PutFile ($implrepo_ior) == -1) {
124 print STDERR "ERROR: cannot set file <$ti_imriorfile>\n";
125 $ImR->Kill (); $ImR->TimedWait (1);
126 exit 1;
129 if (SpawnWait($Act, $activator_ior, $act) != 0) {
130 $ImR->Kill(); $ImR->TimedWait(1);
131 exit 1;
134 #instead of using tao_imr add, we'll use tao_imr update, because
135 #we want to run the server once to generate the ior file.
137 if (SpawnWait($Srv, $messenger_ior, $imr) != 0) {
138 $Act->Kill(); $Act->TimedWait(1);
139 $ImR->Kill(); $ImR->TimedWait(1);
140 exit 1;
142 if ($imr->GetFile ($implrepo_ior) == -1) {
143 print STDERR "ERROR: cannot retrieve file <$imr_srviorfile>\n";
144 $Act->Kill(); $Act->TimedWait(1);
145 $ImR->Kill (); $ImR->TimedWait (1);
146 exit 1;
148 if ($c1->PutFile ($implrepo_ior) == -1) {
149 print STDERR "ERROR: cannot set file <$c1_srviorfile>\n";
150 $Act->Kill(); $Act->TimedWait(1);
151 $ImR->Kill (); $ImR->TimedWait (1);
152 exit 1;
155 RunImRUtil("list -v");
157 RunImRUtil("shutdown MessengerService");
158 $Srv_status = $Srv->TerminateWaitKill ($imr->ProcessStopWaitInterval());
160 if ($Srv_status != 0) {
161 print STDERR "ERROR: Server returned $Srv_status\n";
162 exit 1;
165 RunImRUtil("list -v");
167 # Note : If the server registers itself, then it won't set the
168 # activator name. If we don't set it here, then the activator
169 # won't be able to start the server.
170 my $actname = $ti->hostname;
171 RunImRUtil("update MessengerService -l $actname -c \"$srv_server_cmd $OBJ_REF_STYLE -ORBUseIMR 1 -ORBInitRef ImplRepoService=file://$imr_imriorfile\"");
173 RunImRUtil("list -v");
175 $C1_status = $C1->SpawnWaitKill ($c1->ProcessStartWaitInterval()+985);
177 if ($C1_status != 0) {
178 print STDERR "ERROR: Client returned $C1_status\n";
179 $ImR->Kill (); $ImR->TimedWait (1);
180 $ACT->Kill (); $ACT->TimedWait (1);
181 exit 1;
185 $Act->Kill();
186 $Act_status = $Act->TerminateWaitKill ($act->ProcessStopWaitInterval());
188 if ($Act_status != 0) {
189 print STDERR "ERROR: ImR_Activator returned $Act_status\n";
190 exit 1;
193 RunImRUtil("list -v");
195 RunImRUtil("shutdown MessengerService");
197 $ImR_status = $ImR->TerminateWaitKill ($imr->ProcessStopWaitInterval());
199 if ($ImR_status != 0) {
200 print STDERR "ERROR: ImplRepo Service returned $ImR_status\n";
201 $status = 1;
204 #### Clean up any output files
206 CleanupOutput();
208 exit $status;