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 (void);
40 int client_propagated (void);
42 void client_propagated (int);
44 int server_declared (void);
46 void server_declared (int);
48 RTCORBA::Priority
server_priority (void);
50 void server_priority (RTCORBA::Priority
);
56 int serviced_by_rt_tp (void);
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 (void);
71 void invocation_priority (RTCORBA::Priority
);
76 PortableServer::POA_var poa_
;
79 int client_propagated_
;
81 RTCORBA::Priority server_priority_
;
83 int serviced_by_rt_tp_
;
87 RTCORBA::Priority invocation_priority_
;
89 RTCORBA::Current_var current_
;
92 test_i::test_i (CORBA::ORB_ptr orb
,
93 PortableServer::POA_ptr poa
,
95 : orb_ (CORBA::ORB::_duplicate (orb
)),
96 poa_ (PortableServer::POA::_duplicate (poa
)),
98 client_propagated_ (0),
100 server_priority_ (0),
101 serviced_by_rt_tp_ (1),
102 invocation_priority_ (0)
104 CORBA::Object_var object
=
105 this->orb_
->resolve_initial_references ("RTCurrent");
108 RTCORBA::Current::_narrow (object
.in ());
112 test_i::client_propagated (void)
114 return this->client_propagated_
;
118 test_i::client_propagated (int client_propagated
)
120 this->client_propagated_
= client_propagated
;
124 test_i::server_declared (void)
126 return this->server_declared_
;
130 test_i::server_declared (int server_declared
)
132 this->server_declared_
= server_declared
;
136 test_i::server_priority (void)
138 return this->server_priority_
;
142 test_i::server_priority (RTCORBA::Priority server_priority
)
144 this->server_priority_
= server_priority
;
148 test_i::in_lane (void)
150 return this->in_lane_
;
154 test_i::in_lane (int in_lane
)
156 this->in_lane_
= in_lane
;
160 test_i::serviced_by_rt_tp (void)
162 return this->serviced_by_rt_tp_
;
166 test_i::serviced_by_rt_tp (int serviced_by_rt_tp
)
168 this->serviced_by_rt_tp_
= serviced_by_rt_tp
;
172 test_i::invocation_pool_and_lane (CORBA::ULong pool
,
180 test_i::invocation_pool (CORBA::ULong pool
)
186 test_i::invocation_lane (CORBA::ULong lane
)
192 test_i::invocation_priority (void)
194 return this->invocation_priority_
;
198 test_i::invocation_priority (RTCORBA::Priority invocation_priority
)
200 this->invocation_priority_
= invocation_priority
;
206 ACE_DEBUG ((LM_DEBUG
,
209 this->thread_info ("test_i::start");
211 ACE_DEBUG ((LM_DEBUG
,
214 Tests::ITERATOR
iterator (this->tests_
);
215 while (!iterator
.done ())
217 Test_Object_And_Servant
*test
= 0;
218 iterator
.next (test
);
220 setup_test_parameters (test
,
221 this->current_
.in (),
224 test
->object_
->method ();
226 CORBA::String_var ior
=
227 this->orb_
->object_to_string (test
->object_
.in ());
229 CORBA::Object_var object
=
230 this->orb_
->string_to_object (ior
.in ());
232 test_var test_from_string
=
233 test::_narrow (object
.in ());
235 test_from_string
->method ();
242 test_i::thread_info (const char *method_name
)
244 // Get the ORB_Core's TSS resources.
245 TAO_ORB_Core_TSS_Resources
*tss
=
246 this->orb_
->orb_core ()->get_tss_resources ();
248 /// Get the lane attribute in TSS.
249 TAO_Thread_Lane
*lane
=
250 (TAO_Thread_Lane
*) tss
->lane_
;
254 ACE_DEBUG ((LM_DEBUG
,
255 "(%t) %s (pool = %d; lane = %d); priority = %d (should be %d)\n",
259 this->current_
->the_priority (),
260 this->invocation_priority ()));
262 ACE_ASSERT (this->pool_
== lane
->pool ().id ());
263 ACE_ASSERT (this->lane_
== lane
->id ());
264 ACE_ASSERT (this->current_
->the_priority () ==
265 this->invocation_priority ());
269 ACE_DEBUG ((LM_DEBUG
,
270 "(%t) %s (default thread pool); priority = %d (should be %d)\n",
272 this->current_
->the_priority (),
273 this->invocation_priority ()));
275 ACE_ASSERT (this->pool_
== 0);
276 ACE_ASSERT (this->lane_
== 0);
277 ACE_ASSERT (this->current_
->the_priority () ==
278 this->invocation_priority ());
283 test_i::method (void)
285 this->thread_info ("test_i::method");
288 PortableServer::POA_ptr
289 test_i::_default_POA (void)
291 return PortableServer::POA::_duplicate (this->poa_
.in ());
295 setup_test_parameters (Test_Object_And_Servant
*test
,
296 RTCORBA::Current_ptr current
,
299 CORBA::Short current_thread_priority
;
303 current_thread_priority
=
304 current
->the_priority ();
306 catch (const CORBA::INITIALIZE
&)
310 current_thread_priority
= get_implicit_thread_CORBA_priority (orb
);
312 catch (const CORBA::Exception
&ex
)
314 ex
._tao_print_exception ("Exception in ::setup_test_parameters calling ::get_implicit_thread_CORBA_priority: ");
318 catch (const CORBA::Exception
& dc
)
320 dc
._tao_print_exception ("Exception in ::setup_test_parameters calling current->the_priority(): ");
324 current
->the_priority (current_thread_priority
);
326 if (!test
->servant_
->serviced_by_rt_tp () ||
327 test
->servant_
->client_propagated ())
329 test
->servant_
->invocation_priority (current_thread_priority
);
331 else if (test
->servant_
->server_declared ())
333 test
->servant_
->invocation_priority (test
->servant_
->server_priority ());
337 test
->servant_
->invocation_priority (default_thread_priority
);
340 if (test
->servant_
->client_propagated () &&
341 test
->servant_
->in_lane ())
343 if (current_thread_priority
== default_thread_priority
)
344 test
->servant_
->invocation_lane (0);
346 test
->servant_
->invocation_lane (1);
349 if (!test
->servant_
->serviced_by_rt_tp ())
351 // Get the ORB_Core's TSS resources.
352 TAO_ORB_Core_TSS_Resources
*tss
=
353 orb
->orb_core ()->get_tss_resources ();
355 /// Get the lane attribute in TSS.
356 TAO_Thread_Lane
*lane
=
357 (TAO_Thread_Lane
*) tss
->lane_
;
361 test
->servant_
->invocation_pool_and_lane (lane
->pool ().id (),
366 test
->servant_
->invocation_pool_and_lane (0, 0);
374 Server (CORBA::ORB_ptr orb
);
376 void create_servant_in_root_poa (void);
377 void create_poa_and_servant_with_tp_policy (const char *poa_name
,
378 int set_priority_model
,
379 RTCORBA::PriorityModel priority_model
);
380 void create_poa_and_servant_with_tp_with_lanes_policy (const char *poa_name
,
381 RTCORBA::PriorityModel priority_model
);
383 void start_testing (void);
385 //FUZZ: disable check_for_lack_ACE_OS
386 void shutdown (void);
387 //FUZZ: enable check_for_lack_ACE_OS
390 RTCORBA::RTORB_var rt_orb_
;
391 PortableServer::POA_var root_poa_
;
392 PortableServer::POAManager_var poa_manager_
;
393 RTCORBA::Current_var current_
;
397 CORBA::ULong stacksize_
;
398 CORBA::ULong static_threads_
;
399 CORBA::ULong dynamic_threads_
;
400 CORBA::Boolean allow_request_buffering_
;
401 CORBA::Boolean allow_borrowing_
;
402 CORBA::ULong max_buffered_requests_
;
403 CORBA::ULong max_request_buffer_size_
;
406 Server::Server (CORBA::ORB_ptr orb
)
407 : orb_ (CORBA::ORB::_duplicate (orb
)),
410 dynamic_threads_ (0),
411 allow_request_buffering_ (0),
412 allow_borrowing_ (0),
413 max_buffered_requests_ (0),
414 max_request_buffer_size_ (0)
416 CORBA::Object_var object
=
417 this->orb_
->resolve_initial_references ("RTORB");
420 RTCORBA::RTORB::_narrow (object
.in ());
423 this->orb_
->resolve_initial_references ("RTCurrent");
426 RTCORBA::Current::_narrow (object
.in ());
428 default_thread_priority
=
429 get_implicit_thread_CORBA_priority (this->orb_
.in ());
432 this->orb_
->resolve_initial_references ("RootPOA");
435 PortableServer::POA::_narrow (object
.in ());
438 this->root_poa_
->the_POAManager ();
440 this->poa_manager_
->activate ();
444 Server::create_servant_in_root_poa (void)
447 ACE_NEW_THROW_EX (servant
,
448 test_i (this->orb_
.in (),
449 this->root_poa_
.in (),
451 CORBA::NO_MEMORY ());
453 servant
->invocation_pool_and_lane (0, 0);
454 servant
->in_lane (0);
455 servant
->serviced_by_rt_tp (0);
457 PortableServer::ServantBase_var
safe_servant (servant
);
459 this->tests_
.size (this->tests_
.size () + 1);
460 this->tests_
[this->tests_
.size () - 1].servant_
=
462 this->tests_
[this->tests_
.size () - 1].object_
=
467 Server::create_poa_and_servant_with_tp_policy (const char *poa_name
,
468 int set_priority_model
,
469 RTCORBA::PriorityModel priority_model
)
471 RTCORBA::ThreadpoolId threadpool_id
=
472 this->rt_orb_
->create_threadpool (this->stacksize_
,
473 this->static_threads_
,
474 this->dynamic_threads_
,
475 default_thread_priority
,
476 this->allow_request_buffering_
,
477 this->max_buffered_requests_
,
478 this->max_request_buffer_size_
);
480 CORBA::Policy_var threadpool_policy
=
481 this->rt_orb_
->create_threadpool_policy (threadpool_id
);
483 CORBA::Policy_var priority_model_policy
=
484 this->rt_orb_
->create_priority_model_policy (priority_model
,
485 default_thread_priority
);
487 CORBA::PolicyList policies
;
489 policies
.length (policies
.length () + 1);
490 policies
[policies
.length () - 1] =
493 if (set_priority_model
)
495 policies
.length (policies
.length () + 1);
496 policies
[policies
.length () - 1] =
497 priority_model_policy
;
500 PortableServer::POA_var poa
=
501 this->root_poa_
->create_POA (poa_name
,
502 this->poa_manager_
.in (),
505 RTPortableServer::POA_var rt_poa
=
506 RTPortableServer::POA::_narrow (poa
.in ());
508 test_i
*servant1
= 0;
509 ACE_NEW_THROW_EX (servant1
,
510 test_i (this->orb_
.in (),
513 CORBA::NO_MEMORY ());
515 servant1
->in_lane (0);
517 PortableServer::ObjectId_var id1
;
519 if (set_priority_model
)
521 if (priority_model
== RTCORBA::CLIENT_PROPAGATED
)
523 servant1
->invocation_pool_and_lane (1, 0);
524 servant1
->client_propagated (1);
527 rt_poa
->activate_object (servant1
);
531 test_i
*servant2
= 0;
533 ACE_NEW_THROW_EX (servant2
,
534 test_i (this->orb_
.in (),
537 CORBA::NO_MEMORY ());
539 servant2
->in_lane (0);
541 PortableServer::ServantBase_var
safe_servant2 (servant2
);
543 PortableServer::ObjectId_var id2
;
545 servant1
->invocation_pool_and_lane (2, 0);
546 servant2
->invocation_pool_and_lane (2, 0);
547 servant1
->server_declared (1);
548 servant2
->server_declared (1);
549 servant1
->server_priority (default_thread_priority
+ 1);
550 servant2
->server_priority (default_thread_priority
);
553 rt_poa
->activate_object_with_priority (servant1
,
554 default_thread_priority
+ 1);
557 rt_poa
->activate_object_with_priority (servant2
,
558 default_thread_priority
);
560 CORBA::Object_var object2
=
561 poa
->id_to_reference (id2
.in ());
563 this->tests_
.size (this->tests_
.size () + 1);
564 this->tests_
[this->tests_
.size () - 1].object_
=
565 test::_narrow (object2
.in ());
566 this->tests_
[this->tests_
.size () - 1].servant_
=
572 servant1
->invocation_pool_and_lane (3, 0);
575 rt_poa
->activate_object (servant1
);
578 PortableServer::ServantBase_var
safe_servant (servant1
);
580 CORBA::Object_var object1
=
581 poa
->id_to_reference (id1
.in ());
583 this->tests_
.size (this->tests_
.size () + 1);
584 this->tests_
[this->tests_
.size () - 1].object_
=
585 test::_narrow (object1
.in ());
586 this->tests_
[this->tests_
.size () - 1].servant_
=
591 Server::create_poa_and_servant_with_tp_with_lanes_policy (const char *poa_name
,
592 RTCORBA::PriorityModel priority_model
)
594 RTCORBA::ThreadpoolLanes
lanes (2);
597 lanes
[0].lane_priority
= default_thread_priority
;
598 lanes
[0].static_threads
= this->static_threads_
;
599 lanes
[0].dynamic_threads
= this->dynamic_threads_
;
601 lanes
[1].lane_priority
= default_thread_priority
+ 1;
602 lanes
[1].static_threads
= this->static_threads_
;
603 lanes
[1].dynamic_threads
= this->dynamic_threads_
;
605 RTCORBA::ThreadpoolId threadpool_id
=
606 this->rt_orb_
->create_threadpool_with_lanes (this->stacksize_
,
608 this->allow_borrowing_
,
609 this->allow_request_buffering_
,
610 this->max_buffered_requests_
,
611 this->max_request_buffer_size_
);
613 CORBA::Policy_var threadpool_policy
=
614 this->rt_orb_
->create_threadpool_policy (threadpool_id
);
616 CORBA::Policy_var priority_model_policy
=
617 this->rt_orb_
->create_priority_model_policy (priority_model
,
618 default_thread_priority
);
620 CORBA::PolicyList policies
;
622 policies
.length (policies
.length () + 1);
623 policies
[policies
.length () - 1] =
626 policies
.length (policies
.length () + 1);
627 policies
[policies
.length () - 1] =
628 priority_model_policy
;
630 PortableServer::POA_var poa
=
631 this->root_poa_
->create_POA (poa_name
,
632 this->poa_manager_
.in (),
635 RTPortableServer::POA_var rt_poa
=
636 RTPortableServer::POA::_narrow (poa
.in ());
638 test_i
*servant1
= 0;
639 ACE_NEW_THROW_EX (servant1
,
640 test_i (this->orb_
.in (),
643 CORBA::NO_MEMORY ());
645 servant1
->in_lane (1);
647 PortableServer::ServantBase_var
safe_servant1 (servant1
);
649 PortableServer::ObjectId_var id1
;
651 if (priority_model
== RTCORBA::CLIENT_PROPAGATED
)
653 servant1
->invocation_pool (4);
654 servant1
->client_propagated (1);
657 rt_poa
->activate_object (servant1
);
661 test_i
*servant2
= 0;
663 ACE_NEW_THROW_EX (servant2
,
664 test_i (this->orb_
.in (),
667 CORBA::NO_MEMORY ());
669 servant2
->in_lane (1);
671 PortableServer::ServantBase_var
safe_servant2 (servant2
);
673 PortableServer::ObjectId_var id2
;
675 servant1
->invocation_pool_and_lane (5, 1);
676 servant2
->invocation_pool_and_lane (5, 0);
677 servant1
->server_declared (1);
678 servant2
->server_declared (1);
679 servant1
->server_priority (default_thread_priority
+ 1);
680 servant2
->server_priority (default_thread_priority
);
683 rt_poa
->activate_object_with_priority (servant1
,
684 default_thread_priority
+ 1);
687 rt_poa
->activate_object_with_priority (servant2
,
688 default_thread_priority
);
690 CORBA::Object_var object2
=
691 poa
->id_to_reference (id2
.in ());
693 this->tests_
.size (this->tests_
.size () + 1);
694 this->tests_
[this->tests_
.size () - 1].object_
=
695 test::_narrow (object2
.in ());
696 this->tests_
[this->tests_
.size () - 1].servant_
=
700 CORBA::Object_var object1
=
701 poa
->id_to_reference (id1
.in ());
703 this->tests_
.size (this->tests_
.size () + 1);
704 this->tests_
[this->tests_
.size () - 1].object_
=
705 test::_narrow (object1
.in ());
706 this->tests_
[this->tests_
.size () - 1].servant_
=
711 Server::start_testing (void)
713 Tests::ITERATOR
iterator (this->tests_
);
714 while (!iterator
.done ())
716 Test_Object_And_Servant
*test
= 0;
717 iterator
.next (test
);
719 setup_test_parameters (test
,
720 this->current_
.in (),
723 test
->object_
->start ();
732 this->start_testing ();
734 ACE_DEBUG ((LM_DEBUG
,
735 "\n\n*** Changing priority to be higher ***\n\n"));
737 this->current_
->the_priority (default_thread_priority
+ 1);
739 this->start_testing ();
743 Server::shutdown (void)
745 this->orb_
->shutdown (true);
747 this->orb_
->destroy ();
750 class Task
: public ACE_Task_Base
754 Task (ACE_Thread_Manager
&thread_manager
,
763 Task::Task (ACE_Thread_Manager
&thread_manager
,
765 : ACE_Task_Base (&thread_manager
),
766 orb_ (CORBA::ORB::_duplicate (orb
))
775 Server
server (this->orb_
.in ());
777 server
.create_servant_in_root_poa ();
779 server
.create_poa_and_servant_with_tp_policy ("tp_client_propagated_poa",
781 RTCORBA::CLIENT_PROPAGATED
);
783 server
.create_poa_and_servant_with_tp_policy ("tp_server_declared_poa",
785 RTCORBA::SERVER_DECLARED
);
787 server
.create_poa_and_servant_with_tp_policy ("tp_no_priority_model_poa",
789 RTCORBA::CLIENT_PROPAGATED
);
791 server
.create_poa_and_servant_with_tp_with_lanes_policy ("tp_with_lanes_client_propagated_poa",
792 RTCORBA::CLIENT_PROPAGATED
);
794 server
.create_poa_and_servant_with_tp_with_lanes_policy ("tp_with_lanes_server_declared_poa",
795 RTCORBA::SERVER_DECLARED
);
801 catch (const CORBA::Exception
& ex
)
803 ex
._tao_print_exception ("Exception caught:");
811 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
816 CORBA::ORB_init (argc
,
819 // Make sure we can support multiple priorities that are
820 // required for this test.
821 if (!check_supported_priorities (orb
.in ()))
824 // Thread Manager for managing task.
825 ACE_Thread_Manager thread_manager
;
828 Task
task (thread_manager
,
831 // Task activation flags.
835 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
839 task
.activate (flags
);
844 ACE_ERROR_RETURN ((LM_ERROR
,
845 "Cannot create thread with scheduling policy %s\n"
846 "because the user does not have the appropriate privileges, terminating program....\n"
847 "Check svc.conf options and/or run as root\n",
848 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
856 // Wait for task to exit.
858 thread_manager
.wait ();
859 ACE_ASSERT (result
!= -1);
861 catch (const CORBA::Exception
& ex
)
863 ex
._tao_print_exception ("Exception caught:");