Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Sched_Conf / Sched_Conf_Anomalies.cpp
blobfcaf868bf25fb7a042bd7a85bee79e0d5b5d0d6d
1 // This program performa a simple scheduler configuration run,
2 // and dumps the results of one scheduling into a C++ header file.
4 #include "ace/Sched_Params.h"
5 #include "ace/Get_Opt.h"
6 #include "tao/corba.h"
8 #include "orbsvcs/CosNamingC.h"
9 #include "orbsvcs/Scheduler_Factory.h"
10 #include "orbsvcs/Naming/Naming_Server.h"
14 const char* service_name = "ScheduleService";
16 const char* format_string = "{%-12s, %d, %d, %d, %d, %8d, "
17 "static_cast<RtecScheduler::Criticality_t> (%d), "
18 "static_cast<RtecScheduler::Importance_t> (%d), "
19 "%d, %d, %3d, %d, %d, "
20 "static_cast<RtecScheduler::Info_Type_t> (%d)}\n";
22 int
23 parse_args (int argc, ACE_TCHAR *argv [])
25 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("n:"));
26 int opt;
28 while ((opt = get_opt ()) != EOF)
30 switch (opt)
32 case 'n':
33 service_name = get_opt.opt_arg ();
34 break;
35 case '?':
36 default:
37 ACE_DEBUG ((LM_DEBUG,
38 "Usage: %s "
39 "-n service_name "
40 "\n",
41 argv[0]));
42 return -1;
46 return 0;
49 int
50 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
52 if (parse_args (argc, argv) != 0)
54 return 1;
57 // create initial data for supplier and consumer operations
58 const int operation_count = 8;
59 ACE_Scheduler_Factory::POD_RT_Info config_infos[operation_count] = {
60 // good supplier (no unresolved dependencies)
61 { "good_supplier", // entry point
62 0, // handle
63 5000, // worst case execution time
64 5000, // typical execution time (unused)
65 5000, // cached execution time
66 500000, // period (100 ns)
67 RtecScheduler::HIGH_CRITICALITY, // criticality
68 RtecScheduler::LOW_IMPORTANCE, // importance
69 0, // quantum (unused)
70 1, // threads
71 0, // OS priority
72 0, // Preemption subpriority
73 0, // Preemption priority
74 RtecScheduler::OPERATION // info type
76 // good consumer (no unresolved dependencies)
77 { "good_consumer", // entry point
78 1, // handle
79 5000, // worst case execution time
80 5000, // typical execution time (unused)
81 5000, // cached execution time
82 0, // period (100 ns)
83 RtecScheduler::HIGH_CRITICALITY, // criticality
84 RtecScheduler::LOW_IMPORTANCE, // importance
85 0, // quantum (unused)
86 0, // threads
87 0, // OS priority
88 0, // Preemption subpriority
89 0, // Preemption priority
90 RtecScheduler::OPERATION // info type
92 // supplier with unresolved remote dependencies
93 { "unresolved_remote_supplier", // entry point
94 2, // handle
95 5000, // worst case execution time
96 5000, // typical execution time (unused)
97 5000, // cached execution time
98 0, // period (100 ns)
99 RtecScheduler::HIGH_CRITICALITY, // criticality
100 RtecScheduler::LOW_IMPORTANCE, // importance
101 0, // quantum (unused)
102 0, // threads
103 0, // OS priority
104 0, // Preemption subpriority
105 0, // Preemption priority
106 RtecScheduler::REMOTE_DEPENDANT // info type
108 // consumer with unresolved remote dependencies
109 { "unresolved_remote_consumer", // entry point
110 3, // handle
111 5000, // worst case execution time
112 5000, // typical execution time (unused)
113 5000, // cached execution time
114 0, // period (100 ns)
115 RtecScheduler::HIGH_CRITICALITY, // criticality
116 RtecScheduler::LOW_IMPORTANCE, // importance
117 0, // quantum (unused)
118 0, // threads
119 0, // OS priority
120 0, // Preemption subpriority
121 0, // Preemption priority
122 RtecScheduler::OPERATION // info type
124 // supplier with unresolved local dependencies
125 { "unresolved_local_supplier", // entry point
126 4, // handle
127 5000, // worst case execution time
128 5000, // typical execution time (unused)
129 5000, // cached execution time
130 0, // period (100 ns)
131 RtecScheduler::HIGH_CRITICALITY, // criticality
132 RtecScheduler::LOW_IMPORTANCE, // importance
133 0, // quantum (unused)
134 0, // threads
135 0, // OS priority
136 0, // Preemption subpriority
137 0, // Preemption priority
138 RtecScheduler::OPERATION // info type
140 // consumer with unresolved local dependencies
141 { "unresolved_local_consumer", // entry point
142 5, // handle
143 5000, // worst case execution time
144 5000, // typical execution time (unused)
145 5000, // cached execution time
146 0, // period (100 ns)
147 RtecScheduler::HIGH_CRITICALITY, // criticality
148 RtecScheduler::LOW_IMPORTANCE, // importance
149 0, // quantum (unused)
150 0, // threads
151 0, // OS priority
152 0, // Preemption subpriority
153 0, // Preemption priority
154 RtecScheduler::OPERATION // info type
156 // consumer with unresolved local and remote dependencies
157 { "both_unresolved_consumer_1", // entry point
158 6, // handle
159 5000, // worst case execution time
160 5000, // typical execution time (unused)
161 5000, // cached execution time
162 0, // period (100 ns)
163 RtecScheduler::HIGH_CRITICALITY, // criticality
164 RtecScheduler::LOW_IMPORTANCE, // importance
165 0, // quantum (unused)
166 0, // threads
167 0, // OS priority
168 0, // Preemption subpriority
169 0, // Preemption priority
170 RtecScheduler::OPERATION // info type
172 // another consumer with unresolved
173 // local and remote dependencies
174 { "both_unresolved_consumer_2", // entry point
175 7, // handle
176 5000, // worst case execution time
177 5000, // typical execution time (unused)
178 5000, // cached execution time
179 0, // period (100 ns)
180 RtecScheduler::HIGH_CRITICALITY, // criticality
181 RtecScheduler::LOW_IMPORTANCE, // importance
182 0, // quantum (unused)
183 0, // threads
184 0, // OS priority
185 0, // Preemption subpriority
186 0, // Preemption priority
187 RtecScheduler::OPERATION // info type
193 // Initialize ORB.
194 CORBA::ORB_var orb =
195 CORBA::ORB_init (argc, argv, "internet");
197 CORBA::Object_var poa_object =
198 orb->resolve_initial_references("RootPOA");
200 if (CORBA::is_nil(poa_object.in ()))
201 ACE_ERROR_RETURN ((LM_ERROR,
202 " (%P|%t) Unable to initialize the POA.\n"),
205 PortableServer::POA_var root_poa =
206 PortableServer::POA::_narrow (poa_object.in());
208 PortableServer::POAManager_var poa_manager =
209 root_poa->the_POAManager ();
211 // Initialize the naming services
212 TAO_Naming_Client my_name_client;
213 if (my_name_client.init (orb.in ()) != 0)
214 ACE_ERROR_RETURN ((LM_ERROR,
215 " (%P|%t) Unable to initialize "
216 "the TAO_Naming_Client.\n"),
217 -1);
219 CosNaming::NamingContext_var context =
220 my_name_client.get_context ();
222 if (ACE_Scheduler_Factory::use_config (context.in (),
223 service_name) < 0)
224 ACE_ERROR_RETURN ((LM_ERROR,
225 " (%P|%t) Unable to bind to the scheduling service.\n"),
228 // create and initialize RT_Infos in the scheduler,
229 // make second half of array depend on first half.
230 for (int i = 0; i < operation_count; ++i)
232 // create the RT_Info
233 config_infos[i].handle =
234 ACE_Scheduler_Factory::server ()->create (config_infos[i].entry_point);
236 // initialize the RT_Info
237 ACE_Scheduler_Factory::server ()->
238 set (config_infos[i].handle,
239 static_cast<RtecScheduler::Criticality_t> (config_infos[i].criticality),
240 config_infos[i].worst_case_execution_time,
241 config_infos[i].typical_execution_time,
242 config_infos[i].cached_execution_time,
243 config_infos[i].period,
244 static_cast<RtecScheduler::Importance_t> (config_infos[i].importance),
245 config_infos[i].quantum,
246 config_infos[i].threads,
247 static_cast<RtecScheduler::Info_Type_t> (config_infos[i].info_type));
251 // register dependency of good consumer on good supplier
252 ACE_Scheduler_Factory::server ()->
253 add_dependency (config_infos[1].handle,
254 config_infos[0].handle,
255 1, // number of calls
256 RtecBase::ONE_WAY_CALL // type of dependency
259 // register dependency of consumer that will have unresolved remote
260 // dependencies on supplier with unresolved remote dependencies
261 ACE_Scheduler_Factory::server ()->
262 add_dependency (config_infos[3].handle,
263 config_infos[2].handle,
264 1, // number of calls
265 RtecBase::ONE_WAY_CALL // type of dependency
269 // register dependency of consumer that will have unresolved local
270 // dependencies on supplier with unresolved local dependencies
271 ACE_Scheduler_Factory::server ()->
272 add_dependency (config_infos[5].handle,
273 config_infos[4].handle,
274 1, // number of calls
275 RtecBase::ONE_WAY_CALL // type of dependency
279 // register dependencies on each supplier of first consumer that will
280 // have both unresolved local and unresolved remote dependencies.
281 ACE_Scheduler_Factory::server ()->
282 add_dependency (config_infos[6].handle,
283 config_infos[0].handle,
284 1, // number of calls
285 RtecBase::ONE_WAY_CALL // type of dependency
288 ACE_Scheduler_Factory::server ()->
289 add_dependency (config_infos[6].handle,
290 config_infos[2].handle,
291 1, // number of calls
292 RtecBase::ONE_WAY_CALL // type of dependency
295 ACE_Scheduler_Factory::server ()->
296 add_dependency (config_infos[6].handle,
297 config_infos[4].handle,
298 1, // number of calls
299 RtecBase::ONE_WAY_CALL // type of dependency
302 // Register dependencies on each of the other consumers by second
303 // consumer that will have both unresolved local and unresolved remote
304 // dependencies.
305 ACE_Scheduler_Factory::server ()->
306 add_dependency (config_infos[7].handle,
307 config_infos[1].handle,
308 1, // number of calls
309 RtecBase::ONE_WAY_CALL // type of dependency
312 ACE_Scheduler_Factory::server ()->
313 add_dependency (config_infos[7].handle,
314 config_infos[3].handle,
315 1, // number of calls
316 RtecBase::ONE_WAY_CALL // type of dependency
319 ACE_Scheduler_Factory::server ()->
320 add_dependency (config_infos[7].handle,
321 config_infos[5].handle,
322 1, // number of calls
323 RtecBase::ONE_WAY_CALL // type of dependency
326 ACE_Scheduler_Factory::server ()->
327 add_dependency (config_infos[7].handle,
328 config_infos[6].handle,
329 1, // number of calls
330 RtecBase::ONE_WAY_CALL // type of dependency
333 RtecScheduler::RT_Info_Set_var infos;
334 RtecScheduler::Dependency_Set_var deps;
335 RtecScheduler::Config_Info_Set_var configs;
336 RtecScheduler::Scheduling_Anomaly_Set_var anomalies;
338 ACE_Scheduler_Factory::server ()->compute_scheduling
339 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO,
340 ACE_SCOPE_THREAD),
341 ACE_Sched_Params::priority_max (ACE_SCHED_FIFO,
342 ACE_SCOPE_THREAD),
343 infos.out (), deps.out (),
344 configs.out (), anomalies.out ());
346 ACE_Scheduler_Factory::dump_schedule (infos.in (),
347 deps.in (),
348 configs.in (),
349 anomalies.in (),
350 "Sched_Conf_Anomalies_Runtime.h",
351 format_string);
353 catch (const CORBA::Exception& ex)
355 ex._tao_print_exception ("SYS_EX");
358 return 0;