From 4e0fbcbede63c844fcb99dc98eee3446dba7d1df Mon Sep 17 00:00:00 2001 From: mcorino Date: Thu, 7 Apr 2011 11:48:50 +0000 Subject: Thu Apr 7 11:40:00 UTC 2011 Martin Corino Merged changes from Remedy work branch. --- .../Bug_3953_Regression/Bug_3953_Regression.mpc | 34 ++++ TAO/tests/Bug_3953_Regression/README | 9 + TAO/tests/Bug_3953_Regression/client.cpp | 167 +++++++++++++++++ TAO/tests/Bug_3953_Regression/client_i.cpp | 26 +++ TAO/tests/Bug_3953_Regression/client_i.h | 20 +++ TAO/tests/Bug_3953_Regression/run_test.pl | 76 ++++++++ TAO/tests/Bug_3953_Regression/server.cpp | 198 +++++++++++++++++++++ TAO/tests/Bug_3953_Regression/server_i.cpp | 56 ++++++ TAO/tests/Bug_3953_Regression/server_i.h | 30 ++++ TAO/tests/Bug_3953_Regression/svc.conf | 3 + TAO/tests/Bug_3953_Regression/svc.conf.xml | 5 + TAO/tests/Bug_3953_Regression/test.idl | 38 ++++ 12 files changed, 662 insertions(+) create mode 100644 TAO/tests/Bug_3953_Regression/Bug_3953_Regression.mpc create mode 100644 TAO/tests/Bug_3953_Regression/README create mode 100644 TAO/tests/Bug_3953_Regression/client.cpp create mode 100644 TAO/tests/Bug_3953_Regression/client_i.cpp create mode 100644 TAO/tests/Bug_3953_Regression/client_i.h create mode 100755 TAO/tests/Bug_3953_Regression/run_test.pl create mode 100644 TAO/tests/Bug_3953_Regression/server.cpp create mode 100644 TAO/tests/Bug_3953_Regression/server_i.cpp create mode 100644 TAO/tests/Bug_3953_Regression/server_i.h create mode 100644 TAO/tests/Bug_3953_Regression/svc.conf create mode 100644 TAO/tests/Bug_3953_Regression/svc.conf.xml create mode 100644 TAO/tests/Bug_3953_Regression/test.idl (limited to 'TAO/tests/Bug_3953_Regression') diff --git a/TAO/tests/Bug_3953_Regression/Bug_3953_Regression.mpc b/TAO/tests/Bug_3953_Regression/Bug_3953_Regression.mpc new file mode 100644 index 00000000000..ad221b73797 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/Bug_3953_Regression.mpc @@ -0,0 +1,34 @@ +// -*- MPC -*- +// $Id$ + +project(*_Idl): taoidldefaults { + IDL_Files { + test.idl + } + custom_only = 1 +} + +project(*_Server): taoserver, messaging { + after += *_Idl + Source_Files { + testC.cpp + testS.cpp + server_i.cpp + server.cpp + } + IDL_Files { + } +} + +project(*_Client): taoserver { + exename = client + after += *_Idl + Source_Files { + testC.cpp + testS.cpp + client_i.cpp + client.cpp + } + IDL_Files { + } +} diff --git a/TAO/tests/Bug_3953_Regression/README b/TAO/tests/Bug_3953_Regression/README new file mode 100644 index 00000000000..ab058d902f6 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/README @@ -0,0 +1,9 @@ +This is a test of the nested upcall feature in TAO using mt_noupcall. +start off by calling the server and providing a callback object and a +time-to-live number. The server will callback the client (using the +callback object) and decrement the time-to-live number. + +With mt_noupcall enabled the client should drop the nested upcall from the +server and which leads to a timeout exception in the server and than in the +client. + diff --git a/TAO/tests/Bug_3953_Regression/client.cpp b/TAO/tests/Bug_3953_Regression/client.cpp new file mode 100644 index 00000000000..38dd592717e --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/client.cpp @@ -0,0 +1,167 @@ +// $Id$ + +#include "client_i.h" +#include "ace/Get_Opt.h" +#include "ace/Task.h" + +static const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior"); +// Server IOR. + +static int shutdown_server = 0; +// Flag to tell server to shutdown. + +static CORBA::UShort call_count = 2; +// # of nested calls to be made. + +static int quiet = 0; +// The test is quiet... + +class Client_Task +{ +public: + Client_Task (client_ptr c, + server_ptr s); + int svc (void); + + bool exception (void) const; + +private: + client_var client_; + server_var server_; +}; + +Client_Task::Client_Task (client_ptr c, + server_ptr s) + : client_ (client::_duplicate (c)), + server_ (server::_duplicate (s)) +{ +} + +int +Client_Task::svc (void) +{ + try + { + if (!quiet) + ACE_DEBUG ((LM_DEBUG, + "(%t) Client_Task::svc calling start -> time to live = %d\n", + call_count)); + + // Now, we can invoke an operation on the remote side. + this->server_->start (this->client_.in (), + call_count); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Client_Task::svc"); + return -1; + } + return 0; +} + +static int +parse_args (int argc, + ACE_TCHAR **argv) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("qxn:k:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'q': + quiet = 1; + break; + + case 'x': + shutdown_server = 1; + break; + + case 'n': + call_count = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case 'k': + ior = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-n number of nested calls]" + " [-k ior]" + " [-q (quite)]" + " [-x (shutdown server)]" + "\n", + argv[0]), + -1); + } + + if (ior == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "%s: no nested up calls server ior specified\n", + argv[0]), + -1); + + // Indicates successful parsing of command line. + return 0; +} + +int +ACE_TMAIN (int argc, + ACE_TCHAR **argv) +{ + int result = 0; + try + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); + + result = parse_args (argc, argv); + if (result != 0) + return result; + + CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + poa_manager->activate (); + + object = orb->string_to_object (ior); + + server_var server = server::_narrow (object.in ()); + + // Create an client object to hand to the other side... + client_i client_servant (quiet, + server.in ()); + + PortableServer::ObjectId_var id = + root_poa->activate_object (&client_servant); + + CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); + + client_var client_object = client::_narrow (object_act.in ()); + + Client_Task client_tasks (client_object.in (), + server.in ()); + + client_tasks.svc (); + + if (shutdown_server) + { + server->shutdown (); + } + + root_poa->destroy (1, 1); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("client::main"); + return -1; + } + return result; +} diff --git a/TAO/tests/Bug_3953_Regression/client_i.cpp b/TAO/tests/Bug_3953_Regression/client_i.cpp new file mode 100644 index 00000000000..7525ef2160c --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/client_i.cpp @@ -0,0 +1,26 @@ +// $Id$ + +#include "client_i.h" + +client_i::client_i (int quiet, + server_ptr s) + : quiet_ (quiet), + server_ (server::_duplicate (s)) +{ +} + +void +client_i::ping (CORBA::UShort time_to_live) +{ + if (!this->quiet_) + ACE_DEBUG ((LM_DEBUG, + "(%t) client_i::ping -> time to live = %d\n", + time_to_live)); + + --time_to_live; + + if (time_to_live > 0) + { + this->server_->ping (time_to_live); + } +} diff --git a/TAO/tests/Bug_3953_Regression/client_i.h b/TAO/tests/Bug_3953_Regression/client_i.h new file mode 100644 index 00000000000..b0d308f04b8 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/client_i.h @@ -0,0 +1,20 @@ +// $Id$ + +#include "testS.h" + +class client_i : public POA_client +{ +public: + client_i (int quiet, + server_ptr s); + // Constructor. + + void ping (CORBA::UShort time_to_live); + +private: + int quiet_; + // Be quiet. + + server_var server_; + // Pointer to server. +}; diff --git a/TAO/tests/Bug_3953_Regression/run_test.pl b/TAO/tests/Bug_3953_Regression/run_test.pl new file mode 100755 index 00000000000..5d3abb11162 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/run_test.pl @@ -0,0 +1,76 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +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 $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n"; +my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n"; + +my $iorbase = "server.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +$SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -f $server_iorfile"); +$CL = $client->CreateProcess ("client", "-ORBdebuglevel $debug_level -k file://$client_iorfile -x"); + +print STDERR "\nrunning ST version of the client and the server\n\n"; + +$server_status = $SV->Spawn (); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +if ($server->GetFile ($iorbase) == -1) { + print STDERR "ERROR: cannot retrieve file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} +if ($client->PutFile ($iorbase) == -1) { + print STDERR "ERROR: cannot set file <$client_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval() + 45); + +if ($client_status != 0) { + print STDERR "ERROR: client returned $client_status\n"; + $status = 1; +} + +$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +exit $status; diff --git a/TAO/tests/Bug_3953_Regression/server.cpp b/TAO/tests/Bug_3953_Regression/server.cpp new file mode 100644 index 00000000000..70e3fa49354 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/server.cpp @@ -0,0 +1,198 @@ +// $Id$ + +#include "server_i.h" + +#include "ace/Get_Opt.h" +#include "ace/Task.h" +#include "tao/Messaging/Messaging.h" + +static int quiet = 0; +// The test is quiet... + +static const ACE_TCHAR *ior_file = ACE_TEXT ("test.ior"); +// File of file to which the ior is written + +static int number_of_threads = 1; +// Number of server threads. + +class Server_Task : public ACE_Task_Base +{ +public: + Server_Task (CORBA::ORB_ptr orb); + int svc (void); + +private: + CORBA::ORB_var orb_; +}; + +Server_Task::Server_Task (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var object = + this->orb_->resolve_initial_references ("PolicyCurrent"); + + CORBA::PolicyCurrent_var policy_current = + CORBA::PolicyCurrent::_narrow (object.in ()); + + TimeBase::TimeT timeout_period = 100 * 100000; + + CORBA::Any timeout_as_any; + timeout_as_any <<= timeout_period; + + CORBA::PolicyList policy_list (1); + policy_list.length (1); + policy_list[0] = + this->orb_->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, + timeout_as_any); + + policy_current->set_policy_overrides (policy_list, + CORBA::ADD_OVERRIDE); + + policy_list[0]->destroy(); + + this->orb_->run (); + } + catch (const CORBA::Exception&) + { + return -1; + } + return 0; +} + +static int +write_ior_to_file (const char *ior) +{ + FILE *output_file = ACE_OS::fopen (ior_file, "w"); + + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output files for writing IOR: %s\n", + ior_file), + -1); + + int result = 0; + + result = ACE_OS::fprintf (output_file, + "%s", + ior); + if (result < 0 || + static_cast (result) != ACE_OS::strlen (ior)) + ACE_ERROR_RETURN ((LM_ERROR, + "ACE_OS::fprintf failed while writing %C to %s\n", + ior, + ior_file), + -1); + + ACE_OS::fclose (output_file); + + return 0; +} + +static int +parse_args (int argc, + ACE_TCHAR **argv) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("q:f:t:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'q': + quiet = 1; + break; + + case 't': + number_of_threads = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case 'f': + ior_file = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-t number of threads]" + " [-f ior file]" + " [-q (quite)]" + "\n", + argv[0]), + -1); + } + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR **argv) +{ + int result = 0; + + try + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); + + result = parse_args (argc, argv); + if (result != 0) + return result; + + CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + poa_manager->activate (); + + server_i server_servant (quiet, + orb.in ()); + + PortableServer::ObjectId_var id = + root_poa->activate_object (&server_servant); + + CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); + + server_var server_object = server::_narrow (object_act.in ()); + + CORBA::String_var ior = orb->object_to_string (server_object.in ()); + + result = write_ior_to_file (ior.in ()); + if (result != 0) + return result; + + Server_Task server_tasks (orb.in ()); + + result = server_tasks.activate (THR_BOUND, + number_of_threads); + + if (result != 0) + return result; + + result = ACE_Thread_Manager::instance ()->wait (); + + if (result != 0) + return result; + + root_poa->destroy (1, 1); + + if (!server_servant.exception ()) + ++result; + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("server::main"); + return -1; + } + + return result; +} diff --git a/TAO/tests/Bug_3953_Regression/server_i.cpp b/TAO/tests/Bug_3953_Regression/server_i.cpp new file mode 100644 index 00000000000..d0a374dc038 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/server_i.cpp @@ -0,0 +1,56 @@ +// $Id$ + +#include "server_i.h" + +server_i::server_i (int quiet, + CORBA::ORB_ptr orb) + : quiet_ (quiet), + orb_ (CORBA::ORB::_duplicate (orb)), + exception_ (false) +{ +} + +void +server_i::start (client_ptr c, + CORBA::UShort time_to_live) +{ + this->client_ = client::_duplicate (c); + this->ping (time_to_live); +} + +bool +server_i::exception (void) const +{ + return this->exception_; +} + +void +server_i::ping (CORBA::UShort time_to_live) +{ + if (!this->quiet_) + ACE_DEBUG ((LM_DEBUG, + "(%t) server_i::ping -> time to live = %d\n", + time_to_live)); + + try + { + --time_to_live; + + if (time_to_live > 0) + { + this->client_->ping (time_to_live); + } + } + catch (const CORBA::TIMEOUT&) + { + this->exception_ = true; + ACE_DEBUG ((LM_DEBUG, + "server ping received an expected except.\n")); + } +} + +void +server_i::shutdown (void) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Bug_3953_Regression/server_i.h b/TAO/tests/Bug_3953_Regression/server_i.h new file mode 100644 index 00000000000..a60c9f8876d --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/server_i.h @@ -0,0 +1,30 @@ +// $Id$ + +#include "testS.h" + +class server_i : public POA_server +{ +public: + server_i (int quiet, + CORBA::ORB_ptr orb); + + void ping (CORBA::UShort time_to_live); + + void start (client_ptr c, + CORBA::UShort time_to_live); + + void shutdown (void); + + bool exception (void) const; +private: + int quiet_; + // Be quiet. + + client_var client_; + // Pointer to server. + + CORBA::ORB_var orb_; + // Pointer to orb. + + bool exception_; +}; diff --git a/TAO/tests/Bug_3953_Regression/svc.conf b/TAO/tests/Bug_3953_Regression/svc.conf new file mode 100644 index 00000000000..1878e4a33c5 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/svc.conf @@ -0,0 +1,3 @@ +# $Id$ + +static Client_Strategy_Factory '-ORBWaitStrategy mt_noupcall' diff --git a/TAO/tests/Bug_3953_Regression/svc.conf.xml b/TAO/tests/Bug_3953_Regression/svc.conf.xml new file mode 100644 index 00000000000..91c9afd3b3e --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/svc.conf.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/TAO/tests/Bug_3953_Regression/test.idl b/TAO/tests/Bug_3953_Regression/test.idl new file mode 100644 index 00000000000..45664cfb035 --- /dev/null +++ b/TAO/tests/Bug_3953_Regression/test.idl @@ -0,0 +1,38 @@ +// $Id$ +// +// ============================================================================ +// +// = LIBRARY +// TAO/tests/NestedUpcall +// +// = FILENAME +// test.idl +// +// = DESCRIPTION +// A simple test of nested upcalls. +// +// = AUTHOR +// Irfan Pyarali +// +// ============================================================================ + +interface client +{ + void ping (in unsigned short time_to_live); + // Decrements . If becomes zero, it + // stops. Otherwise, it pings the server. +}; + +interface server +{ + void start (in client c, + in unsigned short time_to_live); + // Turns around and starts pinging the client. + + void ping (in unsigned short time_to_live); + // Decrements . If becomes zero, it + // stops. Otherwise, it pings the client. + + oneway void shutdown (); + // Shutdown the server. +}; -- cgit v1.2.1