summaryrefslogtreecommitdiff
path: root/trunk/TAO/orbsvcs/examples/ImR/Advanced/run_test.pl
blob: 0025c8d1fc961e2492cc164e5824aca923134b6e (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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
##$Id$
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# This test currently does not perform
#    ImplRepo_Service -m (multicast)
#    ImplRepo_Service -l (loack database)
#    ImplRepo_Service -c (install/remove Windows service)
#    tao_imr shutdown -l hostname (shutdown servers on a specific host)
#    tao_imr shutdown_repo (shutting down ImplRepo_Service via tao_imr)

#use strict;
use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::Run_Test;
use Sys::Hostname;
use File::Spec;
use Getopt::Long;


# Initialize variables
my %TestParams;
my $IMPL_IOR = "-ORBInitRef ImplRepoService=file://implrepo.ior";
my $ENV_CMD;
my $IMR_CMD;
my $ACT_CMD;
my $IOR_CMD;
my $SERVER_CMD;
my $CLIENT_CMD;
my $MGR;
my $IMPL;
my $ACT;
my $SERVER;

# Get command line params
$TestParams{file} = "./drivers/all";
GetOptions("file|f=s" => \$TestParams{file});
parse_file();

# Open the Param file and run the tests within
sub parse_file
{
    my $fh;
    my $file = $TestParams{file};

    my $disabled_block = 0;
    if (open($fh, $file))
    {
        while (<$fh>)
        {
            my $line = $_;
            $line =~ s/\s+$//;

            # If the line is negated, ignore it
            if ($line =~ /^--/)
            {
                $disabled_block = ! ($disabled_block);
            }

            elsif ($disabled_block == 0)
            {
                # If the line is negated, ignore it
                if ($line =~ /^-/)
                {
                }

                # If the line is a comment, print it
                elsif ($line =~ /^#/)
                {
                    print "$line\n";
                }

                # Start defining an execution
                elsif ($line =~ /^begin/)
                {
                    $TestParams{file} = "./drivers/defaults";
                    parse_file();
                }

                # Parse a new file
                elsif ($line =~ /^run (\w+)/)
                {
                    $TestParams{file} = "./drivers/$1";
                    parse_file();
                }

                # Acquire parameter
                elsif ($line =~ /(\w+)=(.*)/)
                {
                    &acquire_param($1, $2);
                }

                # Execute a single line
                elsif ($line =~ /^do (\w+)/)
                {
                    my $methodRef = $1;
                    &$methodRef(); #how do I do this in the strict mode?
                }
            }
        }
    }
}

sub invoke_stats()
{
    my $IORS = ($TestParams{server_poas} * $TestParams{server_poa_objs});
    my $THREAD_REQ = ($TestParams{client_iterations} * $IORS * $TestParams{client_requests});
    my $TOTAL_REQ = ($TestParams{client_threads} * $THREAD_REQ);
    
    my $RAND_MSG = "";
    if ($TestParams{client_rand_req} ne "0")
    {
        $RAND_MSG = "(max random)";
    }
    print "* Invocation Stats\n";
    print "* POAs:               $TestParams{server_poas}\n";
    print "* Obj/POA:            $TestParams{server_poa_objs}\n";
    print "* IORs:               $IORS\n";
    print "* Threads:            $TestParams{client_threads}\n";
    print "* Iterations/Thread:  $TestParams{client_iterations}\n";
    print "* Requests/Thread:    $THREAD_REQ $RAND_MSG\n";
    print "* Total Requests:     $TOTAL_REQ $RAND_MSG\n";
}

sub start_imr
{
    generateCommands();

    # Start the manager
    unlink "manager.ior";
    $MGR = new PerlACE::Process("manager_main", "-r $TestParams{activate_retry}");
    $MGR->Spawn();
    PerlACE::waitforfile_timed("manager.ior", 10);

    if ($TestParams{imr_on} eq "1")
    {
        # Start the IMR Service
        unlink "implrepo.ior";
        $IMPL = new PerlACE::Process(
                    "$PerlACE::TAO_ROOT/orbsvcs/ImplRepo_Service/ImplRepo_Service", 
                    $IMR_CMD);
        $IMPL->Spawn();
        PerlACE::waitforfile_timed("implrepo.ior", 10);
    }
}

sub kill_imr
{
    if ($TestParams{imr_on} eq "1")
    {
        if ($TestParams{imr_shutdown} ne "0")
        {
            my $tool_params = "$IMPL_IOR shutdown-repo";
            if ($TestParams{imr_shutdown} eq "2" && $TestParams{activate_mode} ne "")
            {
              $tool_params = "$tool_params -a";
            }

            my $TOOL = new PerlACE::Process("$PerlACE::ACE_ROOT/bin/tao_imr", $tool_params);
            $TOOL->IgnoreExeSubDir(1);
            $TOOL->SpawnWaitKill(5);
            
            # test $IMPL
            if ($TestParams{imr_shutdown} eq "2" && $TestParams{activate_mode} ne "")
            {
              $ACT->WaitKill(5);
              print "* Activator Killed.\n";
            }
            $IMPL->WaitKill(5);
        }
        else
        {
            $IMPL->TerminateWaitKill(1);
        }
        print "* IMR Killed.\n";
    }

    my $TEMP_SERV = new PerlACE::Process("server_main", "-q 1 -x 0");
    $TEMP_SERV->SpawnWaitKill(5);
    $MGR->Kill();
}

# write_iors
# creates the IORS for all the objects the client will invoke
# The POAs will be temporarely registered with the IMR.
sub write_iors
{
    generateCommands();
    unlink "imr_test.ior";
    if ($TestParams{activate_mode} eq "per_client")
    {
        # Run a single fake server for every POA
        for (my $i = 1; $i <= $TestParams{server_poas}; $i++)
        {
            my $TEMP_SERV = new PerlACE::Process("server_main", "$IOR_CMD -p 1 -d " . $i);
            $TEMP_SERV->SpawnWaitKill(5);
        }
        print "* IORs Written\n";
    }
    elsif ($TestParams{activate_mode} ne "")
    {
        # Run a single fake server for all POAs
        my $TEMP_SERV = new PerlACE::Process("server_main", "$IOR_CMD -d 1 -p $TestParams{server_poas}");
        $TEMP_SERV->SpawnWaitKill(5);
        PerlACE::waitforfile_timed("imr_test.ior", 10);
        print "* IORs Written\n"; 
    }
    else
    {
        # Without an activator, the server will write the IORs when manually launched
    }
}

sub start_activator
{
    if ($TestParams{activate_mode} ne "")
    {
        generateCommands();

        # Start the Activator
        unlink "activator.ior";
        $ACT = new PerlACE::Process(
                "$PerlACE::TAO_ROOT/orbsvcs/ImplRepo_Service/ImR_Activator", 
                $ACT_CMD);
        $ACT->Spawn();
        PerlACE::waitforfile_timed("activator.ior", 5);
    }
}

sub kill_activator()
{
    if ($TestParams{activate_mode} ne "")
    {
        if ($TestParams{imr_shutdown} ne "2")
        {
            $ACT->TerminateWaitKill(1);
            print "* Activator Killed.\n";
        }
    }
}

# activator_list
# Lists the known servers
sub activator_list()
{
    my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR list -v");
    $TOOL->IgnoreExeSubDir(1);
    $TOOL->SpawnWaitKill(5);
    
    # TODO: parse output and check values
}

# register_server
# Makes the activator know about the server
# Does nothing for the no-activator mode
sub register_server()
{
    if ($TestParams{activate_mode} eq "per_client")
    {
        # Register a single POA for each server
        generateCommands();
        my $actname = hostname;
        for (my $i = 1; $i <= $TestParams{server_poas}; $i++)
        {
            my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR $TestParams{registration_type} POA_".$i."_1 -c \"server_main $SERVER_CMD -d ".$i." -p 1\" -a $TestParams{activate_mode} -r $TestParams{activate_retry} -l $actname $ENV_CMD");
            $TOOL->IgnoreExeSubDir(1);
            $TOOL->SpawnWaitKill(5);
        }
    }
    elsif ($TestParams{activate_mode} ne "")
    {
        # Register only the first POA for our server
        # The remaining POAs will auto-register when the server is started
        generateCommands();
        my $actname = hostname;
        my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR $TestParams{registration_type} POA_1_1 -c \"server_main $SERVER_CMD -d 1 -p $TestParams{server_poas}\" -a $TestParams{activate_mode} -r $TestParams{activate_retry} -l $actname $ENV_CMD");
        $TOOL->IgnoreExeSubDir(1);
        $TOOL->SpawnWaitKill(5);
    }
    else
    {
        # nothing to register without an activator
    }
}

