summaryrefslogtreecommitdiff
path: root/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/run_test.pl
blob: ff8141814bb7bdfc2d56e49282abce49903afeff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
     & eval 'exec perl -S $0 $argv:q'
     if 0;

# $Id$
# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;


sub count_strings
{
   my $log_file = shift;
   my $find_str = shift;
   open my $fh, '<', $log_file or die $!;
   my $cnt=0;
   while (<$fh>)
   {
      $f = quotemeta($find_str);
      $cnt += $_ =~ /$f/;
   }
    print STDERR "INFO: Count - [$cnt]\n";
    close $fh;
    return($cnt);
}

sub test_1
{
# Test 1:
# This is a test for the creation of initial_pool_threads.
# The test will start up a server with default pool values
# and will result in 5 initial threads being started.

    my $server = shift;
    my $client = shift;
    my $iorbase = shift;
    my $deletelogs = shift;
    my $status = 0;

    print "\nRunning Test 1....\n";
    $test_num=1;

    my $lfname = "server_test" . $test_num . ".log";
    my $scname = "svc" . $test_num . ".conf";
    my $server_iorfile = $server->LocalFile ($iorbase);
    my $client_iorfile = $client->LocalFile ($iorbase);
    my $server_logfile = $server->LocalFile ($lfname);
    my $svc_conf = $server->LocalFile($scname);

    $server->DeleteFile($lfname);

    $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 3 -o $server_iorfile");
    $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s");

    $server_status = $SV->Spawn ();

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        exit 1;
    }

    if ($server->WaitForFileTimed ($iorbase,
                                   $server->ProcessStartWaitInterval()) == -1) {
        print STDERR "ERROR: cannot find file <$server_iorfile>\n";
        $SV->Kill (); $SV->TimedWait (1);
        exit 1;
    }

    $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval());
    if ($client_status != 0) {
        print STDERR "ERROR: client $i returned $client_status\n";
    }

     # Now find the spawned threads in the log file.

    $find_this="DTP_Task::svc() New thread created.";
    $found_cnt=0;

    my($found_cnt) = count_strings($server_logfile,$find_this);

    if ($found_cnt != 5) {
       print STDERR "ERROR: initial_pool_thread test failed w/$found_cnt instead of 5\n";
       $status = 1;
    }
    elsif ($deletelogs) {
        $server->DeleteFile($lfname);
      }

    $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        $status = 1;
    }

    $server->DeleteFile($iorbase);
    $client->DeleteFile($iorbase);

    return($status);
}

sub test_2
{
    # Test 2:
    # This is a test for showing a process maintaining a min_pool_threads after
    # the creation of initial_pool_threads is higher. This test will also
    # exercise the thread_idle_time (timeout).
    # The test will start up a server with 10 init_pool_threads and 5 min_pool_threads.
    # After 10 seconds, 5 threads should expire leaving the minimum 5 threads.


    my $server = shift;
    my $client = shift;
    my $iorbase = shift;
    my $deletelogs = shift;
    my $status = 0;


    print "\nRunning Test 2....\n";
    $test_num=2;
    my $lfname = "server_test" . $test_num . ".log";
    my $scname = "svc" . $test_num . ".conf";
    my $server_iorfile = $server->LocalFile ($iorbase);
    my $client_iorfile = $client->LocalFile ($iorbase);
    my $server_logfile = $server->LocalFile ($lfname);
    my $svc_conf = $server->LocalFile($scname);

    $server->DeleteFile($lfname);

    $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 3 -o $server_iorfile");
    $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s");

    $server_status = $SV->Spawn ();

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        exit 1;
    }

    if ($server->WaitForFileTimed ($iorbase,
                                   $server->ProcessStartWaitInterval()) == -1) {
        print STDERR "ERROR: cannot find file <$server_iorfile>\n";
        $SV->Kill (); $SV->TimedWait (1);
        exit 1;
    }

    # Sleep here for more than the timeout to let the threads die off and log.
    print STDERR "INFO: sleeping 15 seconds\n";
    sleep(15);

    $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval());
    if ($client_status != 0) {
        print STDERR "ERROR: client $i returned $client_status\n";
    }
     # Now find the spawned threads in the log file.

    $find_this="DTP_Task::svc() Existing thread expiring.";
    $found_cnt=0;

    my($found_cnt) = count_strings($server_logfile,$find_this);

    if ($found_cnt != 5) {
       print STDERR "ERROR: min_pool_thread test failed w/$found_cnt instead of 5\n";
       $status = 1;
    }
    elsif ($deletelogs) {
        $server->DeleteFile($lfname);
    }

    $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        $status = 1;
    }

    $server->DeleteFile($iorbase);
    $client->DeleteFile($iorbase);

    return($status);
}

