Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / Sched_Conf / Sched_Conf_Anomalies.cpp
blobc6d9e993aa812aae3275ea1549e4c1172b6ee397
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"
13 const char* service_name = "ScheduleService";
15 const char* format_string = "{%-12s, %d, %d, %d, %d, %8d, "
16 "static_cast<RtecScheduler::Criticality_t> (%d), "
17 "static_cast<RtecScheduler::Importance_t> (%d), "
18 "%d, %d, %3d, %d, %d, "
19 "static_cast<RtecScheduler::Info_Type_t> (%d)}\n";
21 int
22 parse_args (int argc, ACE_TCHAR *argv [])
24 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("n:"));
25 int opt;
27 while ((opt = get_opt ()) != EOF)
29 switch (opt)
31 case 'n':
32 service_name = get_opt.opt_arg ();
33 break;
34 case '?':
35 default:
36 ACE_DEBUG ((LM_DEBUG,
37 "Usage: %s "
38 "-n service_name "
39 "\n",
40 argv[0]));
41 return -1;
45 return 0;
48 int
49 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
51 if (parse_args (argc, argv) != 0)
53 return 1;
56 // create initial data for supplier and consumer operations
57 const int operation_count = 8;
58 ACE_Scheduler_Factory::POD_RT_Info config_infos[operation_count] = {
59 // good supplier (no unresolved dependencies)
60 { "good_supplier", // entry point
61 0, // handle
62 5000, // worst case execution time
63 5000, // typical execution time (unused)
64 5000, // cached execution time
65 500000, // period (100 ns)
66 RtecScheduler::HIGH_CRITICALITY, // criticality
67 RtecScheduler::LOW_IMPORTANCE, // importance
68 0, // quantum (unused)
69 1, // threads
70 0, // OS priority
71 0, // Preemption subpriority
72 0, // Preemption priority
73 RtecScheduler::OPERATION // info type
75 // good consumer (no unresolved dependencies)
76 { "good_consumer", // entry point
77 1, // handle
78 5000, // worst case execution time
79 5000, // typical execution time (unused)
80 5000, // cached execution time
81 0, // period (100 ns)
82 RtecScheduler::HIGH_CRITICALITY, // criticality
83 RtecScheduler::LOW_IMPORTANCE, // importance
84 0, // quantum (unused)
85 0, // threads
86 0, // OS priority
87 0, // Preemption subpriority
88 0, // Preemption priority
89 RtecScheduler::OPERATION // info type
91 // supplier with unresolved remote dependencies
92 { "unresolved_remote_supplier", // entry point
93 2, // handle
94 5000, // worst case execution time
95 5000, // typical execution time (unused)
96 5000, // cached execution time
97 0, // period (100 ns)
98 RtecScheduler::HIGH_CRITICALITY, // criticality
99 RtecScheduler::LOW_IMPORTANCE, // importance
100 0, // quantum (unused)
101 0, // threads
102 0, // OS priority
103 0, // Preemption subpriority
104 0, // Preemption priority
105 RtecScheduler::REMOTE_DEPENDANT // info type
107 // consumer with unresolved remote dependencies
108 { "unresolved_remote_consumer", // entry point
109 3, // handle
110 5000, // worst case execution time
111 5000, // typical execution time (unused)
112 5000, // cached execution time
113 0, // period (100 ns)
114 RtecScheduler::HIGH_CRITICALITY, // criticality
115 RtecScheduler::LOW_IMPORTANCE, // importance
116 0, // quantum (unused)
117 0, // threads
118 0, // OS priority
119 0, // Preemption subpriority
120 0, // Preemption priority
121 RtecScheduler::OPERATION // info type
123 // supplier with unresolved local dependencies
124 { "unresolved_local_supplier", // entry point
125 4, // handle
126 5000, // worst case execution time
127 5000, // typical execution time (unused)
128 5000, // cached execution time
129 0, // period (100 ns)
130 RtecScheduler::HIGH_CRITICALITY, // criticality
131 RtecScheduler::LOW_IMPORTANCE, // importance
132 0, // quantum (unused)
133 0, // threads
134 0, // OS priority
135 0, // Preemption subpriority
136 0, // Preemption priority
137 RtecScheduler::OPERATION // info type
139 // consumer with unresolved local dependencies
140 { "unresolved_local_consumer", // entry point
141 5, // handle
142 5000, // worst case execution time
143 5000, // typical execution time (unused)
144 5000, // cached execution time
145 0, // period (100 ns)
146 RtecScheduler::HIGH_CRITICALITY, // criticality
147 RtecScheduler::LOW_IMPORTANCE, // importance
148 0, // quantum (unused)
149 0, // threads
150 0, // OS priority
151 0, // Preemption subpriority
152 0, // Preemption priority
153 RtecScheduler::OPERATION // info type
155 // consumer with unresolved local and remote dependencies
156 { "both_unresolved_consumer_1", // entry point
157 6, // handle
158 5000, // worst case execution time
159 5000, // typical execution time (unused)
160 5000, // cached execution time
161 0, // period (100 ns)
162 RtecScheduler::HIGH_CRITICALITY, // criticality
163 RtecScheduler::LOW_IMPORTANCE, // importance
164 0, // quantum (unused)
165 0, // threads
166 0, // OS priority
167 0, // Preemption subpriority
168 0, // Preemption priority
169 RtecScheduler::OPERATION // info type
171 // another consumer with unresolved
172 // local and remote dependencies
173 { "both_unresolved_consumer_2", // entry point
174 7, // handle
175 5000, // worst case execution time
176 5000, // typical execution time (unused)
177 5000, // cached execution time
178 0, // period (100 ns)
179 RtecScheduler::HIGH_CRITICALITY, // criticality
180 RtecScheduler::LOW_IMPORTANCE, // importance
181 0, // quantum (unused)
182 0, // threads
183 0, // OS priority
184 0, // Preemption subpriority
185 0, // Preemption priority
186 RtecScheduler::OPERATION // info type
192 // Initialize ORB.
193 CORBA::ORB_var orb =
194 CORBA::ORB_init (argc, argv, "internet");
196 CORBA::Object_var poa_object =
197 orb->resolve_initial_references("RootPOA");
199 if (CORBA::is_nil(poa_object.in ()))
200 ACE_ERROR_RETURN ((LM_ERROR,
201 " (%P|%t) Unable to initialize the POA.\n"),
204 PortableServer::POA_var root_poa =
205 PortableServer::POA::_narrow (poa_object.in());
207 PortableServer::POAManager_var poa_manager =
208 root_poa->the_POAManager ();
210 // Initialize the naming services
211 TAO_Naming_Client my_name_client;
212 if (my_name_client.init (orb.in ()) != 0)
213 ACE_ERROR_RETURN ((LM_ERROR,
214 " (%P|%t) Unable to initialize "
215 "the TAO_Naming_Client.\n"),
216 -1);
218 CosNaming::NamingContext_var context =
219 my_name_client.get_context ();
221 if (ACE_Scheduler_Factory::use_config (context.in (),
222 service_name) < 0)
223 ACE_ERROR_RETURN ((LM_ERROR,
224 " (%P|%t) Unable to bind to the scheduling service.\n"),
227 // create and initialize RT_Infos in the scheduler,
228 // make second half of array depend on first half.
229 for (int i = 0; i < operation_count; ++i)
231 // create the RT_Info
232 config_infos[i].handle =
233 ACE_Scheduler_Factory::server ()->create (config_infos[i].entry_point);
235 // initialize the RT_Info
236 ACE_Scheduler_Factory::server ()->
237 set (config_infos[i].handle,
238 static_cast<RtecScheduler::Criticality_t> (config_infos[i].criticality),
239 config_infos[i].worst_case_execution_time,
240 config_infos[i].typical_execution_time,
241 config_infos[i].cached_execution_time,
242 config_infos[i].period,
243 static_cast<RtecScheduler::Importance_t> (config_infos[i].importance),
244 config_infos[i].quantum,
245 config_infos[i].threads,
246 static_cast<RtecScheduler::Info_Type_t> (config_infos[i].info_type));
250 // register dependency of good consumer on good supplier
251 ACE_Scheduler_Factory::server ()->
252 add_dependency (config_infos[1].handle,
253 config_infos[0].handle,
254 1, // number of calls
255 RtecBase::ONE_WAY_CALL); // type of dependency
257 // register dependency of consumer that will have unresolved remote
258 // dependencies on supplier with unresolved remote dependencies
259 ACE_Scheduler_Factory::server ()->
260 add_dependency (config_infos[3].handle,
261 config_infos[2].handle,
262 1, // number of calls
263 RtecBase::ONE_WAY_CALL); // type of dependency
265 // register dependency of consumer that will have unresolved local
266 // dependencies on supplier with unresolved local dependencies
267 ACE_Scheduler_Factory::server ()->
268 add_dependency (config_infos[5].handle,
269 config_infos[4].handle,
270 1, // number of calls
271 RtecBase::ONE_WAY_CALL); // type of dependency
273 // register dependencies on each supplier of first consumer that will
274 // have both unresolved local and unresolved remote dependencies.
275 ACE_Scheduler_Factory::server ()->
276 add_dependency (config_infos[6].handle,
277 config_infos[0].handle,
278 1, // number of calls
279 RtecBase::ONE_WAY_CALL); // type of dependency
281 ACE_Scheduler_Factory::server ()->
282 add_dependency (config_infos[6].handle,
283 config_infos[2].handle,
284 1, // number of calls
285 RtecBase::ONE_WAY_CALL); // type of dependency
287 ACE_Scheduler_Factory::server ()->
288 add_dependency (config_infos[6].handle,
289 config_infos[4].handle,
290 1, // number of calls
291 RtecBase::ONE_WAY_CALL); // type of dependency
293 // Register dependencies on each of the other consumers by second
294 // consumer that will have both unresolved local and unresolved remote
295 // dependencies.
296 ACE_Scheduler_Factory::server ()->
297 add_dependency (config_infos[7].handle,
298 config_infos[1].handle,
299 1, // number of calls
300 RtecBase::ONE_WAY_CALL); // type of dependency
302 ACE_Scheduler_Factory::server ()->
303 add_dependency (config_infos[7].handle,
304 config_infos[3].handle,
305 1, // number of calls
306 RtecBase::ONE_WAY_CALL); // type of dependency
308 ACE_Scheduler_Factory::server ()->
309 add_dependency (config_infos[7].handle,
310 config_infos[5].handle,
311 1, // number of calls
312 RtecBase::ONE_WAY_CALL); // type of dependency
314 ACE_Scheduler_Factory::server ()->
315 add_dependency (config_infos[7].handle,
316 config_infos[6].handle,
317 1, // number of calls
318 RtecBase::ONE_WAY_CALL); // type of dependency
320 RtecScheduler::RT_Info_Set_var infos;
321 RtecScheduler::Dependency_Set_var deps;
322 RtecScheduler::Config_Info_Set_var configs;
323 RtecScheduler::Scheduling_Anomaly_Set_var anomalies;
325 ACE_Scheduler_Factory::server ()->compute_scheduling
326 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO,
327 ACE_SCOPE_THREAD),
328 ACE_Sched_Params::priority_max (ACE_SCHED_FIFO,
329 ACE_SCOPE_THREAD),
330 infos.out (), deps.out (),
331 configs.out (), anomalies.out ());
333 ACE_Scheduler_Factory::dump_schedule (infos.in (),
334 deps.in (),
335 configs.in (),
336 anomalies.in (),
337 "Sched_Conf_Anomalies_Runtime.h",
338 format_string);
340 catch (const CORBA::Exception& ex)
342 ex._tao_print_exception ("SYS_EX");
345 return 0;