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

# -*- perl -*-

# This is a Perl script that runs some Naming Service tests.
# It runs all the tests that will run with min CORBA.
# It starts all the servers and clients as necessary.

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

## Save the starting directory
$status = 0;
$multicast = '224.9.9.2';
$startdir = getcwd();

$quiet = 0;
$skip_mmap = 0;
$mt_only = 0;

foreach $i (@ARGV) {
    if ($i eq '-q') {
        $quiet = 1;
    }
    elsif ($i eq '-nommap') {
        $skip_mmap = 1;
    }
    elsif ($i eq '-mtonly') {
        $mt_only = 1;
    }
}

my $test = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";

# Variables for command-line arguments to client and server
# executables.
$ns_multicast_port = 10001 + $test->RandomPort(); # Can not be 10000 on Chorus 4.0
$ns_orb_port = 12000 + $test->RandomPort();

$iorfile = "ns.ior";
$persistent_ior_file = "pns.ior";
$persistent_log_file = "test_log";

$data_file = "test_run.data";

## Allow the user to determine where the persistent file will be located
## just in case the current directory is not suitable for locking.
## We can't change the name of the persistent file because that is not
## sufficient to work around locking problems for Tru64 when the current
## directory is NFS mounted from a system that does not properly support
## locking.
foreach my $possible ($ENV{TMPDIR}, $ENV{TEMP}, $ENV{TMP}) {
    if (defined $possible && -d $possible) {
      if (chdir($possible)) {
        last;
      }
    }
}

$test_log = $test->LocalFile ($data_file);
$test->DeleteFile ($data_file);

#Files which used by test
my $test_iorfile = $test->LocalFile ($iorfile);
my $test_persistent_log_file = $test->LocalFile ($persistent_log_file);
my $test_persistent_ior_file = $test->LocalFile ($persistent_ior_file);

$test->DeleteFile($persistent_ior_file);
$test->DeleteFile($iorfile);
$test->DeleteFile($persistent_log_file);

sub name_server
{
    my $args = "-ORBMulticastDiscoveryEndpoint $multicast:$ns_multicast_port -o $test_iorfile -m 1 @_";
    my $prog = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/tao_cosnaming";

    $SV = $test->CreateProcess ("$prog", "$args");

    $test->DeleteFile($iorfile);

    $SV->Spawn ();

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

    sleep(1);
}

sub client
{
    my $args = "@_"." ";
    my $prog = "$ENV{TAO_ROOT}/orbsvcs/tests/Simple_Naming/client";

    $CL = $test->CreateProcess ("$prog", "$args");

    $client_status = $CL->SpawnWaitKill ($test->ProcessStartWaitInterval() + 45);

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

}

## The options below have been reordered due to a
## initialization problem (within the Naming_Service)
## that has only been seen on Windows XP.

sub common_tests
{
    # Options for all simple tests recognized by the 'client' program.
    @opts = ("-s -ORBInitRef NameService=file://$test_iorfile",
             "-p $test_persistent_ior_file -ORBInitRef NameService=file://$test_iorfile",
             "-s -ORBInitRef NameService=mcast://$multicast:$ns_multicast_port\::/NameService",
             "-t -ORBInitRef NameService=file://$test_iorfile",
             "-i -ORBInitRef NameService=file://$test_iorfile",
             "-e -ORBInitRef NameService=file://$test_iorfile",
             "-y -ORBInitRef NameService=file://$test_iorfile",
             "-c file://$test_persistent_ior_file -ORBInitRef NameService=file://$test_iorfile",
        );

    $hostname = $test->HostName ();

    @server_opts = ("-t 30",
                    "-ORBEndpoint iiop://$hostname:$ns_orb_port -f $test_persistent_log_file",
                    "", "", "", "", "",
                    "-ORBEndpoint iiop://$hostname:$ns_orb_port -f $test_persistent_log_file",
        );

    @comments = ("Simple Test: \n",
                 "mmap() Persistent Test (Part 1): \n",
                 "Simple Test (using multicast to locate the server): \n",
                 "Tree Test: \n",
                 "Iterator Test: \n",
                 "Exceptions Test: \n",
                 "Destroy Test: \n",
                 "mmap() Persistent Test (Part 2): \n",
        );

    $test_number = 0;

    print "INFO: Running the test in ", getcwd(), "\n";

    # Run server and client for each of the tests.  Client uses ior in a
    # file to bootstrap to the server.
    foreach $o (@opts) {
        if (index($comments[$test_number],"mmap") != -1 && $skip_mmap == 1) {
            print STDERR "\n *** skipping ".$comments[$test_number];
        }
        else {
            name_server ($server_opts[$test_number]);
            print STDERR "\n          ".$comments[$test_number];
            client ($o);
            $SV->Kill ();
        }
        ## For some reason, only on Windows XP, we need to
        ## wait before starting another tao_cosnaming when
        ## the mmap persistence option is used
        if ($^O eq "MSWin32") {
            sleep(1);
        }
        $test_number++;
    }

    $test->DeleteFile($persistent_ior_file);
    $test->DeleteFile($persistent_log_file);
    $test->DeleteFile($iorfile);

}

sub mt_test ()
{
    # Now run the multithreaded test, sending output to the file.
    print STDERR "\n          Multithreaded Test:\n";
    $test->DeleteFile ($data_file);

    name_server ("");
    client ("-ORBInitRef NameService=file://$test_iorfile -ORBLogFile $test_log", "-m15");

    $SV->Kill ();

    $errors = system ("perl $startdir/process-m-output.pl $test_log 15") >> 8;

    if ($errors > 0) {
        $status = 1;

        if (!$quiet) {
            print STDERR "Errors Detected, printing output\n";
            if (open (DATA, "<$test_log")) {
                print STDERR "================================= Begin\n";
                print STDERR <DATA>;
                print STDERR "================================= End\n";
                close (DATA);
            }
            else {
                print STDERR "ERROR: Could not open $test_log\n";
            }
            $test->DeleteFile ($data_file);
        }
    }

    $test->DeleteFile($iorfile);
}

##############################################################################


common_tests () if (!$mt_only);
mt_test ();
exit $status;