Merge pull request #2323 from jwillemsen/jwi-defaultcopydis
[ACE_TAO.git] / TAO / orbsvcs / tests / Sched / DynSched_Test.cpp
blob965ebf7746bbbe17420009c063700325d5550c55
1 #include "orbsvcs/Sched/Strategy_Scheduler.h"
2 #include "orbsvcs/Time_Utilities.h"
3 #if defined (ACE_HAS_QUANTIFY)
4 # include <quantify.h>
5 #endif /* ACE_HAS_QUANTIFY */
7 // period times, in 100 nanoseconds
8 #define ONE_HZ 10000000
9 #define FIVE_HZ 2000000
10 #define TEN_HZ 1000000
11 #define TWENTY_HZ 500000
13 class DynSched_Test
14 // = TITLE
15 // DynSched Test wrapper
16 // = DESCRIPTION
17 // Wraps static functions for test
19 public:
20 static void setup_rt_info (RtecScheduler::RT_Info &info,
21 const char *entry_point,
22 u_long period,
23 RtecScheduler::Time execution,
24 RtecScheduler::Criticality_t criticality,
25 RtecScheduler::Importance_t importance,
26 u_long threads);
27 // Initializes an RT_Info.
29 static int register_rt_info (ACE_DynScheduler &scheduler,
30 RtecScheduler::RT_Info &info);
31 // Registers an RT_Info.
34 #if 0 /* not currently used */
35 static void setup_conjunction (RtecScheduler::RT_Info &info,
36 const char *entry_point);
37 // Sets up a conjunction.
39 static void setup_disjunction (RtecScheduler::RT_Info &info,
40 const char *entry_point);
41 // Sets up a disjunction.
43 #endif /* not currently used */
45 static int run_schedule (ACE_Scheduler_Strategy &strategy,
46 const char *output_filename,
47 const char *heading);
48 // Creates the schedule, runs timelines.
52 // Initializes an RT_Info.
54 void
55 DynSched_Test::setup_rt_info (RtecScheduler::RT_Info &info,
56 const char *entry_point,
57 u_long period,
58 RtecScheduler::Time execution,
59 RtecScheduler::Criticality_t criticality,
60 RtecScheduler::Importance_t importance,
61 u_long threads)
63 // copy the passed entry point string into the RT_Info
64 info.entry_point = CORBA::string_dup (entry_point);
66 // initialize other values
67 info.handle = 0;
68 info.worst_case_execution_time = execution;
69 info.typical_execution_time = execution;
70 info.cached_execution_time = ORBSVCS_Time::zero ();
71 info.period = period;
72 info.criticality = criticality;
73 info.importance = importance;
74 info.quantum = ORBSVCS_Time::zero ();
75 info.threads = threads;
76 info.priority = 0;
77 info.preemption_subpriority = 0;
78 info.preemption_priority = 0;
79 info.info_type = RtecScheduler::OPERATION;
80 info.volatile_token = 0;
84 // Registers an RT_Info.
86 int
87 DynSched_Test::register_rt_info (ACE_DynScheduler &scheduler,
88 RtecScheduler::RT_Info &info)
90 int result = 0;
92 if (scheduler.register_task (&info, info.handle) !=
93 ACE_DynScheduler::SUCCEEDED)
95 result = 1;
96 ACE_OS::printf ("Could not register info for \"%s\"\n", info.entry_point.in ());
99 return result;
102 #if 0 /* not currently used */
104 // Sets up a conjunction.
106 void
107 DynSched_Test::setup_conjunction (RtecScheduler::RT_Info &info,
108 const char *entry_point)
110 // copy the passed entry point string into the RT_Info
111 info.entry_point = CORBA::string_dup (entry_point);
113 // initialize other values
114 info.handle = 0;
115 info.worst_case_execution_time = ORBSVCS_Time::zero ();
116 info.typical_execution_time = ORBSVCS_Time::zero ();
117 info.cached_execution_time = ORBSVCS_Time::zero ();
118 info.period = 0;
119 info.criticality = RtecScheduler::VERY_LOW_CRITICALITY;
120 info.importance = RtecScheduler::VERY_LOW_IMPORTANCE;
121 info.quantum = ORBSVCS_Time::zero ();
122 info.threads = 0;
123 info.priority = 0;
124 info.preemption_subpriority = 0;
125 info.preemption_priority = 0;
126 info.info_type = RtecScheduler::CONJUNCTION;
127 info.volatile_token = 0;
131 // Sets up a disjunction.
133 void
134 DynSched_Test::setup_disjunction (RtecScheduler::RT_Info &info,
135 const char *entry_point)
137 // copy the passed entry point string into the RT_Info
138 info.entry_point = CORBA::string_dup (entry_point);
140 // initialize other values
141 info.handle = 0;
142 info.worst_case_execution_time = ORBSVCS_Time::zero ();
143 info.typical_execution_time = ORBSVCS_Time::zero ();
144 info.cached_execution_time = ORBSVCS_Time::zero ();
145 info.period = 0;
146 info.criticality = RtecScheduler::VERY_LOW_CRITICALITY;
147 info.importance = RtecScheduler::VERY_LOW_IMPORTANCE;
148 info.quantum = ORBSVCS_Time::zero ();
149 info.threads = 0;
150 info.priority = 0;
151 info.preemption_subpriority = 0;
152 info.preemption_priority = 0;
153 info.info_type = RtecScheduler::DISJUNCTION;
154 info.volatile_token = 0;
156 #endif /* not currently used */
159 // Creates the schedule, runs timelines.
162 DynSched_Test::run_schedule (ACE_Scheduler_Strategy &strategy,
163 const char *output_filename,
164 const char *heading)
166 RtecScheduler::RT_Info low_1, low_5, low_10, low_20;
167 RtecScheduler::RT_Info high_1, high_5, high_10, high_20;
169 ACE_Strategy_Scheduler scheduler (strategy);
171 DynSched_Test::setup_rt_info (low_1, "low_1", ONE_HZ, 180000,
172 RtecScheduler::LOW_CRITICALITY,
173 RtecScheduler::HIGH_IMPORTANCE, 1);
174 DynSched_Test::setup_rt_info (low_5, "low_5", FIVE_HZ, 180000,
175 RtecScheduler::LOW_CRITICALITY,
176 RtecScheduler::HIGH_IMPORTANCE, 1);
177 DynSched_Test::setup_rt_info (low_10, "low_10", TEN_HZ, 180000,
178 RtecScheduler::LOW_CRITICALITY,
179 RtecScheduler::HIGH_IMPORTANCE, 1);
180 DynSched_Test::setup_rt_info (low_20, "low_20", TWENTY_HZ, 180000,
181 RtecScheduler::LOW_CRITICALITY,
182 RtecScheduler::HIGH_IMPORTANCE, 1);
183 DynSched_Test::setup_rt_info (high_1, "high_1", ONE_HZ, 180000,
184 RtecScheduler::HIGH_CRITICALITY,
185 RtecScheduler::LOW_IMPORTANCE, 1);
186 DynSched_Test::setup_rt_info (high_5, "high_5", FIVE_HZ, 180000,
187 RtecScheduler::HIGH_CRITICALITY,
188 RtecScheduler::LOW_IMPORTANCE, 1);
189 DynSched_Test::setup_rt_info (high_10, "high_10", TEN_HZ, 180000,
190 RtecScheduler::HIGH_CRITICALITY,
191 RtecScheduler::LOW_IMPORTANCE, 1);
192 DynSched_Test::setup_rt_info (high_20, "high_20", TWENTY_HZ, 180000,
193 RtecScheduler::HIGH_CRITICALITY,
194 RtecScheduler::LOW_IMPORTANCE, 1);
196 if (
197 DynSched_Test::register_rt_info (scheduler, low_1) ||
198 DynSched_Test::register_rt_info (scheduler, low_5) ||
199 DynSched_Test::register_rt_info (scheduler, low_10) ||
200 DynSched_Test::register_rt_info (scheduler, low_20) ||
201 DynSched_Test::register_rt_info (scheduler, high_1) ||
202 DynSched_Test::register_rt_info (scheduler, high_5) ||
203 DynSched_Test::register_rt_info (scheduler, high_10) ||
204 DynSched_Test::register_rt_info (scheduler, high_20))
206 return -1;
209 #if defined (ACE_HAS_QUANTIFY)
210 quantify_start_recording_data ();
211 #endif /* ACE_HAS_QUANTIFY */
213 ACE_Unbounded_Set<RtecScheduler::Scheduling_Anomaly *> anomaly_set;
214 ACE_DynScheduler::status_t status = scheduler.schedule (anomaly_set);
216 #if defined (ACE_HAS_QUANTIFY)
217 quantify_stop_recording_data ();
218 #endif /* ACE_HAS_QUANTIFY */
220 switch (status)
222 case ACE_DynScheduler::SUCCEEDED:
223 case ACE_DynScheduler::ST_UTILIZATION_BOUND_EXCEEDED:
225 status = scheduler.output_timeline (output_filename, heading);
226 switch (status)
228 case ACE_DynScheduler::SUCCEEDED:
229 case ACE_DynScheduler::ST_UTILIZATION_BOUND_EXCEEDED:
230 break;
232 default :
233 ACE_ERROR_RETURN ((LM_ERROR,
234 "scheduler.output_timeline (\"%s\") failed: "
235 "returned %d\n",
236 output_filename, status), -1);
239 break;
241 default :
243 ACE_ERROR_RETURN ((LM_ERROR,
244 "scheduler.schedule () failed: "
245 "returned %d\n",
246 status), -1);
249 return 0;
253 ACE_TMAIN(int, ACE_TCHAR *[])
255 int result = 0;
257 // create a bunch of different strategies, indicating the minimum critical
258 // priority level (number of priority levels in critical set - 1) for each.
260 ACE_RMS_Scheduler_Strategy rms_strategy (3);
262 ACE_MLF_Scheduler_Strategy mlf_strategy (0);
263 ACE_EDF_Scheduler_Strategy edf_strategy (0);
265 ACE_MUF_Scheduler_Strategy muf_strategy (0);
267 result =
268 DynSched_Test::run_schedule (rms_strategy, "RMS_Timelines",
269 "RMS Scheduling Strategy");
270 if (result < 0)
272 ACE_OS::printf ("run_schedule (rms_strategy, \"RMS_Timelines\", "
273 "\"RMS Scheduling Strategy\") returned %d\n",
274 result);
275 return 1;
278 result =
279 DynSched_Test::run_schedule (mlf_strategy, "MLF_Timelines",
280 "MLF Scheduling Strategy");
281 if (result < 0)
283 ACE_OS::printf ("run_schedule (mlf_strategy, \"MLF_Timelines\", "
284 "\"MLF Scheduling Strategy\") returned %d\n",
285 result);
286 return 1;
289 result =
290 DynSched_Test::run_schedule (edf_strategy, "EDF_Timelines",
291 "EDF Scheduling Strategy");
292 if (result < 0)
294 ACE_OS::printf ("run_schedule (edf_strategy, \"EDF_Timelines\", "
295 "\"EDF Scheduling Strategy\") returned %d\n",
296 result);
297 return 1;
300 result =
301 DynSched_Test::run_schedule (muf_strategy, "MUF_Timelines",
302 "MUF Scheduling Strategy");
303 if (result < 0)
305 ACE_OS::printf ("run_schedule (muf_strategy, \"MUF_Timelines\", "
306 "\"MUF Scheduling Strategy\") returned %d\n",
307 result);
308 return 1;
311 return 0;