diff options
author | mcorino <mcorino@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2011-10-20 09:46:10 +0000 |
---|---|---|
committer | mcorino <mcorino@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2011-10-20 09:46:10 +0000 |
commit | 02686f8d5108580e8a3d56bfe9b124405fdedd18 (patch) | |
tree | 0426ac218b7505e1c06dbf5ff8d2b10144d7ce75 /TAO/tests | |
parent | b2334408ebeffc6686b1f976247926df8411caec (diff) | |
download | ATCD-02686f8d5108580e8a3d56bfe9b124405fdedd18.tar.gz |
Tue Oct 20 09:30:13 UTC 2011 Martin Corino <mcorino@remedy.nl>
Merged changes from Remedy work branch.
Diffstat (limited to 'TAO/tests')
109 files changed, 4453 insertions, 120 deletions
diff --git a/TAO/tests/AMH_Oneway/server.cpp b/TAO/tests/AMH_Oneway/server.cpp index c2db9616e73..d680776d9f6 100644 --- a/TAO/tests/AMH_Oneway/server.cpp +++ b/TAO/tests/AMH_Oneway/server.cpp @@ -81,7 +81,7 @@ public: ST_AMH_Server (int *argc, ACE_TCHAR **argv); virtual ~ST_AMH_Server (); - /// ORB inititalisation stuff + /// ORB initialization stuff int start_orb_and_poa (void); /// register the servant with the poa @@ -91,7 +91,7 @@ public: virtual void run_event_loop (); /// do post-run cleanup. This is necessary here because the servant - /// supplied to regiser_servant happens to be allocated on the + /// supplied to register_servant happens to be allocated on the /// stack, and done after the instance of ST_AMH_Server is /// created. This leads to the servant being destroyed before this /// class's destructor. And alternative solution would be allocate @@ -100,7 +100,7 @@ public: virtual void cleanup (); public: - /// Accesor method (for servants) to the initialised ORB + /// Accesor method (for servants) to the initialized ORB CORBA::ORB_ptr orb () { return this->orb_.in (); } protected: diff --git a/TAO/tests/Bug_1330_Regression/Test.idl b/TAO/tests/Bug_1330_Regression/Test.idl index cf161d304ee..c4d2bf46647 100644 --- a/TAO/tests/Bug_1330_Regression/Test.idl +++ b/TAO/tests/Bug_1330_Regression/Test.idl @@ -4,5 +4,7 @@ interface Test { - void test_method(); + void test_method(); + + oneway void shutdown (); }; diff --git a/TAO/tests/Bug_1330_Regression/Test_i.cpp b/TAO/tests/Bug_1330_Regression/Test_i.cpp index ff714f3bbd6..ef2e83a8dcd 100644 --- a/TAO/tests/Bug_1330_Regression/Test_i.cpp +++ b/TAO/tests/Bug_1330_Regression/Test_i.cpp @@ -3,18 +3,22 @@ // #include "Test_i.h" -Test_i::Test_i() +Test_i::Test_i(CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) { - // Noop } Test_i::~Test_i() { - // Noop } void Test_i::test_method (void) { - // Noop +} + +void +Test_i::shutdown (void) +{ + this->orb_->shutdown (0); } diff --git a/TAO/tests/Bug_1330_Regression/Test_i.h b/TAO/tests/Bug_1330_Regression/Test_i.h index 7c5d11c210e..e1f38a78323 100644 --- a/TAO/tests/Bug_1330_Regression/Test_i.h +++ b/TAO/tests/Bug_1330_Regression/Test_i.h @@ -11,15 +11,21 @@ class Test_i: public POA_Test { public: - /// Constructor - Test_i (void); + /// Constructor + Test_i (CORBA::ORB_ptr orb); - /// Destructor - ~Test_i (void); + /// Destructor + ~Test_i (void); - /// A method - void test_method(void); + /// A method + virtual void test_method(void); + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; }; #endif /* ! BUG_1330_REGRESSION_TEST_I_H */ diff --git a/TAO/tests/Bug_1330_Regression/client.cpp b/TAO/tests/Bug_1330_Regression/client.cpp index 4a0ab7db26d..8613d306f4f 100644 --- a/TAO/tests/Bug_1330_Regression/client.cpp +++ b/TAO/tests/Bug_1330_Regression/client.cpp @@ -5,12 +5,12 @@ #include "ace/Get_Opt.h" const ACE_TCHAR *ior = ACE_TEXT("corbaloc:iiop:localhost:12345/Name\\2dwith\\2dhyphens"); -int shutdown_server = 0; +bool shutdown_server = false; int parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:")); + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("sk:")); int c; while ((c = get_opts ()) != -1) @@ -20,7 +20,7 @@ parse_args (int argc, ACE_TCHAR *argv[]) ior = get_opts.opt_arg (); break; case 's': - shutdown_server = 1; + shutdown_server = true; break; case '?': default: @@ -65,12 +65,16 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) server->test_method(); result =0; + if (shutdown_server) + { + server->shutdown (); + } orb->destroy (); } catch (const CORBA::Exception&) { - result =1; + result = 1; } return result; diff --git a/TAO/tests/Bug_1330_Regression/run_test.pl b/TAO/tests/Bug_1330_Regression/run_test.pl index 84dd57fcc9d..b0a809e0ccd 100755 --- a/TAO/tests/Bug_1330_Regression/run_test.pl +++ b/TAO/tests/Bug_1330_Regression/run_test.pl @@ -35,10 +35,10 @@ $SV = $server->CreateProcess ("server", "-o $server_iorfile"); $CL1 = $client->CreateProcess ("client", - "-k \"corbaloc:iiop:$TARGETHOSTNAME:$port/Name\\2dwith\\2dhyphens\""); + "-ORBdebuglevel $debug_level -k \"corbaloc:iiop:$TARGETHOSTNAME:$port/Name\\2dwith\\2dhyphens\""); $CL2 = $client->CreateProcess ("client", - "-k corbaloc:iiop:$TARGETHOSTNAME:$port/Name%2dwith%2dhyphens"); + "-ORBdebuglevel $debug_level -s -k corbaloc:iiop:$TARGETHOSTNAME:$port/Name%2dwith%2dhyphens"); $server_status = $SV->Spawn (); @@ -69,7 +69,7 @@ if ($client_status != 0) { $status = 1; } -$server_status = $SV->TerminateWaitKill ($server->ProcessStopWaitInterval()); +$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); if ($server_status != 0) { print STDERR "ERROR: server returned $server_status\n"; diff --git a/TAO/tests/Bug_1330_Regression/server.cpp b/TAO/tests/Bug_1330_Regression/server.cpp index 1d586aa6046..e76e80c4759 100644 --- a/TAO/tests/Bug_1330_Regression/server.cpp +++ b/TAO/tests/Bug_1330_Regression/server.cpp @@ -65,10 +65,14 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) if (parse_args (argc, argv) != 0) return 1; - Test_i server_impl; + Test_i *server_impl = 0; + ACE_NEW_RETURN (server_impl, + Test_i (orb.in ()), + 1); + PortableServer::ServantBase_var owner_transfer(server_impl); PortableServer::ObjectId_var id = - root_poa->activate_object (&server_impl); + root_poa->activate_object (server_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); @@ -85,26 +89,27 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) adapter->bind("Name-with-hyphens", ior.in()); - FILE *output_file= ACE_OS::fopen (ior_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "SERVER (%P): Cannot open output file " - "for writing IOR: %C", - "server.ior"), + "for writing IOR: %s", + ior_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); ACE_DEBUG ((LM_DEBUG, - "SERVER (%P): Activated as file://%C\n", - "server.ior")); + "SERVER (%P): Activated as file://%s\n", + ior_file)); poa_manager->activate(); orb->run (); root_poa->destroy (1, 1); + + orb->destroy (); } catch (const CORBA::Exception& ex) { diff --git a/TAO/tests/Bug_2241_Regression/Client_Task.cpp b/TAO/tests/Bug_2241_Regression/Client_Task.cpp index e39e0d96191..a4fe1dbbe2c 100644 --- a/TAO/tests/Bug_2241_Regression/Client_Task.cpp +++ b/TAO/tests/Bug_2241_Regression/Client_Task.cpp @@ -18,11 +18,11 @@ Client_Task::Client_Task (const ACE_TCHAR *ior, int Client_Task::svc (void) { + CORBA::Boolean exception = false; try { CORBA::Object_var tmp = this->corb_->string_to_object (input_); - Test::Hello_var hello = Test::Hello::_narrow(tmp.in ()); @@ -33,21 +33,32 @@ Client_Task::svc (void) input_), 1); } + try + { + CORBA::String_var the_string = hello->get_string (); - CORBA::String_var the_string = - hello->get_string (); - - ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", - the_string.in ())); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); - hello->shutdown (); + hello->shutdown (); + } + catch (CORBA::INTERNAL) + { + exception = true; + ACE_DEBUG ((LM_DEBUG, "OK: Client_Task Expected exception received\n")); + corb_->destroy (); + return 0; + } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } - + if (!exception) + { + ACE_ERROR ((LM_ERROR, "(ERROR: Client_Task::svc Expected exception not received\n")); + } return 0; } diff --git a/TAO/tests/Bug_2241_Regression/Hello.cpp b/TAO/tests/Bug_2241_Regression/Hello.cpp index cabcd9145d9..fa28f2a6135 100644 --- a/TAO/tests/Bug_2241_Regression/Hello.cpp +++ b/TAO/tests/Bug_2241_Regression/Hello.cpp @@ -16,42 +16,8 @@ char * Hello::get_string (void) { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Upcall in process ..\n")); - - // Use portable thread IDs - ACE_Thread_ID self_ID; - ACE_Thread_ID this_ID; - this_ID.id(this->thr_id_); - - if (self_ID == this_ID) - { - if (this->orb_->orb_core ()->optimize_collocation_objects () && - this->orb_->orb_core ()->use_global_collocation ()) - { - ACE_ERROR ((LM_ERROR, - "(%P|%t) ERROR: A remote call has been made " - " exiting ..\n")); - ACE_OS::abort (); - } - else if (this->orb_->orb_core ()->optimize_collocation_objects () && - this->orb_->orb_core ()->use_global_collocation () == 0) - { - TAO::ORB_Table * const orb_table = - TAO::ORB_Table::instance (); - - TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb")); - if (tmp.get () == 0) - { - // We are running on a single ORB and this is an error. - ACE_ERROR ((LM_ERROR, - "(%P|%t) ERROR: A remote call has been made " - " with a single ORB " - " exiting ..\n")); - ACE_OS::abort (); - } - } - } + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: Unexpected Upcall in process ..\n")); return CORBA::string_dup ("Hello there!"); } diff --git a/TAO/tests/Bug_2241_Regression/README b/TAO/tests/Bug_2241_Regression/README new file mode 100644 index 00000000000..d865dd156e6 --- /dev/null +++ b/TAO/tests/Bug_2241_Regression/README @@ -0,0 +1,4 @@ +This test is build without idlflag -Gd, so Direct collocation isn't enabled. +Running this test with -ORBCollocationStrategy 'direct' should result in an Exception. + + diff --git a/TAO/tests/Bug_2241_Regression/run_test.pl b/TAO/tests/Bug_2241_Regression/run_test.pl index e9c473e8341..4cc8f95201a 100755 --- a/TAO/tests/Bug_2241_Regression/run_test.pl +++ b/TAO/tests/Bug_2241_Regression/run_test.pl @@ -18,36 +18,6 @@ $status = 0; $SV = $server->CreateProcess ("Bug_2241_Regression"); -print STDERR "======== Running in Default Mode \n"; -$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile"); -$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); - -if ($sv != 0) { - print STDERR "ERROR in Collocated_Test\n"; - $status = 1; -} -$server->DeleteFile($iorbase); - -print STDERR "======== Running with global ORBCollocationStrategy\n"; -$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global"); -$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); - -if ($sv != 0) { - print STDERR "ERROR in Collocated_Test\n"; - $status = 1; -} -$server->DeleteFile($iorbase); - -print STDERR "======== Running with global ORBCollocationStrategy thru_poa\n"; -$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy thru_poa"); -$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); - -if ($sv != 0) { - print STDERR "ERROR in Collocated_Test\n"; - $status = 1; -} -$server->DeleteFile($iorbase); - print STDERR "======== Running with -ORBCollocation global -ORBCollocationStrategy direct \n"; $SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy direct"); $sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); diff --git a/TAO/tests/Bug_2289_Regression/Bug_2289_Regression.mpc b/TAO/tests/Bug_2289_Regression/Bug_2289_Regression.mpc index 960c4f67ad2..cf4dc3f81cb 100644 --- a/TAO/tests/Bug_2289_Regression/Bug_2289_Regression.mpc +++ b/TAO/tests/Bug_2289_Regression/Bug_2289_Regression.mpc @@ -2,7 +2,7 @@ // $Id$ project(*idl): taoidldefaults { - idlflags += -Gp -Gd -Sa -St + idlflags += -Gp -Gd IDL_Files { Test.idl } diff --git a/TAO/tests/CSD_Collocation/svc.conf.csd b/TAO/tests/CSD_Collocation/svc.conf.csd index 496c14b0103..2e5fd28b84e 100644 --- a/TAO/tests/CSD_Collocation/svc.conf.csd +++ b/TAO/tests/CSD_Collocation/svc.conf.csd @@ -8,9 +8,9 @@ static Advanced_Resource_Factory "-ORBReactorType select_st -ORBInputCDRAllocato # Make sure we use RW client handler so if something goes wrong, the program will bloc, # i.e., won't work. -static Client_Strategy_Factory "-ORBProfileLock null -ORBClientConnectionHandler RW" +static Client_Strategy_Factory "-ORBClientConnectionHandler RW" # Not absolutely necessary for this test, but we add it for fun. -static Server_Strategy_Factory "-ORBConcurrency reactive -ORBPOALock null" +static Server_Strategy_Factory "-ORBConcurrency reactive" static TAO_CSD_TP_Strategy_Factory "-CSDtp child:2:OFF" diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Client_Task.cpp b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Client_Task.cpp new file mode 100644 index 00000000000..8887b3ce577 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Client_Task.cpp @@ -0,0 +1,63 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + int status = 0; + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + CORBA::String_var the_string = + hello->get_string (); + + if (ACE_OS::strcmp (the_string.in (), "Hello there!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + status = 1; + } + else + { + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + } + + hello->shutdown (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + status = 1; + } + + return status; + +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Client_Task.h b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Collocated_Best_Direct.mpc b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Collocated_Best_Direct.mpc new file mode 100644 index 00000000000..2521cb67dda --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Collocated_Best_Direct.mpc @@ -0,0 +1,9 @@ +// -*- MPC -*- +// $Id$ + +// Enable DIRECT Collocation, disable Thru_Poa + +project(Collocated_Best_Direct): taoserver { + exename = Collocated_Best_Direct + idlflags += -Sp -Gd +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Collocated_Test.cpp b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Collocated_Test.cpp new file mode 100644 index 00000000000..282295ad5e3 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Collocated_Test.cpp @@ -0,0 +1,106 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.cpp b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.cpp new file mode 100644 index 00000000000..6494c809db8 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.cpp @@ -0,0 +1,70 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall in process ..\n")); + + // Use portable thread IDs + ACE_Thread_ID self_ID; + // Thread ID from Server + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + // Servant Thread ID same as Thread ID server, so a remote call, + // in case of a collocation the servant runs in calling thread (Client) + if (self_ID == this_ID) + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " exiting ..\n")); + ACE_OS::abort (); + } + else if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation () == 0) + { + TAO::ORB_Table * const orb_table = + TAO::ORB_Table::instance (); + + TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb")); + if (tmp.get () == 0) + { + // We are running on a single ORB and this is an error. + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " with a single ORB " + " exiting ..\n")); + ACE_OS::abort (); + } + } + } + + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.h b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.h new file mode 100644 index 00000000000..1d5e27d075f --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.h @@ -0,0 +1,34 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Server_Task.cpp b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Server_Task.cpp new file mode 100644 index 00000000000..98f37e052e3 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Server_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Server_Task.h b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/Test.idl b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocated_Best/Collocated_Best_Direct/run_test.pl b/TAO/tests/Collocated_Best/Collocated_Best_Direct/run_test.pl new file mode 100755 index 00000000000..39650e4147e --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_Direct/run_test.pl @@ -0,0 +1,45 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; + +$SV = $server->CreateProcess ("Collocated_Best_Direct"); + +print STDERR "======== Running with ORBCollocationg = global, -ORBCollocationStrategy = direct)\n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy direct"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + +$server->DeleteFile($iorbase); + +print STDERR "======== Running with -ORBCollocation global -ORBCollocationStrategy best \n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy best"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Client_Task.cpp b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Client_Task.cpp new file mode 100644 index 00000000000..4708f2680d8 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Client_Task.cpp @@ -0,0 +1,62 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + int status = 0; + + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + CORBA::String_var the_string = + hello->get_string (); + + if (ACE_OS::strcmp (the_string.in (), "Hello there!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + status = 1; + } + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + + hello->shutdown (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + status = 1; + } + + return status; + +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Client_Task.h b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Collocated_Best_NoColl.mpc b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Collocated_Best_NoColl.mpc new file mode 100644 index 00000000000..9604c0aff49 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Collocated_Best_NoColl.mpc @@ -0,0 +1,8 @@ +// -*- MPC -*- +// $Id$ + +// Disable Thru_Pu and don't enable Direct +project(Collocated_Best_NoColl): taoserver { + exename = Collocated_Best_NoColl + idlflags += -Sp +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Collocated_Test.cpp b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Collocated_Test.cpp new file mode 100644 index 00000000000..282295ad5e3 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Collocated_Test.cpp @@ -0,0 +1,106 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.cpp b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.cpp new file mode 100644 index 00000000000..cfa1a886365 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.cpp @@ -0,0 +1,76 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall in process ..\n")); + + // Use portable thread IDs + ACE_Thread_ID self_ID; + // Thread ID from Server + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + // Servant Thread ID same as Thread ID server, so a remote call, + // in case of a collocation the servant runs in calling thread (Client) + if (self_ID == this_ID) + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) OK: A remote call has been made \n")); + } + else if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation () == 0) + { + TAO::ORB_Table * const orb_table = + TAO::ORB_Table::instance (); + + TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb")); + if (tmp.get () == 0) + { + // We are running on a single ORB and this is an error. + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " with a single ORB " + " exiting ..\n")); + ACE_OS::abort (); + } + } + } + else + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: An unexpected collocated call has been made \n")); + } + } + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.h b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.h new file mode 100644 index 00000000000..1d5e27d075f --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.h @@ -0,0 +1,34 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Server_Task.cpp b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Server_Task.cpp new file mode 100644 index 00000000000..98f37e052e3 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Server_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Server_Task.h b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Test.idl b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocated_Best/Collocated_Best_NoColl/run_test.pl b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/run_test.pl new file mode 100755 index 00000000000..f6009aa0dc8 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_NoColl/run_test.pl @@ -0,0 +1,33 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; + +$SV = $server->CreateProcess ("Collocated_Best_NoColl"); + +print STDERR "======== Running with -ORBCollocation global -ORBCollocationStrategy best \n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy best"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Client_Task.cpp b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Client_Task.cpp new file mode 100644 index 00000000000..bfbe61b4942 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Client_Task.cpp @@ -0,0 +1,63 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + int status = 1; + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + CORBA::String_var the_string = + hello->get_string (); + + if (ACE_OS::strcmp (the_string.in (), "Hello there!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + status = 1; + } + else + { + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + } + + hello->shutdown (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + status = 1; + } + + return status; + +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Client_Task.h b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Collocated_Best_ThruP.mpc b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Collocated_Best_ThruP.mpc new file mode 100644 index 00000000000..1d2e67eccdc --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Collocated_Best_ThruP.mpc @@ -0,0 +1,7 @@ +// -*- MPC -*- +// $Id$ + +// Thru_Poa default enabled, Direct default disabled +project(Collocated_Best_ThruP): taoserver { + exename = Collocated_Best_ThruP +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Collocated_Test.cpp b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Collocated_Test.cpp new file mode 100644 index 00000000000..282295ad5e3 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Collocated_Test.cpp @@ -0,0 +1,106 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.cpp b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.cpp new file mode 100644 index 00000000000..fe5d6fec8fa --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.cpp @@ -0,0 +1,68 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" +#include "./tao/Collocation_Strategy.h" + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall in process ..\n")); + + // Use portable thread IDs + ACE_Thread_ID self_ID; + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + if (self_ID == this_ID) + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " exiting ..\n")); + ACE_OS::abort (); + } + else if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation () == 0) + { + TAO::ORB_Table * const orb_table = + TAO::ORB_Table::instance (); + + TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb")); + if (tmp.get () == 0) + { + // We are running on a single ORB and this is an error. + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " with a single ORB " + " exiting ..\n")); + ACE_OS::abort (); + } + } + } + + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.h b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.h new file mode 100644 index 00000000000..1d5e27d075f --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.h @@ -0,0 +1,34 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Server_Task.cpp b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Server_Task.cpp new file mode 100644 index 00000000000..98f37e052e3 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Server_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Server_Task.h b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Test.idl b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocated_Best/Collocated_Best_ThuP/run_test.pl b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/run_test.pl new file mode 100755 index 00000000000..99836c08852 --- /dev/null +++ b/TAO/tests/Collocated_Best/Collocated_Best_ThuP/run_test.pl @@ -0,0 +1,44 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; + +$SV = $server->CreateProcess ("Collocated_Best_ThruP"); + +$server->DeleteFile($iorbase); +print STDERR "======== Running with ORBCollocationg = global, (default ORBCollocationStrategy = thru_poa)\n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + +print STDERR "======== Running with -ORBCollocation global -ORBCollocationStrategy best \n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy best"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocated_Best/README b/TAO/tests/Collocated_Best/README new file mode 100644 index 00000000000..6abd103bbe4 --- /dev/null +++ b/TAO/tests/Collocated_Best/README @@ -0,0 +1,22 @@ +// $Id$ +CollocationStrategy TAO_COLLOCATION_BEST: + +This tests performs a series of checks on CollocationStrategy 'best' (TAO_COLLOCATION_BEST) support in TAO. + +With CollocationStrategy 'best' the best possible collocation strategy is tried to perform. + If TAO_COLLOCATION_DIRECT is possible, this has to be used, else if TAO_COLLOCATION_THRU_POA + is possible this has to be used, else use remote stub. + +The test Collocated_Best_Direct uses IDLflags -Sp, to disable Thru_poa collocation + and -Gd, to enable Direct collocation. +Starting the test with -ORBCollocationStrategy 'best' , + the test should use TAO_COLLOCATION_DIRECT collocation. + +The test Collocated_Best_ThruP uses default IDLflags,so Thru_poa collocation is enabled +and Direct collocation is default not enabled. +Starting the test with -ORBCollocationStrategy 'best', the test should use +TAO_COLLOCATION_THRU_POA collocation. + +The test Collocated_Best_ThruP uses IDLflags -Sp, to disable Thru_poa collocation +and Direct collocation is default not enabled. +Starting the test with -ORBCollocationStrategy 'best', the test should use no collocation, but remote stubs.
\ No newline at end of file diff --git a/TAO/tests/Collocated_DerivedIF/Client_Task.cpp b/TAO/tests/Collocated_DerivedIF/Client_Task.cpp new file mode 100644 index 00000000000..0ea9453a73d --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Client_Task.cpp @@ -0,0 +1,69 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + int status = 0; + + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::HelloAgain_var hello_again = + Test::HelloAgain::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello_again.in())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::HelloAgain reference <%s>\n", + input_), + 1); + } + + CORBA::String_var the_string = hello_again->get_string (); + if (ACE_OS::strcmp (the_string.in (), "Hello there!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + status = 1; + } + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string from hello_again returned <%C>\n", + the_string.in ())); + the_string = hello_again->get_string_again (); + + if (ACE_OS::strcmp (the_string.in (), "Bye!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + status = 1; + } + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string from hello_again returned <%C>\n", + the_string.in ())); + hello_again->shutdown (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + status = 1; + } + + return status; + +} diff --git a/TAO/tests/Collocated_DerivedIF/Client_Task.h b/TAO/tests/Collocated_DerivedIF/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_DerivedIF/Collocated_DerivedIF.mpc b/TAO/tests/Collocated_DerivedIF/Collocated_DerivedIF.mpc new file mode 100644 index 00000000000..7fab7ae785c --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Collocated_DerivedIF.mpc @@ -0,0 +1,8 @@ +// -*- MPC -*- +// $Id$ + +// Thru_Pu is disabled, enable direct +project(Collocated_DIF): taoserver { + exename = Collocated_DerivedIF + idlflags += -Sp -Gd +} diff --git a/TAO/tests/Collocated_DerivedIF/Collocated_Test.cpp b/TAO/tests/Collocated_DerivedIF/Collocated_Test.cpp new file mode 100644 index 00000000000..282295ad5e3 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Collocated_Test.cpp @@ -0,0 +1,106 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_DerivedIF/Hello.cpp b/TAO/tests/Collocated_DerivedIF/Hello.cpp new file mode 100644 index 00000000000..1db920f42f5 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Hello.cpp @@ -0,0 +1,84 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" + + +HelloAgain::HelloAgain (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} +char * +HelloAgain::get_string_again (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall get_string_again in process ..\n")); + + /// Use portable thread IDs + ACE_Thread_ID self_ID; + // Thread ID from Server + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + // Servant Thread ID same as Thread ID server, so a remote call, + // in case of a collocation the servant runs in calling thread (Client) + if (self_ID == this_ID) + { + ACE_ERROR ((LM_ERROR,"(%P|%t) ERROR: A remote call has been made \n")); + } + else + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t)OK: An expected collocated call has been made \n")); + } + } + return CORBA::string_dup ("Bye!"); +} + +char * +HelloAgain::get_string (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) HelloAgain::get_string Upcall get_string in process ..\n")); + + // Use portable thread IDs + ACE_Thread_ID self_ID; + // Thread ID from Server + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + // Servant Thread ID same as Thread ID server, so a remote call, + // in case of a collocation the servant runs in calling thread (Client) + if (self_ID == this_ID) + { + ACE_ERROR ((LM_ERROR,"(%P|%t) ERROR: A remote call has been made \n")); + } + else + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) OK: An expected collocated call has been made \n")); + } + } + return CORBA::string_dup ("Hello there!"); +} +void +HelloAgain::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} + diff --git a/TAO/tests/Collocated_DerivedIF/Hello.h b/TAO/tests/Collocated_DerivedIF/Hello.h new file mode 100644 index 00000000000..a028b36b192 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Hello.h @@ -0,0 +1,36 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + + /// Implement the Test::HelloAgain interface + class HelloAgain + : //public virtual Test::Hello, + public virtual POA_Test::HelloAgain + { + public: + /// Constructor + HelloAgain(CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string_again (void); + virtual char * get_string (void); + virtual void shutdown (void); + + + private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + ACE_thread_t thr_id_; + }; + + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_DerivedIF/README b/TAO/tests/Collocated_DerivedIF/README new file mode 100644 index 00000000000..a500775be3d --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/README @@ -0,0 +1,6 @@ +// $Id$ +CollocationStrategy direct and interface inheritance. + +The base needs to be generated also with direct collocation enabled, +otherwise no direct collocation. + diff --git a/TAO/tests/Collocated_DerivedIF/Server_Task.cpp b/TAO/tests/Collocated_DerivedIF/Server_Task.cpp new file mode 100644 index 00000000000..4d1e74d4a9a --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Server_Task.cpp @@ -0,0 +1,91 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + HelloAgain *hello_impl; + ACE_NEW_RETURN (hello_impl, + HelloAgain (this->sorb_.in (), + ACE_Thread::self ()), + 1); + PortableServer::ServantBase_var owner1_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::HelloAgain_var hello = + Test::HelloAgain::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + // ACE_OS::fprintf (output_file, "%s", ior1.in ()); + + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_DerivedIF/Server_Task.h b/TAO/tests/Collocated_DerivedIF/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_DerivedIF/Test.idl b/TAO/tests/Collocated_DerivedIF/Test.idl new file mode 100644 index 00000000000..001c6e274a2 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/Test.idl @@ -0,0 +1,23 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + oneway void shutdown (); + }; + + // A derived interface + interface HelloAgain : Hello + { + string get_string_again (); + }; +}; diff --git a/TAO/tests/Collocated_DerivedIF/run_test.pl b/TAO/tests/Collocated_DerivedIF/run_test.pl new file mode 100755 index 00000000000..5ac1c3c5df3 --- /dev/null +++ b/TAO/tests/Collocated_DerivedIF/run_test.pl @@ -0,0 +1,33 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; + +$SV = $server->CreateProcess ("Collocated_DerivedIF"); + +print STDERR "======== Running with -ORBCollocation global -ORBCollocationStrategy direct \n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy direct"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocated_NoColl/Client_Task.cpp b/TAO/tests/Collocated_NoColl/Client_Task.cpp new file mode 100644 index 00000000000..4708f2680d8 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Client_Task.cpp @@ -0,0 +1,62 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + int status = 0; + + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + CORBA::String_var the_string = + hello->get_string (); + + if (ACE_OS::strcmp (the_string.in (), "Hello there!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + status = 1; + } + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + + hello->shutdown (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + status = 1; + } + + return status; + +} diff --git a/TAO/tests/Collocated_NoColl/Client_Task.h b/TAO/tests/Collocated_NoColl/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_NoColl/Collocated_NoColl.mpc b/TAO/tests/Collocated_NoColl/Collocated_NoColl.mpc new file mode 100644 index 00000000000..8edb4eea37c --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Collocated_NoColl.mpc @@ -0,0 +1,8 @@ +// -*- MPC -*- +// $Id$ + +// Thru_Pu is default enabled +project(Collocated_NoColl): taoserver { + exename = Collocated_NoColl + +} diff --git a/TAO/tests/Collocated_NoColl/Collocated_Test.cpp b/TAO/tests/Collocated_NoColl/Collocated_Test.cpp new file mode 100644 index 00000000000..282295ad5e3 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Collocated_Test.cpp @@ -0,0 +1,106 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_NoColl/Hello.cpp b/TAO/tests/Collocated_NoColl/Hello.cpp new file mode 100644 index 00000000000..cfa1a886365 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Hello.cpp @@ -0,0 +1,76 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall in process ..\n")); + + // Use portable thread IDs + ACE_Thread_ID self_ID; + // Thread ID from Server + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + // Servant Thread ID same as Thread ID server, so a remote call, + // in case of a collocation the servant runs in calling thread (Client) + if (self_ID == this_ID) + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) OK: A remote call has been made \n")); + } + else if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation () == 0) + { + TAO::ORB_Table * const orb_table = + TAO::ORB_Table::instance (); + + TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb")); + if (tmp.get () == 0) + { + // We are running on a single ORB and this is an error. + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " with a single ORB " + " exiting ..\n")); + ACE_OS::abort (); + } + } + } + else + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: An unexpected collocated call has been made \n")); + } + } + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Collocated_NoColl/Hello.h b/TAO/tests/Collocated_NoColl/Hello.h new file mode 100644 index 00000000000..1d5e27d075f --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Hello.h @@ -0,0 +1,34 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_NoColl/Server_Task.cpp b/TAO/tests/Collocated_NoColl/Server_Task.cpp new file mode 100644 index 00000000000..98f37e052e3 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Server_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_NoColl/Server_Task.h b/TAO/tests/Collocated_NoColl/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_NoColl/Test.idl b/TAO/tests/Collocated_NoColl/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Collocated_NoColl/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocated_NoColl/run_test.pl b/TAO/tests/Collocated_NoColl/run_test.pl new file mode 100755 index 00000000000..0b0ac76ed01 --- /dev/null +++ b/TAO/tests/Collocated_NoColl/run_test.pl @@ -0,0 +1,33 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; + +$SV = $server->CreateProcess ("Collocated_NoColl"); + +print STDERR "======== Running with -ORBCollocation no \n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -ORBCollocation no"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocated_ThruP_Sp/Client_Task.cpp b/TAO/tests/Collocated_ThruP_Sp/Client_Task.cpp new file mode 100644 index 00000000000..7569e6ddb7b --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Client_Task.cpp @@ -0,0 +1,65 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + CORBA::Boolean exception = false; + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + try + { + CORBA::String_var the_string = + hello->get_string (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + + hello->shutdown (); + } + catch (CORBA::INTERNAL) + { + exception = true; + ACE_DEBUG ((LM_DEBUG, "OK: Client_Task Expected exception received\n")); + corb_->destroy (); + return 0; + } + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + if (!exception) + { + ACE_ERROR ((LM_ERROR, "(ERROR: Client_Task::svc Expected exception not received\n")); + } + return 0; +} diff --git a/TAO/tests/Collocated_ThruP_Sp/Client_Task.h b/TAO/tests/Collocated_ThruP_Sp/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_ThruP_Sp/Collocated_Test.cpp b/TAO/tests/Collocated_ThruP_Sp/Collocated_Test.cpp new file mode 100644 index 00000000000..eade083328b --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Collocated_Test.cpp @@ -0,0 +1,105 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_ThruP_Sp/Collocated_ThruP_Sp.mpc b/TAO/tests/Collocated_ThruP_Sp/Collocated_ThruP_Sp.mpc new file mode 100644 index 00000000000..86c10ace774 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Collocated_ThruP_Sp.mpc @@ -0,0 +1,9 @@ +// -*- MPC -*- +// $Id$ + +// Disable THRU_POA Collocation + +project(Collocated_ThruP_Sp): taoserver { + exename = Collocated_ThruP_Sp + idlflags += -Sp +} diff --git a/TAO/tests/Collocated_ThruP_Sp/Hello.cpp b/TAO/tests/Collocated_ThruP_Sp/Hello.cpp new file mode 100644 index 00000000000..e77d95e07bc --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Hello.cpp @@ -0,0 +1,32 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) +{ + ACE_ERROR ((LM_DEBUG, + "(%P|%t) ERROR: Upcall in process ..\n")); + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Collocated_ThruP_Sp/Hello.h b/TAO/tests/Collocated_ThruP_Sp/Hello.h new file mode 100644 index 00000000000..1d5e27d075f --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Hello.h @@ -0,0 +1,34 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_ThruP_Sp/README b/TAO/tests/Collocated_ThruP_Sp/README new file mode 100644 index 00000000000..e475dc45576 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/README @@ -0,0 +1,6 @@ +// $Id$ + +This test is build with idlflag -Sp, to disable Thru_poa collocation. +Running this test with -ORBCollocationStrategy Thru_poa should result in an Exception. + + diff --git a/TAO/tests/Collocated_ThruP_Sp/Server_Task.cpp b/TAO/tests/Collocated_ThruP_Sp/Server_Task.cpp new file mode 100644 index 00000000000..2cca42206ee --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Server_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl = 0; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_ThruP_Sp/Server_Task.h b/TAO/tests/Collocated_ThruP_Sp/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_ThruP_Sp/Test.idl b/TAO/tests/Collocated_ThruP_Sp/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocated_ThruP_Sp/run_test.pl b/TAO/tests/Collocated_ThruP_Sp/run_test.pl new file mode 100755 index 00000000000..a0812ae4f8e --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp/run_test.pl @@ -0,0 +1,60 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; +$debug_level = '0'; + +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +$SV = $server->CreateProcess ("Collocated_ThruP_Sp"); + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-ORBdebuglevel $debug_level -o $server_iorfile -k file://$server_iorfile"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + +print STDERR "======== Running with global ORBCollocationStrategy\n"; +$SV->Arguments ("-ORBdebuglevel $debug_level -o $server_iorfile -k file://$server_iorfile -ORBCollocation global"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + +print STDERR "======== Running with global ORBCollocationStrategy thru_poa\n"; +$SV->Arguments ("-ORBdebuglevel $debug_level -o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy thru_poa"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Client_Task.cpp b/TAO/tests/Collocated_ThruP_Sp_Gd/Client_Task.cpp new file mode 100644 index 00000000000..7569e6ddb7b --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Client_Task.cpp @@ -0,0 +1,65 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "TestC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + CORBA::Boolean exception = false; + try + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + try + { + CORBA::String_var the_string = + hello->get_string (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + + hello->shutdown (); + } + catch (CORBA::INTERNAL) + { + exception = true; + ACE_DEBUG ((LM_DEBUG, "OK: Client_Task Expected exception received\n")); + corb_->destroy (); + return 0; + } + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + if (!exception) + { + ACE_ERROR ((LM_ERROR, "(ERROR: Client_Task::svc Expected exception not received\n")); + } + return 0; +} diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Client_Task.h b/TAO/tests/Collocated_ThruP_Sp_Gd/Client_Task.h new file mode 100644 index 00000000000..8f6557cdec8 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Client_Task.h @@ -0,0 +1,37 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Collocated_Test.cpp b/TAO/tests/Collocated_ThruP_Sp_Gd/Collocated_Test.cpp new file mode 100644 index 00000000000..282295ad5e3 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Collocated_Test.cpp @@ -0,0 +1,106 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Collocated_ThruP_Sp_Gd.mpc b/TAO/tests/Collocated_ThruP_Sp_Gd/Collocated_ThruP_Sp_Gd.mpc new file mode 100644 index 00000000000..a5b5b6fdf8e --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Collocated_ThruP_Sp_Gd.mpc @@ -0,0 +1,9 @@ +// -*- MPC -*- +// $Id$ + +// Disable THRU_POA Collocation, enable Direct Collocation + +project(Coll_ThruP_Sp-Gd): taoserver { + exename = Coll_ThruP_Sp_Gd + idlflags += -Sp -Gd +} diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Hello.cpp b/TAO/tests/Collocated_ThruP_Sp_Gd/Hello.cpp new file mode 100644 index 00000000000..e77d95e07bc --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Hello.cpp @@ -0,0 +1,32 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/ORB_Core_Auto_Ptr.h" + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) +{ + ACE_ERROR ((LM_DEBUG, + "(%P|%t) ERROR: Upcall in process ..\n")); + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Hello.h b/TAO/tests/Collocated_ThruP_Sp_Gd/Hello.h new file mode 100644 index 00000000000..1d5e27d075f --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Hello.h @@ -0,0 +1,34 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/README b/TAO/tests/Collocated_ThruP_Sp_Gd/README new file mode 100644 index 00000000000..c385fcfe91b --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/README @@ -0,0 +1,7 @@ +// $Id$ + +This test is build with idlflag -Sp and Gd, to disable Thru_poa collocation, +but enable direct collocation. +Running this test with -ORBCollocationStrategy Thru_poa should result in an Exception. + + diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Server_Task.cpp b/TAO/tests/Collocated_ThruP_Sp_Gd/Server_Task.cpp new file mode 100644 index 00000000000..98f37e052e3 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Server_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in ()); + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Server_Task.h b/TAO/tests/Collocated_ThruP_Sp_Gd/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/Test.idl b/TAO/tests/Collocated_ThruP_Sp_Gd/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocated_ThruP_Sp_Gd/run_test.pl b/TAO/tests/Collocated_ThruP_Sp_Gd/run_test.pl new file mode 100755 index 00000000000..504290188c1 --- /dev/null +++ b/TAO/tests/Collocated_ThruP_Sp_Gd/run_test.pl @@ -0,0 +1,60 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; +$debug_level = '0'; + +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +$SV = $server->CreateProcess ("Coll_ThruP_Sp_Gd"); + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-ORBdebuglevel $debug_level -o $server_iorfile -k file://$server_iorfile"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + +print STDERR "======== Running with global ORBCollocationStrategy\n"; +$SV->Arguments ("-ORBdebuglevel $debug_level -o $server_iorfile -k file://$server_iorfile -ORBCollocation global"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + +print STDERR "======== Running with global ORBCollocationStrategy thru_poa\n"; +$SV->Arguments ("-ORBdebuglevel $debug_level -o $server_iorfile -k file://$server_iorfile -ORBCollocation global -ORBCollocationStrategy thru_poa"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/Collocation_Opportunities/run_test.pl b/TAO/tests/Collocation_Opportunities/run_test.pl index 689d8586e95..91e99715397 100755 --- a/TAO/tests/Collocation_Opportunities/run_test.pl +++ b/TAO/tests/Collocation_Opportunities/run_test.pl @@ -8,9 +8,17 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' use lib "$ENV{ACE_ROOT}/bin"; use PerlACE::TestTarget; +$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"; -$SV = $server->CreateProcess ("Collocation_Opportunities"); +$SV = $server->CreateProcess ("Collocation_Opportunities", "-ORBdebuglevel $debug_level"); $test = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); diff --git a/TAO/tests/ForwardUponObjectNotExist/client.cpp b/TAO/tests/ForwardUponObjectNotExist/client.cpp index 783d187e115..70666db32e1 100755 --- a/TAO/tests/ForwardUponObjectNotExist/client.cpp +++ b/TAO/tests/ForwardUponObjectNotExist/client.cpp @@ -178,7 +178,6 @@ Worker::run_test (void) return; } - CORBA::Boolean r = server->test_is_a ("IDL:Foo:1.0"); diff --git a/TAO/tests/ForwardUponObjectNotExist/server.cpp b/TAO/tests/ForwardUponObjectNotExist/server.cpp index eb95494366b..133182484f3 100755 --- a/TAO/tests/ForwardUponObjectNotExist/server.cpp +++ b/TAO/tests/ForwardUponObjectNotExist/server.cpp @@ -97,6 +97,10 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t)server: event loop finished\n")); + + root_poa->destroy (1, 1); + + orb->destroy (); } catch (const CORBA::Exception& ex) { diff --git a/TAO/tests/Hello/run_test.pl b/TAO/tests/Hello/run_test.pl index 719974e5c50..f45d4729c86 100755 --- a/TAO/tests/Hello/run_test.pl +++ b/TAO/tests/Hello/run_test.pl @@ -10,11 +10,14 @@ use PerlACE::TestTarget; $status = 0; $debug_level = '0'; - +$cdebug_level = '0'; foreach $i (@ARGV) { if ($i eq '-debug') { $debug_level = '10'; } + if ($i eq '-cdebug') { + $cdebug_level = '10'; + } } my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n"; @@ -27,7 +30,7 @@ $server->DeleteFile($iorbase); $client->DeleteFile($iorbase); $SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile"); -$CL = $client->CreateProcess ("client", "-k file://$client_iorfile"); +$CL = $client->CreateProcess ("client", "-ORBdebuglevel $cdebug_level -k file://$client_iorfile"); $server_status = $SV->Spawn (); if ($server_status != 0) { diff --git a/TAO/tests/Oneway_Buffering/Oneway_Buffering.mpc b/TAO/tests/Oneway_Buffering/Oneway_Buffering.mpc index 92fe4fbd3bc..f04ccc6e29a 100644 --- a/TAO/tests/Oneway_Buffering/Oneway_Buffering.mpc +++ b/TAO/tests/Oneway_Buffering/Oneway_Buffering.mpc @@ -24,7 +24,6 @@ project(*Server): messaging, taoserver { project(*Client): messaging, taoclient { exename = client - requires += corba_messaging after += *idl Source_Files { diff --git a/TAO/tests/POA/Etherealization/run_test.pl b/TAO/tests/POA/Etherealization/run_test.pl index b62766a5e7e..c55d9411bd9 100755 --- a/TAO/tests/POA/Etherealization/run_test.pl +++ b/TAO/tests/POA/Etherealization/run_test.pl @@ -8,9 +8,17 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' use lib "$ENV{ACE_ROOT}/bin"; use PerlACE::TestTarget; +$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"; -$SV = $server->CreateProcess ("Etherealization"); +$SV = $server->CreateProcess ("Etherealization", "-ORBdebuglevel $debug_level"); $test = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); diff --git a/TAO/tests/POA/Nested_Non_Servant_Upcalls/run_test.pl b/TAO/tests/POA/Nested_Non_Servant_Upcalls/run_test.pl index 8da0c1f582c..edac726c827 100755 --- a/TAO/tests/POA/Nested_Non_Servant_Upcalls/run_test.pl +++ b/TAO/tests/POA/Nested_Non_Servant_Upcalls/run_test.pl @@ -8,9 +8,17 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' use lib "$ENV{ACE_ROOT}/bin"; use PerlACE::TestTarget; +$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"; -$SV = $server->CreateProcess ("Nested_Non_Servant_Upcalls"); +$SV = $server->CreateProcess ("Nested_Non_Servant_Upcalls", "-ORBdebuglevel $debug_level"); $test = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Client_Task.cpp b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Client_Task.cpp new file mode 100644 index 00000000000..2bde4bbba67 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Client_Task.cpp @@ -0,0 +1,87 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "testC.h" + +Client_Task::Client_Task (const ACE_TCHAR *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr, + CORBA::Boolean exception) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + , except_ (exception) +{ +} + +int +Client_Task::svc (void) +{ + int status = 0; + try + { + // Get an object reference from the argument string. + CORBA::Object_var tmp = + this->corb_->string_to_object (input_); + + // Try to narrow the object reference to a test reference. + test_var test = test::_narrow (tmp.in ()); + if (CORBA::is_nil (test.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + CORBA::String_var ior = + this->corb_->object_to_string (test.in ()); + + ACE_DEBUG ((LM_DEBUG, + "\nConnecting to: %C\n\n", + ior.in ())); + try + { + CORBA::String_var the_string = test->get_string (); + if (ACE_OS::strcmp (the_string.in (), "Hello there!") != 0) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) - Error, incorrect string returned <%C>\n", + the_string.in ())); + } + else + { + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - OK , correct string returned <%C>\n", + the_string.in ())); + } + test->shutdown (); + } + catch (CORBA::INTERNAL) + { + if (this->except_) + { + ACE_DEBUG ((LM_DEBUG, + "OK: Client_Task Expected exception with" + "direct collocation received\n")); + status = 0; + } + else + { + ACE_ERROR ((LM_ERROR, + "ERROR: Client_Task Unxpected exception with" + "thru_poa collocation received\n")); + status = 1; + } + } + corb_->destroy (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + status = 1; + } + + return status; + +} diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Client_Task.h b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Client_Task.h new file mode 100644 index 00000000000..f1b20a22fbf --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Client_Task.h @@ -0,0 +1,39 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/ORB.h" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const ACE_TCHAR *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr, + CORBA::Boolean exception); + + /// Thread entry point + int svc (void); + +private: + const ACE_TCHAR *input_; + + CORBA::ORB_var corb_; + CORBA::Boolean except_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Collocated_Test.cpp b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Collocated_Test.cpp new file mode 100644 index 00000000000..53f3bf81805 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Collocated_Test.cpp @@ -0,0 +1,103 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const ACE_TCHAR *output = ACE_TEXT("test.ior"); +const ACE_TCHAR *input = ACE_TEXT("file://test.ior"); +CORBA::Boolean exception = false; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:td:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 't': + // no exception expected + exception = false; + break; + case 'd': + // exception expected + exception = true; + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv ()); + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv ()); + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance (), + exception); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/On_Demand_Act_D_Coll.mpc b/TAO/tests/POA/On_Demand_Act_Direct_Coll/On_Demand_Act_D_Coll.mpc new file mode 100644 index 00000000000..973e9e988e1 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/On_Demand_Act_D_Coll.mpc @@ -0,0 +1,15 @@ +// -*- MPC -*- +// $Id$ + +project(On_Demand_Act_D_Coll): taoserver, portableserver { + exename = On_Demand_Act_D_Coll + idlflags += -Gd + + Source_Files { + Collocated_Test.cpp + Server_Task.cpp + Client_Task.cpp + Servant_Activator.cpp + test_i.cpp + } +} diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Servant_Activator.cpp b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Servant_Activator.cpp new file mode 100644 index 00000000000..646f86ba81b --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Servant_Activator.cpp @@ -0,0 +1,64 @@ + +//============================================================================= +/** + * @file Servant_Activator.cpp + * + * $Id$ + * + * Implementation of ServantActivator, which is used by a POA with + * a RETAIN policy. + * + * + * @author Irfan Pyarali + */ +//============================================================================= + + +#include "Servant_Activator.h" +#include "test_i.h" +#include "ace/OS_NS_string.h" + +ServantActivator::ServantActivator (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)), + thr_id_ (thrid) +{ + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ServantActivator::ServantActivator\n"))); +} + +PortableServer::Servant +ServantActivator::incarnate (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa) +{ + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ServantActivator::incarnate\n"))); + // Convert ObjectId to String. + CORBA::String_var s = PortableServer::ObjectId_to_string (oid); + + // If ObjectId string has a test substring, create and return a + // test_i. + + if (ACE_OS::strstr (s.in (), "test") != 0) + return new test_i (this->orb_.in (), poa, this->thr_id_); + else + { + throw CORBA::OBJECT_NOT_EXIST (); + } +} + + +void +ServantActivator::etherealize (const PortableServer::ObjectId &, + PortableServer::POA_ptr , + PortableServer::Servant servant, + CORBA::Boolean , + CORBA::Boolean remaining_activations) +{ + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ServantActivator::etherealize\n"))); + // If there are no remaining activations i.e ObjectIds associated + // with test_i delete it. + if (!remaining_activations) + delete servant; +} diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Servant_Activator.h b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Servant_Activator.h new file mode 100644 index 00000000000..db87624ce55 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Servant_Activator.h @@ -0,0 +1,49 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Servant_Activator.h + * + * $Id$ + * + * Defines a ServantActivator class. + * + * + * @author Irfan Pyarali + */ +//============================================================================= + + +#include "tao/PortableServer/PortableServer.h" +#include "tao/PortableServer/ServantActivatorC.h" +#include "tao/LocalObject.h" + +#include "tao/ORB.h" + +class ServantActivator : + public virtual PortableServer::ServantActivator, + public virtual ::CORBA::LocalObject +{ +public: + ServantActivator (CORBA::ORB_ptr orb, ACE_thread_t thrid); + + /** + * This method is invoked by a POA with USE_SERVANT_MANAGER and + * RETAIN policies, whenever it receives a request for a test object + * that is not currently active. + */ + PortableServer::Servant incarnate (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa); + + /// This method is invoked whenever a test object is deactivated. + void etherealize (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + PortableServer::Servant servant, + CORBA::Boolean cleanup_in_progress, + CORBA::Boolean remaining_activations); + +private: + /// A reference to the ORB. + CORBA::ORB_var orb_; + ACE_thread_t thr_id_; +}; diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Server_Task.cpp b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Server_Task.cpp new file mode 100644 index 00000000000..687ad1e98b6 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Server_Task.cpp @@ -0,0 +1,148 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "Servant_Activator.h" +#include "ace/OS_NS_stdio.h" +#include "ace/Manual_Event.h" + +static const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior"); + +static int +write_iors_to_file (const char *first_ior) +{ + FILE *output_file = ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0 ) + ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output files for writing IORs: %Cn", + ior_output_file), + -1); + + int result = ACE_OS::fprintf (output_file, + "%s", + first_ior); + if (result <= 0 + || static_cast<size_t> (result) != ACE_OS::strlen (first_ior)) + ACE_ERROR_RETURN ((LM_ERROR, + "ACE_OS::fprintf failed while writing %C to %s\n", + first_ior, + ior_output_file), + -1); + + ACE_OS::fclose (output_file); + return 0; +} + +Server_Task::Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + + CORBA::PolicyList policies (4); + policies.length (4); + + // ID Assignment Policy + policies[0] = + root_poa->create_id_assignment_policy (PortableServer::USER_ID); + + // Lifespan Policy + policies[1] = + root_poa->create_lifespan_policy (PortableServer::PERSISTENT); + + // Request Processing Policy + policies[2] = + root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER); + + PortableServer::POA_var first_poa; + { + // Servant Retention Policy + policies[3] = + root_poa->create_servant_retention_policy (PortableServer::RETAIN); + + ACE_CString name = "firstPOA"; + + // Create firstPOA as the child of RootPOA with the above policies + // firstPOA will use SERVANT_ACTIVATOR because of RETAIN policy. + first_poa = root_poa->create_POA (name.c_str (), + poa_manager.in (), + policies); + + } + + // Destroy the policy objects as they have been passed to + // create_POA and no longer needed. + for (CORBA::ULong i = 0; + i < policies.length (); + ++i) + { + CORBA::Policy_ptr policy = policies[i]; + policy->destroy (); + } + // Allocate the servant activator. + ServantActivator activator (this->sorb_.in (), ACE_Thread::self ()); + // Set ServantActivator object as the servant_manager of + // firstPOA. + + first_poa->set_servant_manager (&activator); + // Create a reference with user created ID in firstPOA which uses + // the ServantActivator. + + PortableServer::ObjectId_var first_test_oid = + PortableServer::string_to_ObjectId ("first test"); + + CORBA::Object_var first_test = + first_poa->create_reference_with_id (first_test_oid.in (), "IDL:test:1.0"); + // Invoke object_to_string on the references created in firstPOA + + CORBA::String_var first_test_ior = + this->sorb_->object_to_string (first_test.in ()); + + // Print the ior's of first_test. + ACE_DEBUG((LM_DEBUG,"<%C>\n", + first_test_ior.in ())); + + int write_result = write_iors_to_file (first_test_ior.in ()); + if (write_result != 0) + return write_result; + + // Set the poa_manager state to active, ready to process requests. + poa_manager->activate (); + this->me_.signal (); + // Run the ORB. + this->sorb_->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/Server_Task.h b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Server_Task.h new file mode 100644 index 00000000000..e42043c0711 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const ACE_TCHAR *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const ACE_TCHAR *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/run_test.pl b/TAO/tests/POA/On_Demand_Act_Direct_Coll/run_test.pl new file mode 100755 index 00000000000..39409d83955 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/run_test.pl @@ -0,0 +1,44 @@ +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; + +my $server = PerlACE::TestTarget::create_target(1) || die "Create target 1 failed\n"; + +$iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +$server->DeleteFile($iorbase); + +$status = 0; + +$SV = $server->CreateProcess ("On_Demand_Act_D_Coll"); + +print STDERR "======== Running with ORBCollocationg = global, -ORBCollocationStrategy = thru_poa)\n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -t -ORBCollocation global -ORBCollocationStrategy thru_poa"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in On_Demand_Act_D_Coll test: Servant Activator and Collocation test\n"; + $status = 1; +} +$server->DeleteFile($iorbase); + + +print STDERR "======== Running with -ORBCollocation global -ORBCollocationStrategy direct \n"; +$SV->Arguments ("-o $server_iorfile -k file://$server_iorfile -d -ORBCollocation global -ORBCollocationStrategy direct"); +$sv = $SV->SpawnWaitKill ($server->ProcessStartWaitInterval()); + +if ($sv != 0) { + print STDERR "ERROR in On_Demand_Act_D_Coll test: Servant Activator and Collocation test\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$server->GetStderrLog(); + +exit $status; diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/test.idl b/TAO/tests/POA/On_Demand_Act_Direct_Coll/test.idl new file mode 100644 index 00000000000..687502ce8f9 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/test.idl @@ -0,0 +1,13 @@ +// $Id$ + +interface test +{ + /// Return a simple string + string get_string (); + + void method (); + // A twoway operation. + + void shutdown (); + // Shutdown the server. +}; diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/test_i.cpp b/TAO/tests/POA/On_Demand_Act_Direct_Coll/test_i.cpp new file mode 100644 index 00000000000..41cd3c13348 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/test_i.cpp @@ -0,0 +1,58 @@ +// $Id$ + +#include "test_i.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_string.h" + +// Constructor +test_i::test_i (CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + ,poa_ (PortableServer::POA::_duplicate (poa)) + ,thr_id_ (thrid) +{ +} + +void +test_i::method (void) +{ +} + +char * +test_i::get_string (void) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall in process ..\n")); + // Use portable thread IDs + ACE_Thread_ID self_ID; + // Thread ID from Server + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + // Servant Thread ID same as Thread ID server, so a remote call, + // in case of a collocation the servant runs in calling thread (Client) + if (self_ID == this_ID) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " exiting ..\n")); + ACE_OS::abort (); + } + else + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) OK: A collocated invocation has been made.\n")); + } + return CORBA::string_dup ("Hello there!"); +} + +void +test_i::shutdown (void) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/tests/POA/On_Demand_Act_Direct_Coll/test_i.h b/TAO/tests/POA/On_Demand_Act_Direct_Coll/test_i.h new file mode 100644 index 00000000000..44c4a114aea --- /dev/null +++ b/TAO/tests/POA/On_Demand_Act_Direct_Coll/test_i.h @@ -0,0 +1,44 @@ +//============================================================================= +/** + * @file test_i.h + * + * $Id$ + * + * Defines test_i class for the test interface + * + * + * @author Irfan Pyarali + */ +//============================================================================= + + +#include "testS.h" + +class test_i : public POA_test +{ +public: + /// Constructor - takes a POA and a value parameter + test_i (CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + ACE_thread_t thr_id); + + /// A twoway operation. + void method (void); + + /// A twoway operation. + char * + get_string (void); + + /// Shutdown the ORB + void shutdown (void); + + +protected: + /// Our ORB. + CORBA::ORB_var orb_; + + /// Our POA. + PortableServer::POA_var poa_; +private: + ACE_thread_t thr_id_; +}; diff --git a/TAO/tests/Param_Test/anyop.cpp b/TAO/tests/Param_Test/anyop.cpp index 006d174f24e..c440b8198b2 100644 --- a/TAO/tests/Param_Test/anyop.cpp +++ b/TAO/tests/Param_Test/anyop.cpp @@ -87,10 +87,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) orb->string_to_object ("corbaloc:iiop:localhost:1234/Foo/Bar"); Param_Test_var param_test = - TAO::Narrow_Utils<Param_Test>::unchecked_narrow ( - obj.in (), - _TAO_Param_Test_Proxy_Broker_Factory_function_pointer - ); + TAO::Narrow_Utils<Param_Test>::unchecked_narrow (obj.in ()); TAO_Stub *stub = param_test->_stubobj (); stub->type_id = CORBA::string_dup ("IDL:Param_Test:1.0"); diff --git a/TAO/tests/Policies/Manipulation.cpp b/TAO/tests/Policies/Manipulation.cpp index 2feb981f76d..7e1169fb0f6 100644 --- a/TAO/tests/Policies/Manipulation.cpp +++ b/TAO/tests/Policies/Manipulation.cpp @@ -92,9 +92,7 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) orb->string_to_object ("corbaloc:iiop:localhost:12345/FakeIOR"); Test_var test = - TAO::Narrow_Utils<Test>::unchecked_narrow ( - object.in (), - _TAO_Test_Proxy_Broker_Factory_function_pointer); + TAO::Narrow_Utils<Test>::unchecked_narrow (object.in ()); if (CORBA::is_nil (test.in ())) { diff --git a/TAO/tests/Policies/Policies.mpc b/TAO/tests/Policies/Policies.mpc index 353c7a0ccec..05a385e23a3 100644 --- a/TAO/tests/Policies/Policies.mpc +++ b/TAO/tests/Policies/Policies.mpc @@ -3,5 +3,4 @@ project(Policies Manipulation): taoserver, messaging { exename = Manipulation - requires += corba_messaging } |