sub test_3
{
    # Test 3:
    # This is a test for showing a process maintaining a max_request_queue_depth after
    # more clients request service than the queue allows for.
    # The test will start up a server with a max_request_queue_depth of 10 and
    # will issue calls from 15 clients. There should be 5 CORBA exceptions found
    # in the log after the run.
    #
    my $server = shift;
    my $client = shift;
    my $iorbase = shift;
    my $deletelogs = shift;
    my $status = 0;

    print "\nRunning Test 3....\n";
    $test_num=3;
    $num_clients=15;
    my $lfname = "server_test" . $test_num . ".log";
    my $scname = "svc" . $test_num . ".conf";
    my $server_iorfile = $server->LocalFile ($iorbase);
    my $client_iorfile = $client->LocalFile ($iorbase);
    my $server_logfile = $server->LocalFile ($lfname);
    my $svc_conf = $server->LocalFile($scname);

    $server->DeleteFile($lfname);

    $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 3 -o $server_iorfile");

    $server_status = $SV->Spawn ();

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        exit 1;
    }

    if ($server->WaitForFileTimed ($iorbase,
                                   $server->ProcessStartWaitInterval()) == -1) {
        print STDERR "ERROR: cannot find file <$server_iorfile>\n";
        $SV->Kill (); $SV->TimedWait (1);
        exit 1;
    }

    for ($i = 0; $i < $num_clients; $i++) {
        $CLS[$i] = $client->CreateProcess ("client", "-c $i -k file://$client_iorfile -e 0");
        $CLS[$i]->Spawn ();
    }

    my $valid_num_exceptions=5;
    my $num_exceptions=0;

    for ($i = 0; $i < $num_clients; $i++) {

        $client_status = $CLS[$i]->WaitKill ($client->ProcessStopWaitInterval());

        if ($client_status != 0) {
            $num_exceptions++;
            print STDERR "STATUS: client $i returned $client_status\n";
        }
    }

    $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s");
    $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval());
    if ($client_status != 0) {
        print STDERR "ERROR: client $i returned $client_status\n";
    }

    if ($num_exceptions != $valid_num_exceptions)
    {
      print STDERR "ERROR: max_request_queue_depth test failed w/$num_exceptions instead of $valid_num_exceptions\n";
      $status = 1;
    }
    elsif ($deletelogs) {
        $server->DeleteFile($lfname);
    }


    $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        $status = 1;
    }

    $server->DeleteFile($iorbase);
    $client->DeleteFile($iorbase);

    return($status);
}

sub test_4
{

    # Test 4:
    # This is a test for showing a process maintaining a max_pool_threads after
    # more clients request service than the queue allows for.
    # The test will start up a server with a max_request_queue_depth of 10 and
    # will issue calls from 10 clients. There should be 5 CORBA exceptions found
    # in the log after the run.
    #

    my $server = shift;
    my $client = shift;
    my $iorbase = shift;
    my $deletelogs = shift;
    my $status = 0;

    print "\nRunning Test 4....\n";
    $test_num=4;
    $num_clients=10;
    my $lfname = "server_test" . $test_num . ".log";
    my $scname = "svc" . $test_num . ".conf";
    my $server_iorfile = $server->LocalFile ($iorbase);
    my $client_iorfile = $client->LocalFile ($iorbase);
    my $server_logfile = $server->LocalFile ($lfname);
    my $svc_conf = $server->LocalFile($scname);

    $server->DeleteFile($lfname);

    $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 5 -o $server_iorfile");
    $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s");

    $server_status = $SV->Spawn ();

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        exit 1;
    }

    if ($server->WaitForFileTimed ($iorbase,
                                   $server->ProcessStartWaitInterval()) == -1) {
        print STDERR "ERROR: cannot find file <$server_iorfile>\n";
        $SV->Kill (); $SV->TimedWait (1);
        exit 1;
    }

    for ($i = 0; $i < $num_clients; $i++) {
        $CLS[$i] = $client->CreateProcess ("client", "-c $i -k file://$client_iorfile");
        $CLS[$i]->Spawn ();
    }


    for ($i = 0; $i < $num_clients; $i++) {

        $client_status = $CLS[$i]->WaitKill ($client->ProcessStopWaitInterval());

        if ($client_status != 0) {
            print STDERR "ERROR: client $i returned $client_status\n";
        }
    }

    $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval());

     # Now find the spawned threads in the log file.

    $find_this="Growing threadcount.";
    $found_cnt=0;
    $valid_cnt=4;

    my($found_cnt) = count_strings($server_logfile,$find_this);

    if ($found_cnt != $valid_cnt) {
       print STDERR "ERROR: max_pool_thread test failed w/$found_cnt instead of $valid_cnt\n";
       $status = 1;
    }
    elsif ($deletelogs) {
        $server->DeleteFile($lfname);
    }

    $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());

    if ($server_status != 0) {
        print STDERR "ERROR: server returned $server_status\n";
        $status = 1;
    }

  $server->DeleteFile($iorbase);
  $client->DeleteFile($iorbase);
  return($status);
}

my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
my $iorbase = "server.ior";
my $server_iorfile = $server->LocalFile ($iorbase);
my $client_iorfile = $client->LocalFile ($iorbase);
my $deletelogs = 1;

$server->DeleteFile($iorbase);
$client->DeleteFile($iorbase);

my $status = 0;

# Each test below will start up a server and optionally some clients.
# When a server gets a call it will sleep some number of seconds before responding.
# The -s parameter controls how many seconds it will sleep.
# The order is mandatory and must not contain spaces. It is defined as follows:
# min_pool_threads
# initial_pool_threads
# max_pool_threads
# thread_stack_size
# thread_timeout (in seconds)
# max_queue_request_depth

  while ()
  {
      $status = test_1($server, $client, $iorbase, $deletelogs);
      last if ($status);
      $status = test_2($server, $client, $iorbase, $deletelogs);
      last if ($status);
      $status = test_3($server, $client, $iorbase, $deletelogs);
      last if ($status);
      $status = test_4($server, $client, $iorbase, $deletelogs);
      last;
  }

$server->DeleteFile($iorbase);
$client->DeleteFile($iorbase);

exit $status;