sub unregister_server()
{
    if ($TestParams{activate_mode} eq "per_client")
    {
        # Register a single POA for each server
        generateCommands();
        my $actname = hostname;
        for (my $i = 1; $i <= $TestParams{server_poas}; $i++)
        {
            my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR remove POA_".$i."_1");
            $TOOL->IgnoreExeSubDir(1);
            $TOOL->SpawnWaitKill(5);
        }
    }
    elsif ($TestParams{activate_mode} ne "")
    {
        # Register only the first POA for our server
        # The remaining POAs will auto-register when the server is started
        generateCommands();
        my $actname = hostname;
        my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR remove POA_1_1");
        $TOOL->IgnoreExeSubDir(1);
        $TOOL->SpawnWaitKill(5);
    }
    else
    {
        # nothing is registered without an activator
    }
}


# start_server
# This method is called before the client is luanched.
# It only launches the server for the two manual modes (no-act and manual-act).
sub start_server()
{
    if ($TestParams{activate_mode} eq "")
    {
        generateCommands();
        $SERVER = new PerlACE::Process("server_main", "$SERVER_CMD -d 1 -o 1 -p $TestParams{server_poas}");
        $SERVER->Spawn();
        PerlACE::waitforfile_timed("imr_test.ior", 10);
    }
    elsif ($TestParams{activate_mode} eq "manual")
    {
        activate_server();
    }
    else
    {
        # The server will be launched by the ImR or Client
    }
}

