1 #include "Roundtrip_Handler.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Sched_Params.h"
7 #include "ace/Throughput_Stats.h"
8 #include "ace/OS_NS_errno.h"
9 #include "ace/OS_NS_string.h"
11 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
13 ACE_hrtime_t throughput_base
;
15 int niterations
= 1000;
18 const ACE_TCHAR
*data_type
= ACE_TEXT("octet");
21 parse_args (int argc
, ACE_TCHAR
*argv
[])
23 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:s:k:i:"));
26 while ((c
= get_opts ()) != -1)
30 data_type
= get_opts
.opt_arg ();
32 if (ACE_OS::strcmp (data_type
, ACE_TEXT("octet")) != 0 &&
33 ACE_OS::strcmp (data_type
, ACE_TEXT("char")) != 0 &&
34 ACE_OS::strcmp (data_type
, ACE_TEXT("long")) != 0 &&
35 ACE_OS::strcmp (data_type
, ACE_TEXT("short")) != 0 &&
36 ACE_OS::strcmp (data_type
, ACE_TEXT("double")) != 0 &&
37 ACE_OS::strcmp (data_type
, ACE_TEXT("longlong")) != 0)
42 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
46 ior
= get_opts
.opt_arg ();
50 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
55 ACE_ERROR_RETURN ((LM_ERROR
,
61 "-p <period (msecs)> "
67 // Indicates successful parsing of the command line
72 void test_octet_seq (Test::Roundtrip_ptr roundtrip
,
74 Test::AMI_RoundtripHandler_ptr roundtrip_handler
,
75 Roundtrip_Handler
*roundtrip_handler_impl
)
77 Test::octet_load
ol (sz
);
80 Test::AMI_RoundtripHandler_var rth
=
81 Test::AMI_RoundtripHandler::_duplicate (roundtrip_handler
);
83 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
85 for (int i
= 0; i
!= niterations
; ++i
)
87 // Invoke asynchronous operation....
88 roundtrip
->sendc_test_octet_method (rth
.in (),
90 ACE_OS::gethrtime ());
91 if (orb
->work_pending ())
95 ACE_Time_Value
tv (0, 2000);
97 while (roundtrip_handler_impl
->pending_callbacks ())
99 orb
->perform_work (tv
);
102 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
104 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
105 ACE_High_Res_Timer::global_scale_factor_type gsf
=
106 ACE_High_Res_Timer::global_scale_factor ();
107 ACE_DEBUG ((LM_DEBUG
, "done\n"));
109 roundtrip_handler_impl
->dump_results (gsf
);
111 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
112 test_end
- test_start
,
117 void test_char_seq (Test::Roundtrip_ptr roundtrip
,
119 Test::AMI_RoundtripHandler_ptr roundtrip_handler
,
120 Roundtrip_Handler
*roundtrip_handler_impl
)
122 Test::char_load
cl (sz
);
125 Test::AMI_RoundtripHandler_var rth
=
126 Test::AMI_RoundtripHandler::_duplicate (roundtrip_handler
);
128 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
130 for (int i
= 0; i
!= niterations
; ++i
)
132 // Invoke asynchronous operation....
133 roundtrip
->sendc_test_char_method (rth
.in (),
135 ACE_OS::gethrtime ());
136 if (orb
->work_pending ())
137 orb
->perform_work ();
140 ACE_Time_Value
tv (0, 2000);
142 while (roundtrip_handler_impl
->pending_callbacks ())
144 orb
->perform_work (tv
);
147 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
149 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
150 ACE_High_Res_Timer::global_scale_factor_type gsf
=
151 ACE_High_Res_Timer::global_scale_factor ();
152 ACE_DEBUG ((LM_DEBUG
, "done\n"));
154 roundtrip_handler_impl
->dump_results (gsf
);
156 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
157 test_end
- test_start
,
162 void test_long_seq (Test::Roundtrip_ptr roundtrip
,
164 Test::AMI_RoundtripHandler_ptr roundtrip_handler
,
165 Roundtrip_Handler
*roundtrip_handler_impl
)
167 Test::long_load
ll (sz
);
170 Test::AMI_RoundtripHandler_var rth
=
171 Test::AMI_RoundtripHandler::_duplicate (roundtrip_handler
);
173 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
175 for (int i
= 0; i
!= niterations
; ++i
)
177 // Invoke asynchronous operation....
178 roundtrip
->sendc_test_long_method (rth
.in (),
180 ACE_OS::gethrtime ());
181 if (orb
->work_pending ())
182 orb
->perform_work ();
185 ACE_Time_Value
tv (0, 2000);
187 while (roundtrip_handler_impl
->pending_callbacks ())
189 orb
->perform_work (tv
);
192 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
194 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
195 ACE_High_Res_Timer::global_scale_factor_type gsf
=
196 ACE_High_Res_Timer::global_scale_factor ();
197 ACE_DEBUG ((LM_DEBUG
, "done\n"));
199 roundtrip_handler_impl
->dump_results (gsf
);
201 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
202 test_end
- test_start
,
207 void test_short_seq (Test::Roundtrip_ptr roundtrip
,
209 Test::AMI_RoundtripHandler_ptr roundtrip_handler
,
210 Roundtrip_Handler
*roundtrip_handler_impl
)
212 Test::short_load
sl (sz
);
215 Test::AMI_RoundtripHandler_var rth
=
216 Test::AMI_RoundtripHandler::_duplicate (roundtrip_handler
);
218 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
220 for (int i
= 0; i
!= niterations
; ++i
)
222 // Invoke asynchronous operation....
223 roundtrip
->sendc_test_short_method (rth
.in (),
225 ACE_OS::gethrtime ());
226 if (orb
->work_pending ())
227 orb
->perform_work ();
230 ACE_Time_Value
tv (0, 2000);
232 while (roundtrip_handler_impl
->pending_callbacks ())
234 orb
->perform_work (tv
);
237 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
239 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
240 ACE_High_Res_Timer::global_scale_factor_type gsf
=
241 ACE_High_Res_Timer::global_scale_factor ();
242 ACE_DEBUG ((LM_DEBUG
, "done\n"));
244 roundtrip_handler_impl
->dump_results (gsf
);
246 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
247 test_end
- test_start
,
252 void test_double_seq (Test::Roundtrip_ptr roundtrip
,
254 Test::AMI_RoundtripHandler_ptr roundtrip_handler
,
255 Roundtrip_Handler
*roundtrip_handler_impl
)
257 Test::double_load
dl (sz
);
260 Test::AMI_RoundtripHandler_var rth
=
261 Test::AMI_RoundtripHandler::_duplicate (roundtrip_handler
);
263 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
265 for (int i
= 0; i
!= niterations
; ++i
)
267 // Invoke asynchronous operation....
268 roundtrip
->sendc_test_double_method (rth
.in (),
270 ACE_OS::gethrtime ());
271 if (orb
->work_pending ())
272 orb
->perform_work ();
275 ACE_Time_Value
tv (0, 2000);
277 while (roundtrip_handler_impl
->pending_callbacks ())
279 orb
->perform_work (tv
);
282 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
284 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
285 ACE_High_Res_Timer::global_scale_factor_type gsf
=
286 ACE_High_Res_Timer::global_scale_factor ();
287 ACE_DEBUG ((LM_DEBUG
, "done\n"));
289 roundtrip_handler_impl
->dump_results (gsf
);
291 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
292 test_end
- test_start
,
297 void test_longlong_seq (Test::Roundtrip_ptr roundtrip
,
299 Test::AMI_RoundtripHandler_ptr roundtrip_handler
,
300 Roundtrip_Handler
*roundtrip_handler_impl
)
302 Test::longlong_load
ll (sz
);
305 Test::AMI_RoundtripHandler_var rth
=
306 Test::AMI_RoundtripHandler::_duplicate (roundtrip_handler
);
308 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
310 for (int i
= 0; i
!= niterations
; ++i
)
312 // Invoke asynchronous operation....
313 roundtrip
->sendc_test_longlong_method (rth
.in (),
315 ACE_OS::gethrtime ());
316 if (orb
->work_pending ())
317 orb
->perform_work ();
320 ACE_Time_Value
tv (0, 2000);
322 while (roundtrip_handler_impl
->pending_callbacks ())
324 orb
->perform_work (tv
);
327 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
329 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
330 ACE_High_Res_Timer::global_scale_factor_type gsf
=
331 ACE_High_Res_Timer::global_scale_factor ();
332 ACE_DEBUG ((LM_DEBUG
, "done\n"));
334 roundtrip_handler_impl
->dump_results (gsf
);
336 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
337 test_end
- test_start
,
342 // Main function starts below
345 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
348 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
349 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
350 // Enable FIFO scheduling
352 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
354 ACE_SCOPE_PROCESS
)) != 0)
356 if (ACE_OS::last_error () == EPERM
)
358 ACE_DEBUG ((LM_DEBUG
,
359 "client (%P|%t): user is not superuser, "
360 "test runs in time-shared class\n"));
363 ACE_ERROR ((LM_ERROR
,
364 "client (%P|%t): sched_params failed\n"));
370 CORBA::ORB_init (argc
, argv
);
372 CORBA::Object_var poa_object
=
373 orb
->resolve_initial_references("RootPOA");
375 if (CORBA::is_nil (poa_object
.in ()))
376 ACE_ERROR_RETURN ((LM_ERROR
,
377 " (%P|%t) Unable to initialize the POA.\n"),
380 PortableServer::POA_var root_poa
=
381 PortableServer::POA::_narrow (poa_object
.in ());
383 PortableServer::POAManager_var poa_manager
=
384 root_poa
->the_POAManager ();
386 if (parse_args (argc
, argv
) != 0)
389 CORBA::Object_var object
=
390 orb
->string_to_object (ior
);
392 Test::Roundtrip_var roundtrip
=
393 Test::Roundtrip::_narrow (object
.in ());
395 if (CORBA::is_nil (roundtrip
.in ()))
396 ACE_ERROR_RETURN ((LM_ERROR
,
397 "Nil Test::Roundtrip reference <%s>\n",
403 for (int j
= 0; j
< 100; ++j
)
405 ACE_hrtime_t start
= 0;
406 (void) roundtrip
->test_octet_method (oc
,
410 Roundtrip_Handler
*roundtrip_handler_impl
;
411 ACE_NEW_RETURN (roundtrip_handler_impl
,
412 Roundtrip_Handler (niterations
),
414 PortableServer::ServantBase_var
owner_transfer(roundtrip_handler_impl
);
416 Test::AMI_RoundtripHandler_var roundtrip_handler
=
417 roundtrip_handler_impl
->_this ();
419 poa_manager
->activate ();
421 if (ACE_OS::strcmp (data_type
, ACE_TEXT("octet")) == 0 )
423 test_octet_seq (roundtrip
.in (),
425 roundtrip_handler
.in (),
426 roundtrip_handler_impl
);
428 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("char")) == 0)
430 test_char_seq (roundtrip
.in (),
432 roundtrip_handler
.in (),
433 roundtrip_handler_impl
);
435 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("long")) == 0)
437 test_long_seq (roundtrip
.in (),
439 roundtrip_handler
.in (),
440 roundtrip_handler_impl
);
442 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("short")) == 0)
444 test_short_seq (roundtrip
.in (),
446 roundtrip_handler
.in (),
447 roundtrip_handler_impl
);
449 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("double")) == 0)
451 test_double_seq (roundtrip
.in (),
453 roundtrip_handler
.in (),
454 roundtrip_handler_impl
);
456 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("longlong")) == 0)
458 test_longlong_seq (roundtrip
.in (),
460 roundtrip_handler
.in (),
461 roundtrip_handler_impl
);
464 roundtrip
->shutdown ();
466 root_poa
->destroy (true, true);
470 catch (const CORBA::Exception
& ex
)
472 ex
._tao_print_exception ("Exception caught: ");