summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Event/Mcast/Two_Way/run_test.pl
blob: eac3e3f580f82c5c89284286976a17ee57379ac5 (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
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

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

# This is a Perl script that runs Simple EC Mcast example.  It starts
# consumer, supplier and two (federated) Event Channel servers.
# See README for more details.

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

$status = 0;

# Configuration parameters

# Number of Event Channel/Application pairs that will be started up.
my $apps_number = 3;

$test = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
$test->AddLibPath ("../Common");
# Variables for command-line arguments to client and server executables.
my $ec_ior  = "ec.ior";
my $gw_conf = "gateway.conf";

my $rundate = POSIX::strftime("%Y_%m_%d_%H_%M", localtime);
my @test_results = ();
for ($i = 0; $i < 2*$apps_number; $i++) {
    $test_results[$i] = $test->LocalFile ("run_test_".$i.$rundate);
}

my $test_gw_conf = $test->LocalFile ($gw_conf);
my $test_ec_ior = $test->LocalFile ($ec_ior);
$test->DeleteFile ($ec_ior);

my @ps = ();

sub run_test {
    for ($i = 0; $i < $apps_number; $i++) {
        $test->DeleteFile ($ec_ior.$i);
    }

    # Start federated Event Channels.
    for ($i = 0; $i < $apps_number; $i++) {
        if (run_ec ($i) != 0) {
            kill_processes ();
            return -1;
        }
    }

    # Start EC clients.
    for ($i = 0; $i < $apps_number; $i++) {
        my $ps_index = $apps_number + $i;
        $ps[$ps_index] = $test->CreateProcess ("application", "-ORBLogFile $test_results[$ps_index] -d ".
                                               "-ORBInitRef Event_Service=file://$test_ec_ior.$ps_index");
        if ($ps[$ps_index]->Spawn () == -1) {
            print STDERR "ERROR detected clients Spawn\n";
            kill_processes ();
            return -1;
        }
    }

    # Shutdown.
    $status = wait_kill_processes ();

    for ($i = 0; $i < $apps_number; $i++) {
        $test->DeleteFile ($ec_ior.$i);
    }

    return $status;
}

# Start Event Channel server.
sub run_ec {
    my $id = $_[0];
    my $ior_file = $test_ec_ior.$id;
    my $ior = $ec_ior.$id;

    $ps[$id] = $test->CreateProcess ("gateway-ec", "-ORBLogFile $test_results[$id] ".
                                                   "-ORBsvcconf $test_gw_conf -i $ior_file");
    if ($ps[$id]->Spawn () == -1) {
        print STDERR "ERROR detected channels Spawn\n";
        return 1;
    }

    if ($test->WaitForFileTimed ($ior, $test->ProcessStartWaitInterval()) == -1) {
        print STDERR "ERROR: cannot find IOR file <$ior_file>\n";
        $ps[$id]->Kill (); $ps[$id]->TimedWait (1);
        return 1;
    }

    return 0;
}

# Wait for and kill, if necessary, all started processes.
sub wait_kill_processes
{
    my $result = 0;
    foreach $p (@ps) {
        if ($p->WaitKill ($test->ProcessStopWaitInterval() + 45) != 0) {
            print STDERR "ERROR detected\n";
            $result = 1;
        }
    }

    return 0;
}

sub kill_processes
{
    foreach $p (@ps) {
        $p->Kill (); $p->TimedWait (1);
    }

    return 0;
}

sub analyze_results {
    my $filename = @$_[0];
    if (! open (TEST_OUTPUT, "<$filename")) {
        print STDERR "ERROR: Could not open $filename\n";
        return -1;
    }
    
    my $status = 0;
    while (<TEST_OUTPUT>) {
        if (m/total of/) {
            chomp $_;
            my @words = split (/ /, $_);
            my $pid = $words[3];
            my $h = $words[7];
            $heartbeats{$pid} += $h;
        }
        elsif (m/Received following heartbeats/) {
            #skip this line - we do our own counting.
        }
        else {
            $status = -1;
            print STDERR $_;
        }
    }
    close (TEST_OUTPUT);
    
    foreach $pid (keys %heartbeats) {
        my $ideal_heartbeats = $apps_number * 50;
        my $received_heartbeats = $heartbeats{$pid};
        my $in_range = (($ideal_heartbeats - $received_heartbeats)
                        <= $number_of_applications);
        my $range_note = " (";
        if (! $in_range) {
            $range_note .= "NOT ";
            $status = -1;
        }
        $range_note.=
            "within range of $number_of_applications from $ideal_heartbeats)";
        print STDERR
            "Received $received_heartbeats heartbeats from pid $pid";
        print STDERR "$range_note\n";
    }

    if ($status == 0) {
        print STDERR "SUCCESS\n";
        return 0;
    }
 
    print STDERR "ERROR - check $filename for full output.\n";
    return -1;
}

##############################################################
# Run executables.
##############################################################

if (run_test () == -1) {
    $status = 1;
}

for ($i = 0; $i < 2*$apps_number; $i++) {
    if (analyze_results ($test_results[$i]) == -1) {
        $status = 1;
    }
}

exit $status;