summaryrefslogtreecommitdiff
path: root/ACE/TAO/orbsvcs/DevGuideExamples/ImplRepo/Basic/run_test.pl
blob: 258d9c09ff0113c1493590d81c491e1d91f081b4 (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
# $Id$

eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

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

$status = 0;
$debug_level = '0';

foreach $i (@ARGV) {
    if ($i eq '-debug') {
        $debug_level = '10';
    }
}

my $srv = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
my $cli = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
my $imr = PerlACE::TestTarget::create_target (3) || die "Create target 3 failed\n";

my $WAIT_TIMEOUT = 2;
my $DEBUG_LEVEL = 1;
my $OBJ_REF_STYLE = "-orbobjrefstyle url";

my $implrepo_server = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImplRepo_Service";

my $implrepo_ior = "imr.ior";
my $messenger_ior = "messenger.ior";

my $imr_imriorfile = $imr->LocalFile ($implrepo_ior);
my $srv_imriorfile = $srv->LocalFile ($implrepo_ior);
my $srv_srviorfile = $srv->LocalFile ($messenger_ior);
my $cli_srviorfile = $cli->LocalFile ($messenger_ior);

$Srv = $srv->CreateProcess ("MessengerServer", "-ORBdebuglevel $debug_level ".
                                               "-orbuseimr 1 ".
                                               "$OBJ_REF_STYLE ".
                                               "-ORBInitRef ImplRepoService=file://$srv_imriorfile");
$Cli = $cli->CreateProcess ("MessengerClient", "-k file://$cli_srviorfile");

sub CleanupOutput {
    $imr->DeleteFile ($implrepo_ior);
    $srv->DeleteFile ($implrepo_ior);
    $srv->DeleteFile ($messenger_ior);
    $cli->DeleteFile ($messenger_ior);
}

# Use url object reference style for readability, and startup timeout of 2 seconds.
# Unlike the chapter we'll forgo using -m, because we want to be able to run this
# as a test in our nightly builds, and multicast could interfere with other machines.
$ImR = $imr->CreateProcess ($implrepo_server, "-d $DEBUG_LEVEL ".
                                               "$OBJ_REF_STYLE ".
                                               "-t 2 ".
                                               "-o $imr_imriorfile");

CleanupOutput();

#### Start the example
print ">>> " . $ImR->CommandLine() . "\n";
$ImR_status = $ImR->Spawn ();

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

if ($imr->WaitForFileTimed ($implrepo_ior,$imr->ProcessStartWaitInterval()) == -1) {
    print STDERR "ERROR: cannot find file <$imr_imriorfile>\n";
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}

if ($imr->GetFile ($implrepo_ior) == -1) {
    print STDERR "ERROR: cannot retrieve file <$imr_imriorfile>\n";
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}
if ($srv->PutFile ($implrepo_ior) == -1) {
    print STDERR "ERROR: cannot set file <$srv_imriorfile>\n";
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}

print ">>> " . $Srv->CommandLine() . "\n";
$Srv_status = $Srv->Spawn ();

if ($Srv_status != 0) {
    print STDERR "ERROR: Server returned $Srv_status\n";
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}

if ($srv->WaitForFileTimed ($messenger_ior,$srv->ProcessStartWaitInterval()) == -1) {
    print STDERR "ERROR: cannot find file <$srv_srviorfile>\n";
    $Srv->Kill (); $Srv->TimedWait (1);
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}

if ($srv->GetFile ($messenger_ior) == -1) {
    print STDERR "ERROR: cannot retrieve file <$srv_srviorfile>\n";
    $Srv->Kill (); $Srv->TimedWait (1);
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}
if ($cli->PutFile ($messenger_ior) == -1) {
    print STDERR "ERROR: cannot set file <$cli_srviorfile>\n";
    $Srv->Kill (); $Srv->TimedWait (1);
    $ImR->Kill (); $ImR->TimedWait (1);
    exit 1;
}

$Cli_status = $Cli->SpawnWaitKill ($cli->ProcessStartWaitInterval());
if ($Cli_status != 0) {
    print STDERR "ERROR: Client failed to run correctly. Client returned $Cli_status\n";
    $status = 1;
}

$Srv_status = $Srv->TerminateWaitKill ($srv->ProcessStopWaitInterval());

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

$ImR_status = $ImR->TerminateWaitKill ($imr->ProcessStopWaitInterval());

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

#### Clean up any output files

CleanupOutput();

exit $status;