1 #include "ace/Get_Opt.h"
2 #include "ace/Array_Base.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/RTCORBA/Thread_Pool.h"
7 #include "tao/RTPortableServer/RTPortableServer.h"
8 #include "../check_supported_priorities.cpp"
10 RTCORBA::Priority default_thread_priority
;
14 struct Test_Object_And_Servant
20 typedef ACE_Array_Base
<Test_Object_And_Servant
> Tests
;
23 setup_test_parameters (Test_Object_And_Servant
*test
,
24 RTCORBA::Current_ptr current
,
30 test_i (CORBA::ORB_ptr orb
,
31 PortableServer::POA_ptr poa
,
38 PortableServer::POA_ptr
_default_POA ();
40 int client_propagated ();
42 void client_propagated (int);
44 int server_declared ();
46 void server_declared (int);
48 RTCORBA::Priority
server_priority ();
50 void server_priority (RTCORBA::Priority
);
56 int serviced_by_rt_tp ();
58 void serviced_by_rt_tp (int);
60 void thread_info (const char *method_name
);
62 void invocation_pool_and_lane (CORBA::ULong pool
,
65 void invocation_pool (CORBA::ULong pool
);
67 void invocation_lane (CORBA::ULong lane
);
69 RTCORBA::Priority
invocation_priority ();
71 void invocation_priority (RTCORBA::Priority
);
75 PortableServer::POA_var poa_
;
78 int client_propagated_
;
80 RTCORBA::Priority server_priority_
;
82 int serviced_by_rt_tp_
;
86 RTCORBA::Priority invocation_priority_
;
88 RTCORBA::Current_var current_
;
91 test_i::test_i (CORBA::ORB_ptr orb
,
92 PortableServer::POA_ptr poa
,
94 : orb_ (CORBA::ORB::_duplicate (orb
)),
95 poa_ (PortableServer::POA::_duplicate (poa
)),
97 client_propagated_ (0),
100 serviced_by_rt_tp_ (1),
101 invocation_priority_ (0)
103 CORBA::Object_var object
=
104 this->orb_
->resolve_initial_references ("RTCurrent");
107 RTCORBA::Current::_narrow (object
.in ());
111 test_i::client_propagated ()
113 return this->client_propagated_
;
117 test_i::client_propagated (int client_propagated
)
119 this->client_propagated_
= client_propagated
;
123 test_i::server_declared ()
125 return this->server_declared_
;
129 test_i::server_declared (int server_declared
)
131 this->server_declared_
= server_declared
;
135 test_i::server_priority ()
137 return this->server_priority_
;
141 test_i::server_priority (RTCORBA::Priority server_priority
)
143 this->server_priority_
= server_priority
;
149 return this->in_lane_
;
153 test_i::in_lane (int in_lane
)
155 this->in_lane_
= in_lane
;
159 test_i::serviced_by_rt_tp ()
161 return this->serviced_by_rt_tp_
;
165 test_i::serviced_by_rt_tp (int serviced_by_rt_tp
)
167 this->serviced_by_rt_tp_
= serviced_by_rt_tp
;
171 test_i::invocation_pool_and_lane (CORBA::ULong pool
,
179 test_i::invocation_pool (CORBA::ULong pool
)
185 test_i::invocation_lane (CORBA::ULong lane
)
191 test_i::invocation_priority ()
193 return this->invocation_priority_
;
197 test_i::invocation_priority (RTCORBA::Priority invocation_priority
)
199 this->invocation_priority_
= invocation_priority
;
205 ACE_DEBUG ((LM_DEBUG
,
208 this->thread_info ("test_i::start");
210 ACE_DEBUG ((LM_DEBUG
,
213 Tests::ITERATOR
iterator (this->tests_
);
214 while (!iterator
.done ())
216 Test_Object_And_Servant
*test
= 0;
217 iterator
.next (test
);
219 setup_test_parameters (test
,
220 this->current_
.in (),
223 test
->object_
->method ();
225 CORBA::String_var ior
=
226 this->orb_
->object_to_string (test
->object_
.in ());
228 CORBA::Object_var object
=
229 this->orb_
->string_to_object (ior
.in ());
231 test_var test_from_string
=
232 test::_narrow (object
.in ());
234 test_from_string
->method ();
241 test_i::thread_info (const char *method_name
)
243 // Get the ORB_Core's TSS resources.
244 TAO_ORB_Core_TSS_Resources
*tss
=
245 this->orb_
->orb_core ()->get_tss_resources ();
247 /// Get the lane attribute in TSS.
248 TAO_Thread_Lane
*lane
=
249 (TAO_Thread_Lane
*) tss
->lane_
;
253 ACE_DEBUG ((LM_DEBUG
,
254 "(%t) %s (pool = %d; lane = %d); priority = %d (should be %d)\n",
258 this->current_
->the_priority (),
259 this->invocation_priority ()));
261 ACE_ASSERT (this->pool_
== lane
->pool ().id ());
262 ACE_ASSERT (this->lane_
== lane
->id ());
263 ACE_ASSERT (this->current_
->the_priority () ==
264 this->invocation_priority ());
268 ACE_DEBUG ((LM_DEBUG
,
269 "(%t) %s (default thread pool); priority = %d (should be %d)\n",
271 this->current_
->the_priority (),
272 this->invocation_priority ()));
274 ACE_ASSERT (this->pool_
== 0);
275 ACE_ASSERT (this->lane_
== 0);
276 ACE_ASSERT (this->current_
->the_priority () ==
277 this->invocation_priority ());
284 this->thread_info ("test_i::method");
287 PortableServer::POA_ptr
288 test_i::_default_POA ()
290 return PortableServer::POA::_duplicate (this->poa_
.in ());
294 setup_test_parameters (Test_Object_And_Servant
*test
,
295 RTCORBA::Current_ptr current
,
298 CORBA::Short current_thread_priority
;
302 current_thread_priority
=
303 current
->the_priority ();
305 catch (const CORBA::INITIALIZE
&)
309 current_thread_priority
= get_implicit_thread_CORBA_priority (orb
);
311 catch (const CORBA::Exception
&ex
)
313 ex
._tao_print_exception ("Exception in ::setup_test_parameters calling ::get_implicit_thread_CORBA_priority: ");
317 catch (const CORBA::Exception
& dc
)
319 dc
._tao_print_exception ("Exception in ::setup_test_parameters calling current->the_priority(): ");
323 current
->the_priority (current_thread_priority
);
325 if (!test
->servant_
->serviced_by_rt_tp () ||
326 test
->servant_
->client_propagated ())
328 test
->servant_
->invocation_priority (current_thread_priority
);
330 else if (test
->servant_
->server_declared ())
332 test
->servant_
->invocation_priority (test
->servant_
->server_priority ());
336 test
->servant_
->invocation_priority (default_thread_priority
);
339 if (test
->servant_
->client_propagated () &&
340 test
->servant_
->in_lane ())
342 if (current_thread_priority
== default_thread_priority
)
343 test
->servant_
->invocation_lane (0);
345 test
->servant_
->invocation_lane (1);
348 if (!test
->servant_
->serviced_by_rt_tp ())
350 // Get the ORB_Core's TSS resources.
351 TAO_ORB_Core_TSS_Resources
*tss
=
352 orb
->orb_core ()->get_tss_resources ();
354 /// Get the lane attribute in TSS.
355 TAO_Thread_Lane
*lane
=
356 (TAO_Thread_Lane
*) tss
->lane_
;
360 test
->servant_
->invocation_pool_and_lane (lane
->pool ().id (),
365 test
->servant_
->invocation_pool_and_lane (0, 0);
373 Server (CORBA::ORB_ptr orb
);
375 void create_servant_in_root_poa ();
376 void create_poa_and_servant_with_tp_policy (const char *poa_name
,
377 int set_priority_model
,
378 RTCORBA::PriorityModel priority_model
);
379 void create_poa_and_servant_with_tp_with_lanes_policy (const char *poa_name
,
380 RTCORBA::PriorityModel priority_model
);
382 void start_testing ();
384 //FUZZ: disable check_for_lack_ACE_OS
386 //FUZZ: enable check_for_lack_ACE_OS
389 RTCORBA::RTORB_var rt_orb_
;
390 PortableServer::POA_var root_poa_
;
391 PortableServer::POAManager_var poa_manager_
;
392 RTCORBA::Current_var current_
;
396 CORBA::ULong stacksize_
;
397 CORBA::ULong static_threads_
;
398 CORBA::ULong dynamic_threads_
;
399 CORBA::Boolean allow_request_buffering_
;
400 CORBA::Boolean allow_borrowing_
;
401 CORBA::ULong max_buffered_requests_
;
402 CORBA::ULong max_request_buffer_size_
;
405 Server::Server (CORBA::ORB_ptr orb
)
406 : orb_ (CORBA::ORB::_duplicate (orb
)),
409 dynamic_threads_ (0),
410 allow_request_buffering_ (0),
411 allow_borrowing_ (0),
412 max_buffered_requests_ (0),
413 max_request_buffer_size_ (0)
415 CORBA::Object_var object
=
416 this->orb_
->resolve_initial_references ("RTORB");
419 RTCORBA::RTORB::_narrow (object
.in ());
422 this->orb_
->resolve_initial_references ("RTCurrent");
425 RTCORBA::Current::_narrow (object
.in ());
427 default_thread_priority
=
428 get_implicit_thread_CORBA_priority (this->orb_
.in ());
431 this->orb_
->resolve_initial_references ("RootPOA");
434 PortableServer::POA::_narrow (object
.in ());
437 this->root_poa_
->the_POAManager ();
439 this->poa_manager_
->activate ();
443 Server::create_servant_in_root_poa ()
446 ACE_NEW_THROW_EX (servant
,
447 test_i (this->orb_
.in (),
448 this->root_poa_
.in (),
450 CORBA::NO_MEMORY ());
452 servant
->invocation_pool_and_lane (0, 0);
453 servant
->in_lane (0);
454 servant
->serviced_by_rt_tp (0);
456 PortableServer::ServantBase_var
safe_servant (servant
);
458 this->tests_
.size (this->tests_
.size () + 1);
459 this->tests_
[this->tests_
.size () - 1].servant_
=
461 this->tests_
[this->tests_
.size () - 1].object_
=
466 Server::create_poa_and_servant_with_tp_policy (const char *poa_name
,
467 int set_priority_model
,
468 RTCORBA::PriorityModel priority_model
)
470 RTCORBA::ThreadpoolId threadpool_id
=
471 this->rt_orb_
->create_threadpool (this->stacksize_
,
472 this->static_threads_
,
473 this->dynamic_threads_
,
474 default_thread_priority
,
475 this->allow_request_buffering_
,
476 this->max_buffered_requests_
,
477 this->max_request_buffer_size_
);
479 CORBA::Policy_var threadpool_policy
=
480 this->rt_orb_
->create_threadpool_policy (threadpool_id
);
482 CORBA::Policy_var priority_model_policy
=
483 this->rt_orb_
->create_priority_model_policy (priority_model
,
484 default_thread_priority
);
486 CORBA::PolicyList policies
;
488 policies
.length (policies
.length () + 1);
489 policies
[policies
.length () - 1] =
492 if (set_priority_model
)
494 policies
.length (policies
.length () + 1);
495 policies
[policies
.length () - 1] =
496 priority_model_policy
;
499 PortableServer::POA_var poa
=
500 this->root_poa_
->create_POA (poa_name
,
501 this->poa_manager_
.in (),
504 RTPortableServer::POA_var rt_poa
=
505 RTPortableServer::POA::_narrow (poa
.in ());
507 test_i
*servant1
= 0;
508 ACE_NEW_THROW_EX (servant1
,
509 test_i (this->orb_
.in (),
512 CORBA::NO_MEMORY ());
514 servant1
->in_lane (0);
516 PortableServer::ObjectId_var id1
;
518 if (set_priority_model
)
520 if (priority_model
== RTCORBA::CLIENT_PROPAGATED
)
522 servant1
->invocation_pool_and_lane (1, 0);
523 servant1
->client_propagated (1);
526 rt_poa
->activate_object (servant1
);
530 test_i
*servant2
= 0;
532 ACE_NEW_THROW_EX (servant2
,
533 test_i (this->orb_
.in (),
536 CORBA::NO_MEMORY ());
538 servant2
->in_lane (0);
540 PortableServer::ServantBase_var
safe_servant2 (servant2
);
542 PortableServer::ObjectId_var id2
;
544 servant1
->invocation_pool_and_lane (2, 0);
545 servant2
->invocation_pool_and_lane (2, 0);
546 servant1
->server_declared (1);
547 servant2
->server_declared (1);
548 servant1
->server_priority (default_thread_priority
+ 1);
549 servant2
->server_priority (default_thread_priority
);
552 rt_poa
->activate_object_with_priority (servant1
,
553 default_thread_priority
+ 1);
556 rt_poa
->activate_object_with_priority (servant2
,
557 default_thread_priority
);
559 CORBA::Object_var object2
=
560 poa
->id_to_reference (id2
.in ());
562 this->tests_
.size (this->tests_
.size () + 1);
563 this->tests_
[this->tests_
.size () - 1].object_
=
564 test::_narrow (object2
.in ());
565 this->tests_
[this->tests_
.size () - 1].servant_
=
571 servant1
->invocation_pool_and_lane (3, 0);
574 rt_poa
->activate_object (servant1
);
577 PortableServer::ServantBase_var
safe_servant (servant1
);
579 CORBA::Object_var object1
=
580 poa
->id_to_reference (id1
.in ());
582 this->tests_
.size (this->tests_
.size () + 1);
583 this->tests_
[this->tests_
.size () - 1].object_
=
584 test::_narrow (object1
.in ());
585 this->tests_
[this->tests_
.size () - 1].servant_
=
590 Server::create_poa_and_servant_with_tp_with_lanes_policy (const char *poa_name
,
591 RTCORBA::PriorityModel priority_model
)
593 RTCORBA::ThreadpoolLanes
lanes (2);
596 lanes
[0].lane_priority
= default_thread_priority
;
597 lanes
[0].static_threads
= this->static_threads_
;
598 lanes
[0].dynamic_threads
= this->dynamic_threads_
;
600 lanes
[1].lane_priority
= default_thread_priority
+ 1;
601 lanes
[1].static_threads
= this->static_threads_
;
602 lanes
[1].dynamic_threads
= this->dynamic_threads_
;
604 RTCORBA::ThreadpoolId threadpool_id
=
605 this->rt_orb_
->create_threadpool_with_lanes (this->stacksize_
,
607 this->allow_borrowing_
,
608 this->allow_request_buffering_
,
609 this->max_buffered_requests_
,
610 this->max_request_buffer_size_
);
612 CORBA::Policy_var threadpool_policy
=
613 this->rt_orb_
->create_threadpool_policy (threadpool_id
);
615 CORBA::Policy_var priority_model_policy
=
616 this->rt_orb_
->create_priority_model_policy (priority_model
,
617 default_thread_priority
);
619 CORBA::PolicyList policies
;
621 policies
.length (policies
.length () + 1);
622 policies
[policies
.length () - 1] =
625 policies
.length (policies
.length () + 1);
626 policies
[policies
.length () - 1] =
627 priority_model_policy
;
629 PortableServer::POA_var poa
=
630 this->root_poa_
->create_POA (poa_name
,
631 this->poa_manager_
.in (),
634 RTPortableServer::POA_var rt_poa
=
635 RTPortableServer::POA::_narrow (poa
.in ());
637 test_i
*servant1
= 0;
638 ACE_NEW_THROW_EX (servant1
,
639 test_i (this->orb_
.in (),
642 CORBA::NO_MEMORY ());
644 servant1
->in_lane (1);
646 PortableServer::ServantBase_var
safe_servant1 (servant1
);
648 PortableServer::ObjectId_var id1
;
650 if (priority_model
== RTCORBA::CLIENT_PROPAGATED
)
652 servant1
->invocation_pool (4);
653 servant1
->client_propagated (1);
656 rt_poa
->activate_object (servant1
);
660 test_i
*servant2
= 0;
662 ACE_NEW_THROW_EX (servant2
,
663 test_i (this->orb_
.in (),
666 CORBA::NO_MEMORY ());
668 servant2
->in_lane (1);
670 PortableServer::ServantBase_var
safe_servant2 (servant2
);
672 PortableServer::ObjectId_var id2
;
674 servant1
->invocation_pool_and_lane (5, 1);
675 servant2
->invocation_pool_and_lane (5, 0);
676 servant1
->server_declared (1);
677 servant2
->server_declared (1);
678 servant1
->server_priority (default_thread_priority
+ 1);
679 servant2
->server_priority (default_thread_priority
);
682 rt_poa
->activate_object_with_priority (servant1
,
683 default_thread_priority
+ 1);
686 rt_poa
->activate_object_with_priority (servant2
,
687 default_thread_priority
);
689 CORBA::Object_var object2
=
690 poa
->id_to_reference (id2
.in ());
692 this->tests_
.size (this->tests_
.size () + 1);
693 this->tests_
[this->tests_
.size () - 1].object_
=
694 test::_narrow (object2
.in ());
695 this->tests_
[this->tests_
.size () - 1].servant_
=
699 CORBA::Object_var object1
=
700 poa
->id_to_reference (id1
.in ());
702 this->tests_
.size (this->tests_
.size () + 1);
703 this->tests_
[this->tests_
.size () - 1].object_
=
704 test::_narrow (object1
.in ());
705 this->tests_
[this->tests_
.size () - 1].servant_
=
710 Server::start_testing ()
712 Tests::ITERATOR
iterator (this->tests_
);
713 while (!iterator
.done ())
715 Test_Object_And_Servant
*test
= 0;
716 iterator
.next (test
);
718 setup_test_parameters (test
,
719 this->current_
.in (),
722 test
->object_
->start ();
731 this->start_testing ();
733 ACE_DEBUG ((LM_DEBUG
,
734 "\n\n*** Changing priority to be higher ***\n\n"));
736 this->current_
->the_priority (default_thread_priority
+ 1);
738 this->start_testing ();
744 this->orb_
->shutdown (true);
746 this->orb_
->destroy ();
749 class Task
: public ACE_Task_Base
752 Task (ACE_Thread_Manager
&thread_manager
,
760 Task::Task (ACE_Thread_Manager
&thread_manager
,
762 : ACE_Task_Base (&thread_manager
),
763 orb_ (CORBA::ORB::_duplicate (orb
))
772 Server
server (this->orb_
.in ());
774 server
.create_servant_in_root_poa ();
776 server
.create_poa_and_servant_with_tp_policy ("tp_client_propagated_poa",
778 RTCORBA::CLIENT_PROPAGATED
);
780 server
.create_poa_and_servant_with_tp_policy ("tp_server_declared_poa",
782 RTCORBA::SERVER_DECLARED
);
784 server
.create_poa_and_servant_with_tp_policy ("tp_no_priority_model_poa",
786 RTCORBA::CLIENT_PROPAGATED
);
788 server
.create_poa_and_servant_with_tp_with_lanes_policy ("tp_with_lanes_client_propagated_poa",
789 RTCORBA::CLIENT_PROPAGATED
);
791 server
.create_poa_and_servant_with_tp_with_lanes_policy ("tp_with_lanes_server_declared_poa",
792 RTCORBA::SERVER_DECLARED
);
798 catch (const CORBA::Exception
& ex
)
800 ex
._tao_print_exception ("Exception caught:");
808 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
813 CORBA::ORB_init (argc
,
816 // Make sure we can support multiple priorities that are
817 // required for this test.
818 if (!check_supported_priorities (orb
.in ()))
821 // Thread Manager for managing task.
822 ACE_Thread_Manager thread_manager
;
825 Task
task (thread_manager
,
828 // Task activation flags.
832 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
836 task
.activate (flags
);
841 ACE_ERROR_RETURN ((LM_ERROR
,
842 "Cannot create thread with scheduling policy %s\n"
843 "because the user does not have the appropriate privileges, terminating program....\n"
844 "Check svc.conf options and/or run as root\n",
845 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
853 // Wait for task to exit.
855 thread_manager
.wait ();
856 ACE_ASSERT (result
!= -1);
858 catch (const CORBA::Exception
& ex
)
860 ex
._tao_print_exception ("Exception caught:");