summaryrefslogtreecommitdiff
path: root/ACE/examples/Reactor/Misc/test_early_timeouts.cpp
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:30 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:30 +0000
commitc44379cc7d9c7aa113989237ab0f56db12aa5219 (patch)
tree66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/examples/Reactor/Misc/test_early_timeouts.cpp
parent3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff)
downloadATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz
Repo restructuring
Diffstat (limited to 'ACE/examples/Reactor/Misc/test_early_timeouts.cpp')
-rw-r--r--ACE/examples/Reactor/Misc/test_early_timeouts.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/ACE/examples/Reactor/Misc/test_early_timeouts.cpp b/ACE/examples/Reactor/Misc/test_early_timeouts.cpp
new file mode 100644
index 00000000000..4c7193d9a67
--- /dev/null
+++ b/ACE/examples/Reactor/Misc/test_early_timeouts.cpp
@@ -0,0 +1,114 @@
+// $Id$
+
+// ================================================================
+//
+// = LIBRARY
+// examples/Reactor/Misc/
+//
+// = FILENAME
+// test_early_timeouts.cpp
+//
+// = DESCRIPTION
+// On some platforms, select() returns before the time value
+// specified. This tests counts the number of times this happens
+// and the max early timeout.
+//
+// = AUTHOR
+// Irfan Pyarali <irfan@cs.wustl.edu>
+//
+// ================================================================
+
+#include "ace/Handle_Set.h"
+#include "ace/Pipe.h"
+#include "ace/Log_Msg.h"
+#include "ace/Time_Value.h"
+#include "ace/OS_NS_sys_time.h"
+#include "ace/OS_NS_sys_select.h"
+
+ACE_RCSID(Misc, test_early_timeouts, "$Id$")
+
+int
+ACE_TMAIN (int, ACE_TCHAR *[])
+{
+ // Mumber of seconds this test should run
+ int runtime_in_seconds = 10;
+
+ // Iterations
+ int iterations = runtime_in_seconds * 10;
+
+ // 100 millisecond timeout
+ ACE_Time_Value timeout (0, 100000);
+
+ // Time before starting select
+ ACE_Time_Value starting_time_of_day;
+
+ // Time before starting select
+ ACE_Time_Value ending_time_of_day;
+
+ // Number of times the timer expired early
+ int no_of_early_timers = 0;
+
+ // Maximum early timeout
+ ACE_Time_Value maximum_early_timeout;
+
+ //
+ // Dummy handle and handle set
+ // Note that some OS do not like "empty selects"
+ //
+
+ // Dummy handle set
+ ACE_Handle_Set dummy_handle_set;
+
+ // Dummy pipe
+ ACE_Pipe dummy_pipe;
+ int result = dummy_pipe.open ();
+ ACE_ASSERT (result == 0);
+ ACE_UNUSED_ARG (result); // To avoid compile warning with ACE_NDEBUG.
+
+ for (int i = 1; i <= iterations; i++)
+ {
+ // Add dummy handle to dummy set
+ dummy_handle_set.set_bit (dummy_pipe.read_handle ());
+
+ // Note the time before select
+ starting_time_of_day = ACE_OS::gettimeofday ();
+
+ // Wait for timeout
+ result = ACE_OS::select ((int) dummy_pipe.read_handle (), dummy_handle_set, 0, 0, &timeout);
+ ACE_ASSERT (result == 0);
+
+ // Note the time after select
+ ending_time_of_day = ACE_OS::gettimeofday ();
+
+ // Expected ending time
+ ACE_Time_Value expected_ending_time_of_day =
+ starting_time_of_day + timeout;
+
+ // If the timer expired early
+ if (ending_time_of_day < expected_ending_time_of_day)
+ {
+ // How early
+ ACE_Time_Value early_timeout = expected_ending_time_of_day - ending_time_of_day;
+
+ // Increment number of early timers
+ no_of_early_timers++;
+
+ // Check max early timeout
+ if (early_timeout > maximum_early_timeout)
+ {
+ maximum_early_timeout = early_timeout;
+ }
+ }
+ }
+
+ ACE_DEBUG ((LM_DEBUG,
+ "There were %d early timers out of %d calls to select() (%f%%)\n"
+ "The max early timeout was: %dsec %dusec\n",
+ no_of_early_timers,
+ iterations,
+ float (no_of_early_timers) / iterations * 100,
+ maximum_early_timeout.sec (),
+ maximum_early_timeout.usec ()));
+
+ return 0;
+}