Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / orbsvcs / tests / Sched_Conf / Sched_Conf_Runtime.cpp
blobf720fdbabb93e0ba660e242502e2ee6f47ec93da
1 // This program exercises a run-time scheduler,
2 // using the config run generated C++ header file.
4 #include "ace/Sched_Params.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_string.h"
7 #include "tao/corba.h"
9 #include "orbsvcs/CosNamingC.h"
10 #include "orbsvcs/Scheduler_Factory.h"
11 #include "orbsvcs/Naming/Naming_Server.h"
13 #include "Sched_Conf_Runtime.h"
18 int
19 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
21 try
23 // Initialize ORB.
24 CORBA::ORB_var orb =
25 CORBA::ORB_init (argc, argv, "internet");
27 CORBA::Object_var poa_object =
28 orb->resolve_initial_references("RootPOA");
30 if (CORBA::is_nil(poa_object.in ()))
31 ACE_ERROR_RETURN ((LM_ERROR,
32 " (%P|%t) Unable to initialize the POA.\n"),
33 1);
35 PortableServer::POA_var root_poa =
36 PortableServer::POA::_narrow (poa_object.in());
38 PortableServer::POAManager_var poa_manager =
39 root_poa->the_POAManager ();
41 poa_manager->activate ();
43 // Store a pointer to the local run-time scheduler.
44 RtecScheduler::Scheduler_ptr runtime_scheduler =
45 ACE_Scheduler_Factory::server ();
47 // Some useful variables for retrieving values from the scheduler.
48 RtecScheduler::RT_Info *rt_info = 0;
49 RtecScheduler::OS_Priority priority;
50 RtecScheduler::Preemption_Subpriority_t subpriority;
51 RtecScheduler::Preemption_Priority_t p_priority;
52 RtecScheduler::Dispatching_Type_t dispatching_type;
54 for (int i = 0; i < infos_size; ++i)
56 // Make sure the correct handle is returned by the
57 // run-time scheduler's create and lookup methods.
58 ACE_ASSERT (infos [i].handle ==
59 runtime_scheduler->create (infos [i].entry_point));
61 ACE_ASSERT (infos [i].handle ==
62 runtime_scheduler->lookup (infos [i].entry_point));
64 // Make sure the values in the RT_Info returned by get are OK.
65 delete rt_info;
66 rt_info = runtime_scheduler->get (infos [i].handle);
68 ACE_ASSERT (rt_info != 0);
69 ACE_ASSERT (ACE_OS::strcmp (rt_info->entry_point,
70 infos [i].entry_point) == 0);
71 ACE_ASSERT (rt_info->handle ==
72 infos [i].handle);
73 ACE_ASSERT (rt_info->worst_case_execution_time ==
74 infos [i].worst_case_execution_time);
75 ACE_ASSERT (rt_info->typical_execution_time ==
76 infos [i].typical_execution_time);
77 ACE_ASSERT (rt_info->cached_execution_time ==
78 infos [i].cached_execution_time);
79 ACE_ASSERT (rt_info->period ==
80 infos [i].period);
81 ACE_ASSERT (rt_info->criticality ==
82 static_cast<RtecScheduler::Criticality_t> (infos [i].criticality));
83 ACE_ASSERT (rt_info->importance ==
84 static_cast<RtecScheduler::Importance_t> (infos [i].importance));
85 ACE_ASSERT (rt_info->quantum ==
86 infos [i].quantum);
87 ACE_ASSERT (rt_info->threads ==
88 infos [i].threads);
89 ACE_ASSERT (rt_info->priority ==
90 infos [i].priority);
91 ACE_ASSERT (rt_info->preemption_subpriority ==
92 infos [i].static_subpriority);
93 ACE_ASSERT (rt_info->preemption_priority ==
94 infos [i].preemption_priority);
95 ACE_ASSERT (rt_info->info_type ==
96 static_cast<RtecScheduler::Info_Type_t> (infos [i].info_type));
98 // Make sure the values in the scheduler's internal RT_Info are OK.
99 // Scheduler will generate messages if any values don't match.
100 runtime_scheduler->set (infos [i].handle,
101 static_cast<RtecScheduler::Criticality_t> (infos [i].criticality),
102 infos [i].worst_case_execution_time,
103 infos [i].typical_execution_time,
104 infos [i].cached_execution_time,
105 infos [i].period,
106 static_cast<RtecScheduler::Importance_t> (infos [i].importance),
107 infos [i].quantum,
108 infos [i].threads,
109 static_cast<RtecScheduler::Info_Type_t> (infos [i].info_type));
111 // Make sure the correct priority values are returned.
112 runtime_scheduler->priority (infos [i].handle,
113 priority,
114 subpriority,
115 p_priority);
117 ACE_ASSERT (priority == infos [i].priority);
118 ACE_ASSERT (subpriority == infos [i].static_subpriority);
119 ACE_ASSERT (p_priority == infos [i].preemption_priority);
120 runtime_scheduler->entry_point_priority (infos [i].entry_point,
121 priority,
122 subpriority,
123 p_priority);
125 ACE_ASSERT (priority == infos [i].priority);
126 ACE_ASSERT (subpriority == infos [i].static_subpriority);
127 ACE_ASSERT (p_priority == infos [i].preemption_priority);
130 for (int j = 0; j < configs_size; ++j)
132 // Make sure the correct preemption priority is stored.
133 ACE_ASSERT (j == configs [j].preemption_priority);
135 // Make sure the correct queue configuration values are returned.
136 runtime_scheduler->
137 dispatch_configuration (configs [j].preemption_priority,
138 priority,
139 dispatching_type);
141 ACE_ASSERT (priority == configs [j].thread_priority);
142 ACE_ASSERT (dispatching_type == configs [j].dispatching_type);
145 catch (const CORBA::Exception& ex)
147 ex._tao_print_exception ("SYS_EX");
150 return 0;