Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / CSD_Strategy / ThreadPool5 / run_test.pl
blob468627fda05b2c3be1e27d33cd7c4c92712225c8
1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
3 if 0;
5 # -*- perl -*-
7 use lib "$ENV{ACE_ROOT}/bin";
8 use PerlACE::TestTarget;
10 $status = 0;
12 $iorfname_prefix = "server";
13 $num_servants=1;
14 $num_clients_per_servant=40;
15 $num_orb_threads=1;
16 $num_csd_threads=1;
17 $collocated_test=0;
18 $servant_cancellation_option="";
20 if ($ARGV[0] eq 'collocated') {
21 # 1 servant, 1 collocated client, 1 orb thread, 2 strategy working threads
22 $num_clients_per_servant=1;
23 $collocated_test=1;
24 $num_csd_threads=2;
26 elsif ($ARGV[0] eq 'multiple_servants') {
27 # multiple servants and single orb thread.
28 # 10 servant, 40 client, 1 orb thread, 10 strategy working threads
29 $num_servants=10;
30 $num_csd_threads=10;
31 $num_clients_per_servant=4;
33 elsif ($ARGV[0] eq 'multiple_orb_threads') {
34 # multiple servants and multiple orb threads.
35 # 10 servant, 40 client, 4 orb thread, 10 strategy working threads
36 $num_servants=10;
37 $num_csd_threads=10;
38 $num_clients_per_servant=4;
39 $num_orb_threads=4;
41 elsif ($ARGV[0] eq 'cancel_servant') {
42 # Cancel one servant and leave the other alive.
43 # 2 servant, 10 client, 5 orb thread, 1 strategy working threads
44 $num_clients_per_servant=5;
45 $num_servants=2;
46 $num_csd_threads=2;
47 $num_orb_threads=5;
48 $servant_cancellation_option = " -d 1 ";
50 elsif ($ARGV[0] eq '') {
51 # default test - 1 servant, 40 clients , 1 orb thread, 1 csd thread
53 else {
54 print STDERR "ERROR: invalid parameter $ARGV[0] \n";
55 exit 1;
58 $debug_level = '0';
60 foreach $i (@ARGV) {
61 if ($i eq '-debug') {
62 $debug_level = '10';
66 $num_clients = $num_servants * $num_clients_per_servant;
68 my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
70 $SV = $server->CreateProcess("server_main",
71 "-p $iorfname_prefix -s $num_servants ".
72 "-c $num_clients -t $num_orb_threads -n $num_csd_threads ".
73 "-l $collocated_test $servant_cancellation_option");
75 my @clients = ();
76 for ($i = 0; $i < $num_clients; $i++) {
77 $clients[$i] = PerlACE::TestTarget::create_target ($i+1) || die "Create target $i+1 failed\n";
80 #Delete old ior files.
81 my @iorfiles = ();
82 my @server_iorfiles = ();
83 for ($i = 0; $i < $num_servants; $i++) {
84 $servant_id = sprintf("%02d", ($i + 1));
85 $iorfiles[$i] = $iorfname_prefix . "_$servant_id.ior";
86 $server_iorfiles[$i] = $server->LocalFile($iorfiles[$i]);
87 $server->DeleteFile($iorfiles[$i]);
91 my @CLS = ();
92 my @clients_iorfile = ();
93 $count = 0;
94 for ($i = 0; $i < $num_servants; $i++) {
95 for ($j = 0; $j < $num_clients_per_servant; $j++) {
96 $clients_iorfile[$count] = $clients[$count]->LocalFile($iorfiles[$i]);
97 $clients[$count]->DeleteFile($iorfiles[$i]);
98 $CLS[$count] = $clients[$count]->CreateProcess ("client_main",
99 " -i file://$clients_iorfile[$count]");
100 $count ++;
104 $server_status = $SV->Spawn ();
106 if ($server_status != 0) {
107 print STDERR "ERROR: server returned $server_status\n";
108 exit 1;
111 # Wait for the servant ior files created by server.
112 for ($i = 0; $i < $num_servants; $i++) {
113 if ($server->WaitForFileTimed ($iorfiles[$i],
114 $server->ProcessStartWaitInterval()) == -1) {
115 print STDERR "ERROR: cannot find file <$server_iorfiles[$i]>\n";
116 $SV->Kill (); $SV->TimedWait (1);
117 exit 1;
121 for ($i = 0; $i < $num_servants; $i++) {
122 if ($server->GetFile ($iorfiles[$i]) == -1) {
123 print STDERR "ERROR: cannot retrieve $i-th file <$server_iorfiles[$i]>\n";
124 $SV->Kill (); $SV->TimedWait (1);
125 exit 1;
129 $count = 0;
130 for ($i = 0; $i < $num_servants; $i++) {
131 for ($j = 0; $j < $num_clients_per_servant; $j++) {
132 if ($clients[$count]->PutFile ($iorfiles[$i]) == -1) {
133 print STDERR "ERROR: client $count cannot set file <$clients_iorfile[$count]>\n";
134 $SV->Kill (); $SV->TimedWait (1);
135 exit 1;
137 $count ++;
141 $count = 0;
143 if ($collocated_test == 0) {
144 for ($i = 0; $i < $num_servants; $i++) {
145 for ($j = 0; $j < $num_clients_per_servant; $j++) {
146 my $client_status = $CLS[$count]->Spawn();
147 if ($client_status != 0) {
148 print STDERR "ERROR: client $count Spawn returned $client_status\n";
149 $status = 1;
151 $count ++;
155 for ($i = 0; $i < $num_clients; $i++) {
156 my $client_status = $CLS[$i]->WaitKill ($clients[$i]->ProcessStartWaitInterval() + 45);
158 if ($client_status != 0) {
159 print STDERR "ERROR: client $i WaitKill returned $client_status\n";
160 $status = 1;
165 $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval() + 45);
167 if ($server_status != 0) {
168 print STDERR "ERROR: server returned $server_status\n";
169 $status = 1;
173 #Delete ior files generated by this run.
174 for ($i = 0; $i < $num_servants; $i++) {
175 $server->DeleteFile($iorfiles[$i]);
178 $count = 0;
179 for ($i = 0; $i < $num_servants; $i++) {
180 for ($j = 0; $j < $num_clients_per_servant; $j++) {
181 $clients[$count]->DeleteFile($iorfiles[$i]);
182 $count++;
186 exit $status;