# Activate Server
# This method is an alternative way to start the server.
# It will activate the servers regardless of mode.
sub activate_server
{
    if ($TestParams{activate_mode} eq "per_client")
    {
        # Register a single POA for each server
        generateCommands();
        my $actname = hostname;
        for (my $i = 1; $i <= $TestParams{server_poas}; $i++)
        {
            my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR activate POA_".$i."_1");
            $TOOL->IgnoreExeSubDir(1);
            $TOOL->SpawnWaitKill(5);
        }
    }
    elsif ($TestParams{activate_mode} ne "")
    {
        # Register only the first POA for our server
        # The remaining POAs will auto-register when the server is started
        generateCommands();
        my $actname = hostname;
        my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR activate POA_1_1");
        $TOOL->IgnoreExeSubDir(1);
        $TOOL->SpawnWaitKill(5);
    }
    else # No activator
    {
        start_server();
    }
}

# kill server
# This method is called when the services of the server are no longer required.
# per_client does nothing.
sub kill_server()
{
    if ($TestParams{activate_mode} eq "per_client")
    {
        # clients do this
    }
    elsif ($TestParams{activate_mode} ne "")
    {
        # Kill the single server
        my $TOOL = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr", "$IMPL_IOR shutdown POA_1_1");
        $TOOL->SpawnWaitKill(5);
    }
    else
    {
        $SERVER->Kill();
        print "* Server Killed.\n";
    }
}

# launch_client
# This method spawns the client and blocks until the client is done
sub launch_client
{
    generateCommands();
    if ($TestParams{activate_mode} eq "per_client")
    {
        my $CLIENT = new PerlACE::Process("client_main", "$CLIENT_CMD -x 1");
        $CLIENT->SpawnWaitKill(500);
    }
    else
    {
        my $CLIENT = new PerlACE::Process("client_main", "$CLIENT_CMD");
        $CLIENT->SpawnWaitKill(500);
    }
}

# Private methods

