summaryrefslogtreecommitdiff
path: root/tests/Timer_Queue_Test.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-07-04 19:07:51 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-07-04 19:07:51 +0000
commitaddd1378f0e08b121abfd35f247c17798dbbfb65 (patch)
tree90475affd37872b65b16a86c3b3e9b0eeb98715a /tests/Timer_Queue_Test.cpp
parent523aa4a484f446b3ebd1334849f4af26a7371e3f (diff)
downloadATCD-addd1378f0e08b121abfd35f247c17798dbbfb65.tar.gz
ChangeLogTag:Sun Jul 4 12:34:24 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
Diffstat (limited to 'tests/Timer_Queue_Test.cpp')
-rw-r--r--tests/Timer_Queue_Test.cpp233
1 files changed, 128 insertions, 105 deletions
diff --git a/tests/Timer_Queue_Test.cpp b/tests/Timer_Queue_Test.cpp
index c985f5c762e..3f8578531ce 100644
--- a/tests/Timer_Queue_Test.cpp
+++ b/tests/Timer_Queue_Test.cpp
@@ -10,13 +10,16 @@
//
// = DESCRIPTION
// This is a simple test of <ACE_Timer_Queue> and four of its
-// subclasses (<ACE_Timer_List>, <ACE_Timer_Heap>, <ACE_Timer_Wheel>, and
-// <ACE_Timer_Hash>). The test sets up a bunch of timers and then adds
-// them to a timer queue. The functionality of the timer queue is then
-// tested. No command line arguments are needed to run the test.
+// subclasses (<ACE_Timer_List>, <ACE_Timer_Heap>,
+// <ACE_Timer_Wheel>, and <ACE_Timer_Hash>). The test sets up a
+// bunch of timers and then adds them to a timer queue. The
+// functionality of the timer queue is then tested. No command
+// line arguments are needed to run the test.
//
// = AUTHORS
-// Douglas C. Schmidt, Prashant Jain, and Darrell Brunsch
+// Douglas C. Schmidt <schmidt@cs.wustl.edu>,
+// Prashant Jain <pjain@cs.wustl.edu>, and
+// Darrell Brunsch <brunsch@cs.wustl.edu>
//
// ============================================================================
@@ -52,9 +55,9 @@ randomize_array (T array[], size_t size)
}
}
-// Number of iterations for the performance tests. Some platforms have a very
-// high ACE_DEFAULT_TIMERS (HP-UX is 400), so limit this to a reasonable run
-// time.
+// Number of iterations for the performance tests. Some platforms
+// have a very high ACE_DEFAULT_TIMERS (HP-UX is 400), so limit this
+// to a reasonable run time.
#if (ACE_DEFAULT_TIMERS > 20)
static int max_iterations = 2000;
#else
@@ -80,7 +83,8 @@ public:
const void *arg)
{
ACE_ASSERT (arg == (const void *) 42 || arg == (const void *)007);
- if (arg != (const void *)42)
+
+ if (arg != (const void *) 42)
return -1;
else
return 0;
@@ -99,16 +103,17 @@ test_functionality (ACE_Timer_Queue *tq)
ACE_ASSERT (ACE_Time_Value::zero == ACE_Time_Value (0));
long timer_id, timer_id2;
- // Do a test on earliest_time
-
+ // Do a test on earliest_time.
ACE_Time_Value earliest_time = tq->gettimeofday ();
- timer_id = tq->schedule (&eh, (const void *) 1,
+ timer_id = tq->schedule (&eh,
+ (const void *) 1,
earliest_time);
ACE_OS::sleep (ACE_Time_Value (0, 10));
- timer_id2 = tq->schedule (&eh, (const void *) 1,
+ timer_id2 = tq->schedule (&eh,
+ (const void *) 1,
tq->gettimeofday ());
ACE_ASSERT (tq->earliest_time () == earliest_time);
@@ -116,42 +121,51 @@ test_functionality (ACE_Timer_Queue *tq)
tq->cancel (timer_id);
tq->cancel (timer_id2);
- timer_id = tq->schedule (&eh, (const void *) 1,
+ timer_id = tq->schedule (&eh,
+ (const void *) 1,
tq->gettimeofday ());
ACE_ASSERT (timer_id != -1);
ACE_ASSERT (tq->is_empty () == 0); //==
- ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
- tq->gettimeofday ()) != -1);
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 42,
+ tq->gettimeofday ()) != -1);
ACE_ASSERT (tq->is_empty () == 0); //==
- ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
- tq->gettimeofday ()) != -1);
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 42,
+ tq->gettimeofday ()) != -1);
ACE_ASSERT (tq->is_empty () == 0); //==
+
// The following method will trigger a call to <handle_close>.
ACE_ASSERT (tq->cancel (timer_id, 0, 0) == 1);
ACE_ASSERT (tq->is_empty () == 0);
ACE_ASSERT (tq->expire () == 2);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 007,
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 007,
tq->gettimeofday ()) != -1);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 42,
tq->gettimeofday () + ACE_Time_Value (100)) != -1);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
- tq->gettimeofday () + ACE_Time_Value (100)) != -1);
-
- // The following will trigger a call to <handle_close> when
- // it cancels the second timer. This happens because the first
- // timer has an <act> of 007, which causes eh.handle_timeout () to
- // return -1. Since -1 is returned, all timers that use <eh> will
- // be cancelled (and <handle_close> will only be called on the first
- // timer that is cancelled).
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 42,
+ tq->gettimeofday () + ACE_Time_Value (100)) != -1);
+
+ // The following will trigger a call to <handle_close> when it
+ // cancels the second timer. This happens because the first timer
+ // has an <act> of 007, which causes eh.handle_timeout () to return
+ // -1. Since -1 is returned, all timers that use <eh> will be
+ // cancelled (and <handle_close> will only be called on the first
+ // timer that is cancelled).
ACE_ASSERT (tq->expire () == 1);
ACE_ASSERT (tq->is_empty () != 0);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 4,
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 4,
tq->gettimeofday ()) != -1);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 5,
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 5,
tq->gettimeofday ()) != -1);
// The following method will trigger a call to <handle_close>.
@@ -161,14 +175,17 @@ test_functionality (ACE_Timer_Queue *tq)
// This tests to make sure that <handle_close> is called when there
// is only one timer of the type in the queue
- ACE_ASSERT (tq->schedule (&eh, (const void *) 007,
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 007,
tq->gettimeofday ()) != -1);
ACE_ASSERT (tq->expire () == 1);
- timer_id = tq->schedule (&eh, (const void *) 6,
+ timer_id = tq->schedule (&eh,
+ (const void *) 6,
tq->gettimeofday ());
ACE_ASSERT (timer_id != -1);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 7,
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 7,
tq->gettimeofday ()) != -1);
// The following method will *not* trigger a call to <handle_close>.
@@ -220,7 +237,7 @@ test_performance (ACE_Timer_Queue *tq,
max_iterations, test_name));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
- et.real_time, et.user_time, et.system_time));
+ et.real_time, et.user_time, et.system_time));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("time per call = %f usecs\n"),
(et.user_time / ACE_timer_t (max_iterations)) * 1000000));
@@ -243,7 +260,7 @@ test_performance (ACE_Timer_Queue *tq,
max_iterations, test_name));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
- et.real_time, et.user_time, et.system_time));
+ et.real_time, et.user_time, et.system_time));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("time per call = %f usecs\n"),
(et.user_time / ACE_timer_t (max_iterations)) * 1000000));
@@ -266,10 +283,10 @@ test_performance (ACE_Timer_Queue *tq,
timer.stop ();
if (!tq->is_empty ())
- {
- ACE_OS::sleep (ACE_Time_Value (1));
- tq->expire ();
- }
+ {
+ ACE_OS::sleep (ACE_Time_Value (1));
+ tq->expire ();
+ }
ACE_ASSERT (tq->is_empty ());
@@ -304,10 +321,10 @@ test_performance (ACE_Timer_Queue *tq,
tq->cancel (timer_ids[i]);
if (!tq->is_empty ())
- {
- ACE_OS::sleep (ACE_Time_Value (1));
- tq->expire ();
- }
+ {
+ ACE_OS::sleep (ACE_Time_Value (1));
+ tq->expire ();
+ }
ACE_ASSERT (tq->is_empty ());
@@ -316,14 +333,17 @@ test_performance (ACE_Timer_Queue *tq,
timer.elapsed_time (et);
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("time to randomly cancel %d timers for %s\n"),
- max_iterations, test_name));
+ ASYS_TEXT ("time to randomly cancel %d timers for %s\n"),
+ max_iterations,
+ test_name));
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
- et.real_time, et.user_time, et.system_time));
+ ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
+ et.real_time,
+ et.user_time,
+ et.system_time));
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("time per call = %f usecs\n"),
- (et.user_time / ACE_timer_t (max_iterations)) * 1000000));
+ ASYS_TEXT ("time per call = %f usecs\n"),
+ (et.user_time / ACE_timer_t (max_iterations)) * 1000000));
// Test the amount of time required to randomly schedule all the timers.
@@ -353,7 +373,9 @@ test_performance (ACE_Timer_Queue *tq,
max_iterations, test_name));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
- et.real_time, et.user_time, et.system_time));
+ et.real_time,
+ et.user_time,
+ et.system_time));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("time per call = %f usecs\n"),
(et.user_time / ACE_timer_t (max_iterations)) * 1000000));
@@ -365,10 +387,10 @@ test_performance (ACE_Timer_Queue *tq,
tq->expire ();
if (!tq->is_empty ())
- {
- ACE_OS::sleep (ACE_Time_Value (1));
- tq->expire ();
- }
+ {
+ ACE_OS::sleep (ACE_Time_Value (1));
+ tq->expire ();
+ }
ACE_ASSERT (tq->is_empty ());
@@ -381,7 +403,7 @@ test_performance (ACE_Timer_Queue *tq,
max_iterations, test_name));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
- et.real_time, et.user_time, et.system_time));
+ et.real_time, et.user_time, et.system_time));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("time per call = %f usecs\n"),
(et.user_time / ACE_timer_t (max_iterations)) * 1000000));
@@ -389,13 +411,23 @@ test_performance (ACE_Timer_Queue *tq,
delete [] times;
}
-struct Timer_Queue_List
+class Timer_Queue_Stack
{
- Timer_Queue_List (ACE_Timer_Queue *queue, const ASYS_TCHAR *name, Timer_Queue_List *next = NULL)
+ // = TITLE
+ // Keeps track of the <Timer_Queue>s that we're going to test.
+ //
+ // = DESCRIPTION
+ // This data structure is organized as a stack to make it easy to implement.
+public:
+ // = Initialization method
+ Timer_Queue_Stack (ACE_Timer_Queue *queue,
+ const ASYS_TCHAR *name,
+ Timer_Queue_Stack *next = NULL)
: queue_ (queue),
name_ (name),
next_ (next)
{}
+ // "Push" a new <queue> on the stack of <queue>s.
ACE_Timer_Queue *queue_;
// Pointer to the subclass of <ACE_Timer_Queue> that we're testing.
@@ -403,8 +435,8 @@ struct Timer_Queue_List
const ASYS_TCHAR *name_;
// Name of the Queue that we're testing.
- Timer_Queue_List *next_;
- // Pointer to the next <Timer_Queues> structure
+ Timer_Queue_Stack *next_;
+ // Pointer to the next <Timer_Queue>.
};
int
@@ -419,88 +451,79 @@ main (int argc, ASYS_TCHAR *argv[])
// = Perform initializations.
- Timer_Queue_List *tq_list = NULL;
+ Timer_Queue_Stack *tq_stack = NULL;
- // Add new Timer_Queue implementations here.
-
+ // Add new Timer_Queue implementations here. Note that these will
+ // be executed in "reverse order" since we treat
// Timer_Hash (Heap)
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_Hash_Heap,
- ASYS_TEXT ("ACE_Timer_Hash (Heap)"),
- tq_list),
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_Hash_Heap,
+ ASYS_TEXT ("ACE_Timer_Hash (Heap)"),
+ tq_stack),
-1);
// Timer_Hash
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_Hash,
- ASYS_TEXT ("ACE_Timer_Hash"),
- tq_list),
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_Hash,
+ ASYS_TEXT ("ACE_Timer_Hash"),
+ tq_stack),
-1);
- // Timer_List
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_List,
- ASYS_TEXT ("ACE_Timer_List"),
- tq_list),
+ // Timer_stack
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_List,
+ ASYS_TEXT ("ACE_Timer_List"),
+ tq_stack),
-1);
// Timer_Wheel without preallocated memory
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_Wheel,
- ASYS_TEXT ("ACE_Timer_Wheel (non-preallocated)"),
- tq_list),
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_Wheel,
+ ASYS_TEXT ("ACE_Timer_Wheel (non-preallocated)"),
+ tq_stack),
-1);
// Timer_Wheel with preallocated memory.
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_Wheel (ACE_DEFAULT_TIMER_WHEEL_SIZE,
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_Wheel (ACE_DEFAULT_TIMER_WHEEL_SIZE,
ACE_DEFAULT_TIMER_WHEEL_RESOLUTION,
max_iterations),
- ASYS_TEXT ("ACE_Timer_Wheel (preallocated)"),
- tq_list),
+ ASYS_TEXT ("ACE_Timer_Wheel (preallocated)"),
+ tq_stack),
-1);
-
-
// Timer_Heap without preallocated memory.
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_Heap,
- ASYS_TEXT ("ACE_Timer_Heap (non-preallocated)"),
- tq_list),
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_Heap,
+ ASYS_TEXT ("ACE_Timer_Heap (non-preallocated)"),
+ tq_stack),
-1);
// Timer_Heap with preallocate memory.
-
- ACE_NEW_RETURN (tq_list,
- Timer_Queue_List (new ACE_Timer_Heap (max_iterations, 1),
- ASYS_TEXT ("ACE_Timer_Heap (preallocated)"),
- tq_list),
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new ACE_Timer_Heap (max_iterations, 1),
+ ASYS_TEXT ("ACE_Timer_Heap (preallocated)"),
+ tq_stack),
-1);
// Create the Timer ID array
-
ACE_NEW_RETURN (timer_ids,
long[max_iterations],
-1);
- Timer_Queue_List *tq_ptr = tq_list;
+ Timer_Queue_Stack *tq_ptr = tq_stack;
while (tq_ptr != NULL)
{
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("**** starting test of %s\n"),
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("**** starting test of %s\n"),
tq_ptr->name_));
test_functionality (tq_ptr->queue_);
test_performance (tq_ptr->queue_,
tq_ptr->name_);
delete tq_ptr->queue_;
- Timer_Queue_List *temp = tq_ptr;
+ Timer_Queue_Stack *temp = tq_ptr;
tq_ptr = tq_ptr->next_;
delete temp;
}