1 #include "ace/Get_Opt.h"
3 #include "tao/ORB_Core.h"
5 #include "tao/RTPortableServer/RTPortableServer.h"
6 #include "../check_supported_priorities.cpp"
12 test_i (CORBA::ORB_ptr orb
,
13 PortableServer::POA_ptr poa
,
14 CORBA::Short server_priority
,
15 CORBA::Short client_priority
);
17 CORBA::Short
method ();
19 void prioritized_method ();
21 //FUZZ: disable check_for_lack_ACE_OS
23 //FUZZ: enable check_for_lack_ACE_OS
25 PortableServer::POA_ptr
_default_POA ();
29 PortableServer::POA_var poa_
;
30 CORBA::Short server_priority_
;
31 CORBA::Short client_priority_
;
34 test_i::test_i (CORBA::ORB_ptr orb
,
35 PortableServer::POA_ptr poa
,
36 CORBA::Short server_priority
,
37 CORBA::Short client_priority
)
38 : orb_ (CORBA::ORB::_duplicate (orb
)),
39 poa_ (PortableServer::POA::_duplicate (poa
)),
40 server_priority_ (server_priority
),
41 client_priority_ (client_priority
)
51 return this->client_priority_
;
55 test_i::prioritized_method ()
57 CORBA::Object_var object
=
58 this->orb_
->resolve_initial_references ("RTCurrent");
60 RTCORBA::Current_var current
=
61 RTCORBA::Current::_narrow (object
.in ());
63 CORBA::Short priority
=
64 current
->the_priority ();
67 "test_i::prioritized_method: client = %d server = %d (should be %d)\n",
68 this->client_priority_
,
70 this->server_priority_
));
72 ACE_ASSERT (this->server_priority_
== priority
);
79 "test_i::shutdown\n"));
81 this->orb_
->shutdown (false);
84 PortableServer::POA_ptr
85 test_i::_default_POA ()
87 return PortableServer::POA::_duplicate (this->poa_
.in ());
90 static CORBA::Short server_priority
;
91 static CORBA::Short client_priority
;
92 static CORBA::ULong stacksize
= 0;
93 static CORBA::ULong static_threads
= 2;
94 static CORBA::ULong dynamic_threads
= 0;
95 static RTCORBA::Priority default_thread_priority
;
96 static CORBA::Boolean allow_request_buffering
= 0;
97 static CORBA::ULong max_buffered_requests
= 0;
98 static CORBA::ULong max_request_buffer_size
= 0;
99 static CORBA::Boolean allow_borrowing
= 0;
102 parse_args (int argc
, ACE_TCHAR
**argv
)
104 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:c:"));
107 while ((c
= get_opts ()) != -1)
111 ::server_priority
= ACE_OS::atoi (get_opts
.opt_arg ());
115 ::client_priority
= ACE_OS::atoi (get_opts
.opt_arg ());
120 ACE_ERROR_RETURN ((LM_ERROR
,
122 "-s server priority "
123 "-c client priority "
133 write_iors_to_file (CORBA::Object_ptr object
,
135 const char *filename
)
138 ACE_OS::fopen (filename
, "w");
139 ACE_ASSERT (file
!= 0);
141 CORBA::String_var ior
=
142 orb
->object_to_string (object
);
146 ACE_OS::fprintf (file
,
150 ACE_ASSERT (result
== ACE_OS::strlen (ior
.in ()));
151 ACE_UNUSED_ARG (result
);
153 ACE_OS::fclose (file
);
159 server (CORBA::ORB_ptr orb
,
160 RTCORBA::RTORB_ptr rt_orb
,
161 PortableServer::POA_ptr root_poa
,
162 PortableServer::POAManager_ptr poa_manager
);
164 void test_root_poa ();
165 void test_child_poa ();
167 typedef void (server::*test_function
) (CORBA::PolicyList
&policies
,
168 CORBA::Short server_priority
,
169 CORBA::Short client_priority
,
170 const char *test_name
);
172 void test_default_pool_poa (CORBA::Short server_priority
,
173 CORBA::Short client_priority
,
174 server::test_function function
,
175 const char *test_name
);
177 void test_bands_poa (CORBA::PolicyList
&policies
,
178 CORBA::Short server_priority
,
179 CORBA::Short client_priority
,
180 server::test_function function
,
181 const char *test_name
);
183 void test_no_lanes_poa (CORBA::Short server_priority
,
184 CORBA::Short client_priority
,
185 server::test_function function
,
186 const char *test_name
);
188 void test_lanes_poa (CORBA::Short server_priority
,
189 CORBA::Short client_priority
,
190 server::test_function function
,
191 const char *test_name
);
193 void test_no_bands_client_propagated_poa (CORBA::PolicyList
&policies
,
194 CORBA::Short server_priority
,
195 CORBA::Short client_priority
,
196 const char *test_name
);
198 void test_bands_client_propagated_poa (CORBA::PolicyList
&policies
,
199 CORBA::Short server_priority
,
200 CORBA::Short client_priority
,
201 const char *test_name
);
203 void test_no_bands_server_declared_poa (CORBA::PolicyList
&policies
,
204 CORBA::Short server_priority
,
205 CORBA::Short client_priority
,
206 const char *test_name
);
208 void test_bands_server_declared_poa (CORBA::PolicyList
&policies
,
209 CORBA::Short server_priority
,
210 CORBA::Short client_priority
,
211 const char *test_name
);
213 void test_default_pool_no_bands_client_propagated_poa ();
215 void test_no_lanes_no_bands_client_propagated_poa ();
217 void test_lanes_no_bands_client_propagated_poa ();
219 void test_default_pool_bands_client_propagated_poa ();
221 void test_no_lanes_bands_client_propagated_poa ();
223 void test_lanes_bands_client_propagated_poa ();
225 void test_default_pool_no_bands_server_declared_poa ();
227 void test_no_lanes_no_bands_server_declared_poa ();
229 void test_lanes_no_bands_server_declared_poa ();
231 void test_default_pool_bands_server_declared_poa ();
233 void test_no_lanes_bands_server_declared_poa ();
235 void test_lanes_bands_server_declared_poa ();
239 RTCORBA::RTORB_var rt_orb_
;
240 PortableServer::POA_var root_poa_
;
241 PortableServer::POAManager_var poa_manager_
;
244 server::server (CORBA::ORB_ptr orb
,
245 RTCORBA::RTORB_ptr rt_orb
,
246 PortableServer::POA_ptr root_poa
,
247 PortableServer::POAManager_ptr poa_manager
)
248 : orb_ (CORBA::ORB::_duplicate (orb
)),
249 rt_orb_ (RTCORBA::RTORB::_duplicate (rt_orb
)),
250 root_poa_ (PortableServer::POA::_duplicate (root_poa
)),
251 poa_manager_ (PortableServer::POAManager::_duplicate (poa_manager
))
256 server::test_root_poa ()
259 ACE_NEW_THROW_EX (servant
,
260 test_i (this->orb_
.in (),
261 this->root_poa_
.in (),
262 TAO_INVALID_PRIORITY
,
263 TAO_INVALID_PRIORITY
),
264 CORBA::NO_MEMORY ());
266 PortableServer::ServantBase_var
safe_servant (servant
);
268 PortableServer::ObjectId_var id
=
269 this->root_poa_
->activate_object (servant
);
271 CORBA::Object_var object_act
= this->root_poa_
->id_to_reference (id
.in ());
274 test::_narrow (object_act
.in ());
276 write_iors_to_file (test
.in (),
282 server::test_child_poa ()
284 CORBA::PolicyList policies
;
286 policies
[policies
.length () - 1] =
287 this->root_poa_
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
289 PortableServer::POA_var poa
=
290 this->root_poa_
->create_POA ("child",
291 this->poa_manager_
.in (),
295 ACE_NEW_THROW_EX (servant
,
296 test_i (this->orb_
.in (),
298 TAO_INVALID_PRIORITY
,
299 TAO_INVALID_PRIORITY
),
300 CORBA::NO_MEMORY ());
302 PortableServer::ServantBase_var
safe_servant (servant
);
304 PortableServer::ObjectId_var id
=
305 poa
->activate_object (servant
);
307 CORBA::Object_var object_act
= poa
->id_to_reference (id
.in ());
310 test::_narrow (object_act
.in ());
312 write_iors_to_file (test
.in (),
318 server::test_default_pool_poa (CORBA::Short server_priority
,
319 CORBA::Short client_priority
,
320 server::test_function function
,
321 const char *test_name
)
323 CORBA::PolicyList empty_policies
;
324 (this->*function
) (empty_policies
,
331 server::test_bands_poa (CORBA::PolicyList
&policies
,
332 CORBA::Short server_priority
,
333 CORBA::Short client_priority
,
334 server::test_function function
,
335 const char *test_name
)
337 RTCORBA::PriorityBands bands
;
340 bands
[0].low
= default_thread_priority
;
341 bands
[0].high
= default_thread_priority
;
342 bands
[1].low
= ::server_priority
- 1;
343 bands
[1].high
= ::server_priority
+ 1;
344 bands
[2].low
= ::client_priority
- 1;
345 bands
[2].high
= ::client_priority
+ 1;
347 policies
.length (policies
.length () + 1);
348 policies
[policies
.length () - 1] =
349 this->rt_orb_
->create_priority_banded_connection_policy (bands
);
351 (this->*function
) (policies
,
358 server::test_no_lanes_poa (CORBA::Short server_priority
,
359 CORBA::Short client_priority
,
360 server::test_function function
,
361 const char *test_name
)
363 RTCORBA::ThreadpoolId threadpool_id
=
364 this->rt_orb_
->create_threadpool (stacksize
,
367 default_thread_priority
,
368 allow_request_buffering
,
369 max_buffered_requests
,
370 max_request_buffer_size
);
372 CORBA::Policy_var threadpool_policy
=
373 this->rt_orb_
->create_threadpool_policy (threadpool_id
);
375 CORBA::PolicyList policies
;
380 (this->*function
) (policies
,
387 server::test_lanes_poa (CORBA::Short server_priority
,
388 CORBA::Short client_priority
,
389 server::test_function function
,
390 const char *test_name
)
392 RTCORBA::ThreadpoolLanes lanes
;
395 lanes
[0].lane_priority
= ::client_priority
;
396 lanes
[0].static_threads
= static_threads
;
397 lanes
[0].dynamic_threads
= dynamic_threads
;
399 lanes
[1].lane_priority
= ::server_priority
;
400 lanes
[1].static_threads
= static_threads
;
401 lanes
[1].dynamic_threads
= dynamic_threads
;
403 lanes
[2].lane_priority
= default_thread_priority
;
404 lanes
[2].static_threads
= static_threads
;
405 lanes
[2].dynamic_threads
= dynamic_threads
;
407 RTCORBA::ThreadpoolId threadpool_id
=
408 this->rt_orb_
->create_threadpool_with_lanes (stacksize
,
411 allow_request_buffering
,
412 max_buffered_requests
,
413 max_request_buffer_size
);
415 CORBA::Policy_var threadpool_policy
=
416 this->rt_orb_
->create_threadpool_policy (threadpool_id
);
418 CORBA::PolicyList policies
;
423 (this->*function
) (policies
,
430 server::test_no_bands_client_propagated_poa (CORBA::PolicyList
&policies
,
431 CORBA::Short server_priority
,
432 CORBA::Short client_priority
,
433 const char *test_name
)
435 policies
.length (policies
.length () + 1);
436 policies
[policies
.length () - 1] =
437 this->rt_orb_
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
438 default_thread_priority
);
440 PortableServer::POA_var poa
=
441 this->root_poa_
->create_POA (test_name
,
442 this->poa_manager_
.in (),
445 RTPortableServer::POA_var rt_poa
=
446 RTPortableServer::POA::_narrow (poa
.in ());
449 ACE_NEW_THROW_EX (servant
,
450 test_i (this->orb_
.in (),
454 CORBA::NO_MEMORY ());
456 PortableServer::ServantBase_var
safe_servant (servant
);
458 PortableServer::ObjectId_var id
=
459 rt_poa
->activate_object (servant
);
461 CORBA::Object_var object
=
462 poa
->id_to_reference (id
.in ());
464 write_iors_to_file (object
.in (),
470 server::test_bands_client_propagated_poa (CORBA::PolicyList
&policies
,
471 CORBA::Short server_priority
,
472 CORBA::Short client_priority
,
473 const char *test_name
)
475 this->test_bands_poa (policies
,
478 &server::test_no_bands_client_propagated_poa
,
483 server::test_default_pool_no_bands_client_propagated_poa ()
485 this->test_default_pool_poa (::client_priority
+ 1,
486 ::client_priority
+ 1,
487 &server::test_no_bands_client_propagated_poa
,
488 "default_pool_no_bands_client_propagated");
492 server::test_no_lanes_no_bands_client_propagated_poa ()
494 this->test_no_lanes_poa (::client_priority
- 1,
495 ::client_priority
- 1,
496 &server::test_no_bands_client_propagated_poa
,
497 "no_lanes_no_bands_client_propagated");
501 server::test_lanes_no_bands_client_propagated_poa ()
503 this->test_lanes_poa (::client_priority
,
505 &server::test_no_bands_client_propagated_poa
,
506 "lanes_no_bands_client_propagated");
510 server::test_default_pool_bands_client_propagated_poa ()
512 this->test_default_pool_poa (::client_priority
+ 1,
513 ::client_priority
+ 1,
514 &server::test_bands_client_propagated_poa
,
515 "default_pool_bands_client_propagated");
519 server::test_no_lanes_bands_client_propagated_poa ()
521 this->test_no_lanes_poa (::client_priority
- 1,
522 ::client_priority
- 1,
523 &server::test_bands_client_propagated_poa
,
524 "no_lanes_bands_client_propagated");
528 server::test_lanes_bands_client_propagated_poa ()
530 this->test_lanes_poa (::client_priority
,
531 ::client_priority
+ 1,
532 &server::test_bands_client_propagated_poa
,
533 "lanes_bands_client_propagated");
537 server::test_no_bands_server_declared_poa (CORBA::PolicyList
&policies
,
538 CORBA::Short server_priority
,
539 CORBA::Short client_priority
,
540 const char *test_name
)
542 policies
.length (policies
.length () + 1);
543 policies
[policies
.length () - 1] =
544 this->rt_orb_
->create_priority_model_policy (RTCORBA::SERVER_DECLARED
,
545 default_thread_priority
);
547 PortableServer::POA_var poa
=
548 this->root_poa_
->create_POA (test_name
,
549 this->poa_manager_
.in (),
552 RTPortableServer::POA_var rt_poa
=
553 RTPortableServer::POA::_narrow (poa
.in ());
556 ACE_NEW_THROW_EX (servant
,
557 test_i (this->orb_
.in (),
561 CORBA::NO_MEMORY ());
563 PortableServer::ServantBase_var
safe_servant (servant
);
565 PortableServer::ObjectId_var id
=
566 rt_poa
->activate_object_with_priority (servant
,
569 CORBA::Object_var object
=
570 poa
->id_to_reference (id
.in ());
572 write_iors_to_file (object
.in (),
578 server::test_bands_server_declared_poa (CORBA::PolicyList
&policies
,
579 CORBA::Short server_priority
,
580 CORBA::Short client_priority
,
581 const char *test_name
)
583 this->test_bands_poa (policies
,
586 &server::test_no_bands_server_declared_poa
,
591 server::test_default_pool_no_bands_server_declared_poa ()
593 this->test_default_pool_poa (::server_priority
,
594 ::client_priority
+ 1,
595 &server::test_no_bands_server_declared_poa
,
596 "default_pool_no_bands_server_declared");
600 server::test_no_lanes_no_bands_server_declared_poa ()
602 this->test_no_lanes_poa (::server_priority
,
603 ::client_priority
- 1,
604 &server::test_no_bands_server_declared_poa
,
605 "no_lanes_no_bands_server_declared");
609 server::test_lanes_no_bands_server_declared_poa ()
611 this->test_lanes_poa (::server_priority
,
612 ::client_priority
+ 1,
613 &server::test_no_bands_server_declared_poa
,
614 "lanes_no_bands_server_declared");
618 server::test_default_pool_bands_server_declared_poa ()
620 this->test_default_pool_poa (::server_priority
,
621 ::client_priority
- 1,
622 &server::test_bands_server_declared_poa
,
623 "default_pool_bands_server_declared");
627 server::test_no_lanes_bands_server_declared_poa ()
629 this->test_no_lanes_poa (::server_priority
,
630 ::client_priority
+ 1,
631 &server::test_bands_server_declared_poa
,
632 "no_lanes_bands_server_declared");
636 server::test_lanes_bands_server_declared_poa ()
638 this->test_lanes_poa (::server_priority
,
639 ::client_priority
- 1,
640 &server::test_bands_server_declared_poa
,
641 "lanes_bands_server_declared");
644 class Task
: public ACE_Task_Base
647 Task (ACE_Thread_Manager
&thread_manager
,
655 Task::Task (ACE_Thread_Manager
&thread_manager
,
657 : ACE_Task_Base (&thread_manager
),
658 orb_ (CORBA::ORB::_duplicate (orb
))
667 CORBA::Object_var object
=
668 this->orb_
->resolve_initial_references ("RTORB");
670 RTCORBA::RTORB_var rt_orb
=
671 RTCORBA::RTORB::_narrow (object
.in ());
673 // The following sets the current thread to the lowest priority
674 // for this scheduling policy. This will give us the biggest
675 // range on NT since the default priority is 0 where as the
676 // lowest priority is -15.
677 ACE_hthread_t current_thread
;
678 ACE_Thread::self (current_thread
);
681 this->orb_
->orb_core ()->orb_params ()->ace_sched_policy ();
683 int minimum_priority
=
684 ACE_Sched_Params::priority_min (sched_policy
);
687 ACE_Thread::setprio (current_thread
,
693 this->orb_
->resolve_initial_references ("RTCurrent");
695 RTCORBA::Current_var current
=
696 RTCORBA::Current::_narrow (object
.in ());
698 default_thread_priority
=
699 get_implicit_thread_CORBA_priority (this->orb_
.in ());
702 default_thread_priority
+ 2;
705 default_thread_priority
+ 5;
708 this->orb_
->resolve_initial_references ("RootPOA");
710 PortableServer::POA_var root_poa
=
711 PortableServer::POA::_narrow (object
.in ());
713 PortableServer::POAManager_var poa_manager
=
714 root_poa
->the_POAManager ();
716 server
server (this->orb_
.in (),
721 server
.test_root_poa ();
723 server
.test_child_poa ();
725 server
.test_default_pool_no_bands_client_propagated_poa ();
727 server
.test_default_pool_no_bands_server_declared_poa ();
729 server
.test_no_lanes_no_bands_client_propagated_poa ();
731 server
.test_no_lanes_no_bands_server_declared_poa ();
733 server
.test_lanes_no_bands_client_propagated_poa ();
735 server
.test_lanes_no_bands_server_declared_poa ();
737 server
.test_default_pool_bands_client_propagated_poa ();
739 server
.test_default_pool_bands_server_declared_poa ();
741 server
.test_no_lanes_bands_client_propagated_poa ();
743 server
.test_no_lanes_bands_server_declared_poa ();
745 server
.test_lanes_bands_client_propagated_poa ();
747 server
.test_lanes_bands_server_declared_poa ();
749 poa_manager
->activate ();
753 this->orb_
->destroy ();
755 catch (const CORBA::Exception
& ex
)
757 ex
._tao_print_exception ("Exception caught");
765 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
770 CORBA::ORB_init (argc
, argv
);
773 parse_args (argc
, argv
);
777 // Make sure we can support multiple priorities that are required
779 if (!check_supported_priorities (orb
.in ()))
782 // Thread Manager for managing task.
783 ACE_Thread_Manager thread_manager
;
786 Task
task (thread_manager
,
789 // Task activation flags.
793 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
797 task
.activate (flags
);
802 ACE_ERROR_RETURN ((LM_ERROR
,
803 "Cannot create thread with scheduling policy %C\n"
804 "because the user does not have the appropriate privileges, terminating program....\n"
805 "Check svc.conf options and/or run as root\n",
806 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
814 // Wait for task to exit.
816 thread_manager
.wait ();
817 ACE_ASSERT (result
!= -1);
819 catch (const CORBA::Exception
& ex
)
821 ex
._tao_print_exception ("Exception caught");