# acquire_param
# Transforms certain parameters into usable forms
sub acquire_param
{
    $TestParams{$_[0]} = $_[1];

    if ($_[0] eq "imr_persistence")
    {
        if ($TestParams{imr_persistence} eq "registry")
        {
            $TestParams{imr_persistence} = "-r";
        }
        elsif ($TestParams{imr_persistence} eq "binary")
        {
            $TestParams{imr_persistence} = "-p imr_persist";
        }
        elsif ($TestParams{imr_persistence} eq "XML")
        {
            $TestParams{imr_persistence} = "-x imr_persist";
        }
    }

    elsif ($_[0] eq "imr_persistence_clear")
    {
        if ($TestParams{imr_persistence_clear} eq "1")
        {
            $TestParams{imr_persistence_clear} = "-e";
        }
        else
        {
            $TestParams{imr_persistence_clear} = "";
        }
    }

    elsif ($_[0] eq "server_ref_style" && $TestParams{server_ref_style} ne "")
    {
        $TestParams{server_ref_style} = "-ORBObjRefStyle $TestParams{server_ref_style}";
    }
    
    elsif ($_[0] eq "client_rand_req" && $TestParams{client_rand_req} eq "1")
    {
        $TestParams{client_rand_req} = "r";
    }

    elsif ($_[0] eq "client_holding" && $TestParams{client_holding} eq "1")
    {
        $TestParams{client_holding} = "h";
    }

    elsif ($_[0] eq "client_noprofile" && $TestParams{client_noprofile} eq "1")
    {
        $TestParams{client_noprofile} = "n";
    }
}

# generateCommands
# Create common cammand line sets
sub generateCommands
{
    $ENV_CMD = "";
    for (my $i = 0; $i < $TestParams{env_varnum}; $i++)
    {
        $ENV_CMD = "$ENV_CMD -e Name_" . $i . "=Value_" . $i . " ";
    }

    if ($TestParams{env_dir} ne "")
    {
        $ENV_CMD = "$ENV_CMD -w " . File::Spec->rel2abs($TestParams{env_dir}) . " ";
    }

    $IMR_CMD    = "-o implrepo.ior "
                . "$TestParams{imr_persistence} "
                . "$TestParams{imr_persistence_clear} "
                . "-ORBEndPoint $TestParams{imr_endpoint} "
                . "-d $TestParams{imr_debug_level} "
                . "-v $TestParams{imr_ping_interval} "
                . "-t $TestParams{imr_startup_timeout} ";

    $ACT_CMD    = "$IMPL_IOR -o activator.ior -d $TestParams{imr_debug_level}";

    $SERVER_CMD = "-ORBUseIMR $TestParams{imr_on} $IMPL_IOR "
                . "$ENV_CMD "
                . "$TestParams{server_ref_style} "
                . "-b " . File::Spec->rel2abs(".") . " "
                . "-t $TestParams{server_ior_table} "
                . "-z $TestParams{env_pause_type} "
                . "-s $TestParams{server_start_pause} "
                . "-c $TestParams{server_obj_act_pause} "
                . "-a $TestParams{server_activate_pause} "
                . "-r $TestParams{server_run_pause} "
                . "-n $TestParams{server_poa_objs} "
                . "-x $TestParams{server_hit_time_min} ";

    $CLIENT_CMD = "-z $TestParams{env_pause_type} "
                . "-s $TestParams{client_start_pause} "
                . "-t $TestParams{client_threads} "
                . "-i $TestParams{client_iterations} "
                . "-r $TestParams{client_rand_req}$TestParams{client_requests} "
                . "-e $TestParams{client_holding}$TestParams{client_noprofile} ";

    $IOR_CMD    = "-ORBUseIMR $TestParams{imr_on} $IMPL_IOR "
                . "$TestParams{server_ref_style} "
                . "-b " . File::Spec->rel2abs(".") . " "
                . "-t $TestParams{server_ior_table} "
                . "-n $TestParams{server_poa_objs} "
                . "-z s -s 100 -o 1 -x 0 " # sleep 100, write iors, and exit
}