1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
7 use lib
"$ENV{ACE_ROOT}/bin";
8 use PerlACE
::TestTarget
;
12 my $redirection_enabled = 0;
21 #$ENV{ACE_TEST_VERBOSE} = "1";
23 my $server = PerlACE
::TestTarget
::create_target
(1) || die "Create target 1 failed\n";
24 my $client = PerlACE
::TestTarget
::create_target
(2) || die "Create target 2 failed\n";
26 ## The LoadManager needs to register signals with the ORB's reactor (on
27 ## Windows only) and thus can not use the TP Reactor since it doesn't
28 ## support that kind of thing. So, we swith to the Select MT Reactor.
29 my $NM_conf = $server->LocalFile ("windows" . $PerlACE::svcconf_ext
);
31 my $name_mgr_iorbase = "nm.ior";
32 my $name_srv_iorbase = "ns.ior";
33 my $stdout_file = "test.out";
34 my $stderr_file = "test.err";
36 my $server_hostname = $server->HostName ();
37 my $name_mgr_iorfile = $server->LocalFile ($name_mgr_iorbase);
38 my $name_server_iorfile = $server->LocalFile ($name_srv_iorbase);
40 my $naming_mgr_client_iorfile = $client->LocalFile ($name_mgr_iorbase);
41 my $name_srv_client_iorfile = $client->LocalFile ($name_srv_iorbase);
42 my $client_stdout_file = $client->LocalFile ($stdout_file);
43 my $client_stderr_file = $client->LocalFile ($stderr_file);
45 $server->DeleteFile($name_mgr_iorbase);
46 $server->DeleteFile($name_srv_iorbase);
47 $client->DeleteFile($name_mgr_iorbase);
48 $client->DeleteFile($name_srv_iorbase);
49 $client->DeleteFile($stdout_file);
50 $client->DeleteFile($stderr_file);
52 my $DEBUG_LEVEL = "-ORBDebugLevel $debug_level";
53 my $hostname = $server->HostName ();
54 my $ns_orb_port1 = 10001 + $server->RandomPort ();
55 my $ns_endpoint1 = "iiop://$hostname:$ns_orb_port1";
57 my $DEF_REF = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port1";
58 #my $NM_REF = "-ORBInitRef NameService=file://$name_srv_client_iorfile";
59 #my $RM_REF = "-ORBInitRef NamingManager=file://$naming_mgr_client_iorfile";
60 my $NS_REF = "--ns file://$name_srv_client_iorfile";
61 my $LOAD_ARG = "$DEF_REF $DEBUG_LEVEL";
63 my $tao_ft_naming = "$ENV{TAO_ROOT}/orbsvcs/FT_Naming_Service/tao_ft_naming";
64 my $name_dir = "NameService";
65 my $group_dir = "Groups";
66 my $ns_args = "$DEBUG_LEVEL " .
67 "-ORBListenEndPoints $ns_endpoint1 " .
68 "-h $name_mgr_iorbase " .
69 "-o $name_srv_iorbase " .
72 ($^O
eq 'MSWin32' ?
"-ORBSvcConf $NM_conf" : '');
74 my $NM = $server->CreateProcess ($tao_ft_naming, $ns_args);
75 my $NSGROUP = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsgroup");
76 my $NSLIST = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nslist");
77 my $NSADD = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsadd");
78 my $NSDEL = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsdel");
80 my $POSITIVE_TEST_RESULT = 0;
81 my $NEGATIVE_TEST_RESULT = 1;
83 sub clean_persistence_dir
($$)
86 my $directory_name = shift;
88 chdir $directory_name;
89 opendir(THISDIR
, ".");
90 @allfiles = grep(!/^\.\.?$/, readdir(THISDIR
));
92 foreach $tmp (@allfiles){
93 $target->DeleteFile ($tmp);
98 # Make sure that the directory to use to hold the persistence data
99 # exists and is cleaned out.
100 sub init_persistence_directory
($$)
103 my $directory_name = shift;
105 if ( ! -d
$directory_name ) {
106 mkdir ($directory_name, 0777);
108 clean_persistence_dir
($target, $directory_name);
114 my $file_name = shift;
115 if (-s
$file_name ) # size of file is greater than zero
117 open TESTFILE
, $file_name or die "Couldn't open file: $!";
118 my @teststring = <TESTFILE
>; # read in all of the file
119 print STDERR
"\n@teststring\n";
124 sub redirect_output
()
126 open(OLDOUT
, ">&", \
*STDOUT
) or die "Can't dup STDOUT: $!";
127 open(OLDERR
, ">&", \
*STDERR
) or die "Can't dup STDERR: $!";
128 open STDERR
, '>', $client_stderr_file;
129 open STDOUT
, '>', $client_stdout_file;
134 open(STDERR
, ">&OLDERR") or die "Can't dup OLDERR: $!";
135 open(STDOUT
, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
141 my $expected_test_result = shift;
143 my $arglist = "$LOAD_ARG $args";
145 if ($expected_test_result != $POSITIVE_TEST_RESULT ) {
146 print STDERR
"\n\n======== Running Negative Test ================\n";
148 print STDERR
"\n\n======== Running Positive Test ================\n";
150 print STDERR
"$args\n";
152 $NSGROUP->Arguments ($arglist);
154 if ($redirection_enabled) {
158 my $client_status = $NSGROUP->SpawnWaitKill ($client->ProcessStartWaitInterval());
160 if ($redirection_enabled) {
165 if ($client_status != $expected_test_result) {
166 my $time = localtime;
167 print STDERR
"ERROR: client returned $client_status at $time\n";
168 if ($redirection_enabled) {
169 cat_file
($client_stderr_file);
170 cat_file
($client_stdout_file);
178 print STDERR
"\n\n======== Running tao_nsadd ================\n";
180 $NSADD->Arguments ($args);
182 if ($redirection_enabled) {
186 #tao_nsadd --ns file://ns.ior --name iso --ctx
187 my $client_status = $NSADD->SpawnWaitKill ($client->ProcessStartWaitInterval());
189 if ($redirection_enabled) {
193 if ($client_status != $0) {
194 my $time = localtime;
195 print STDERR
"ERROR: nsadd returned $client_status at $time\n";
196 if ($redirection_enabled) {
197 cat_file
($client_stderr_file);
205 print STDERR
"\n\n======== Running tao_nsdel ================\n";
207 $NSDEL->Arguments ($args);
209 if ($redirection_enabled) {
213 #tao_nsdel --ns file://ns.ior --name iso --destroy
214 my $client_status = $NSDEL->SpawnWaitKill ($client->ProcessStartWaitInterval());
216 if ($redirection_enabled) {
220 if ($client_status != $0) {
221 my $time = localtime;
222 print STDERR
"ERROR: nsdel returned $client_status at $time\n";
223 if ($redirection_enabled) {
224 cat_file
($client_stderr_file);
232 print STDERR
"\n\n======== Running tao_nslist ================\n";
234 $NSLIST->Arguments ($args);
236 if ($redirection_enabled) {
240 #tao_nslist --ns file://ns.ior
241 my $client_status = $NSLIST->SpawnWaitKill ($client->ProcessStartWaitInterval());
243 if ($redirection_enabled) {
247 if ($client_status != $0) {
248 my $time = localtime;
249 print STDERR
"ERROR: nslist returned $client_status at $time\n";
250 if ($redirection_enabled) {
251 cat_file
($client_stderr_file);
261 $POSITIVE_TEST_RESULT);
264 "group_create -group ieee -policy round",
265 $POSITIVE_TEST_RESULT);
268 "group_create -group ieed -policy random",
269 $POSITIVE_TEST_RESULT);
272 "group_create -group ieec -policy least",
273 $NEGATIVE_TEST_RESULT);
276 "group_create -group ieee -policy round",
277 $NEGATIVE_TEST_RESULT);
281 $POSITIVE_TEST_RESULT);
284 "member_list -group ieee",
285 $POSITIVE_TEST_RESULT);
288 "member_add -group ieee -location $server_hostname -ior file://$naming_mgr_client_iorfile",
289 $POSITIVE_TEST_RESULT);
292 "member_list -group ieee",
293 $POSITIVE_TEST_RESULT);
295 run_nsadd
("$DEF_REF"." --name iso --ctx");
297 run_nslist
("$NS_REF");
300 "group_unbind -name iso/ieee",
301 $NEGATIVE_TEST_RESULT);
303 run_nslist
("$NS_REF");
306 "group_bind -group ieee -name iso/ieee",
307 $POSITIVE_TEST_RESULT);
309 run_nslist
("$NS_REF");
312 "member_add -group ieee -location $server_hostname -ior file://$naming_mgr_client_iorfile",
313 $NEGATIVE_TEST_RESULT);
316 "member_list -group ieee",
317 $POSITIVE_TEST_RESULT);
320 "member_show -group ieee -location $server_hostname",
321 $POSITIVE_TEST_RESULT);
324 "member_remove -group ieee -location $server_hostname",
325 $POSITIVE_TEST_RESULT);
328 "member_list -group ieee",
329 $POSITIVE_TEST_RESULT);
332 "group_remove -group ieee",
333 $POSITIVE_TEST_RESULT);
336 "group_unbind -name iso/ieee",
337 $POSITIVE_TEST_RESULT);
339 run_nslist
("$NS_REF");
343 $POSITIVE_TEST_RESULT);
345 run_nsdel
("$DEF_REF"." --name iso --destroy");
347 # Verify we can handle a non-existent ior to add to the list
348 run_nsadd
("$DEF_REF --name does_not_exist --ior file://thisfiledoesnotexist");
349 run_nslist
("$NS_REF");
350 run_nsdel
("$DEF_REF"." --name does_not_exist");
351 run_nslist
("$NS_REF");
356 $POSITIVE_TEST_RESULT);
359 print STDERR
"\n\n======== Running tao_nsgroup Test================\n";
362 print STDERR
"This test will check the methods of the tao_nsgroup\n";
365 init_persistence_directory
($server, $name_dir );
366 init_persistence_directory
($server, $group_dir );
368 ################################################################################
369 # setup END block to cleanup after exit call
370 ################################################################################
373 $server->DeleteFile($name_mgr_iorbase);
374 $server->DeleteFile($name_srv_iorbase);
375 $client->DeleteFile($name_mgr_iorbase);
376 $client->DeleteFile($name_srv_iorbase);
377 $client->DeleteFile($stdout_file);
378 $client->DeleteFile($stderr_file);
380 if ( -d
$name_dir ) {
381 clean_persistence_dir
($server, $name_dir);
385 if ( -d
$group_dir ) {
386 clean_persistence_dir
($server, $group_dir);
391 ################################################################################
392 ## Start tao_ft_naming Service
393 ################################################################################
395 $server_status = $NM->Spawn ();
397 if ($server_status != 0) {
398 print STDERR
"ERROR: server returned $server_status\n";
402 if ($server->WaitForFileTimed ($name_mgr_iorbase,
403 $server->ProcessStartWaitInterval()) == -1) {
404 print STDERR
"ERROR: cannot find file <$name_mgr_iorbase>\n";
405 $NM->Kill (); $NM->TimedWait (1);
409 print STDERR
"Waiting for $name_mgr_iorbase\n";
410 if ($server->GetFile ($name_mgr_iorbase) == -1) {
411 print STDERR
"ERROR: cannot retrieve file <$name_mgr_iorbase>\n";
412 $NM->Kill (); $NM->TimedWait (1);
416 if ($client->PutFile ($name_mgr_iorbase) == -1) {
417 print STDERR
"ERROR: cannot set file <$naming_mgr_client_iorfile>\n";
418 $NM->Kill (); $NM->TimedWait (1);
424 print STDERR
"\n\n====================================================\n";
426 $server_status = $NM->TerminateWaitKill ($server->ProcessStopWaitInterval());
428 if ($server_status != 0) {
429 print STDERR
"ERROR: server returned $server_status\n";