diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-01-13 04:40:43 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-01-13 04:40:43 +0000 |
commit | a35ae2f983e79aa3e58c30c46850fbed8db04146 (patch) | |
tree | 09f268a4fc7b6fde778abdc2654d049ec6286fc2 /tests | |
parent | ac28159e4d1b086ead532421d73eaba695a9ea7b (diff) | |
download | ATCD-a35ae2f983e79aa3e58c30c46850fbed8db04146.tar.gz |
foo
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Thread_Pool_Test.cpp | 2 | ||||
-rw-r--r-- | tests/Timer_Queue_Test.cpp | 130 |
2 files changed, 110 insertions, 22 deletions
diff --git a/tests/Thread_Pool_Test.cpp b/tests/Thread_Pool_Test.cpp index 2a0a662914c..761479f9264 100644 --- a/tests/Thread_Pool_Test.cpp +++ b/tests/Thread_Pool_Test.cpp @@ -73,7 +73,7 @@ Thread_Pool::close (u_long) Thread_Pool::Thread_Pool (int n_threads) { - // Create worker threads. + // Create a pool of worker threads. if (this->activate (THR_NEW_LWP, n_threads) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); } diff --git a/tests/Timer_Queue_Test.cpp b/tests/Timer_Queue_Test.cpp index f0ec1c90815..2ff194ba59f 100644 --- a/tests/Timer_Queue_Test.cpp +++ b/tests/Timer_Queue_Test.cpp @@ -1,6 +1,6 @@ -// ============================================================================ // $Id$ +// ============================================================================ // // = LIBRARY // tests @@ -9,20 +9,23 @@ // Timer_Queue_Test.cpp // // = DESCRIPTION -// This is a simple test of ACE_Timer_Queue. 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. +// This is a simple test of <ACE_Timer_Queue> and two of its +// subclasses (<ACE_Timer_List> and <ACE_Timer_Heap>). 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. // // = AUTHOR // Prashant Jain // // ============================================================================ - -#include "ace/Timer_Queue.h" +#include "ace/Timer_List.h" +#include "ace/Timer_Heap.h" #include "test_config.h" +const int MAX_ITERATIONS = ACE_DEFAULT_MAX_TIMERS - 1; + class Example_Handler : public ACE_Event_Handler { public: @@ -34,12 +37,9 @@ public: } }; -int -main (int, char *[]) +static void +test_functionality (ACE_Timer_Queue *tq) { - ACE_START_TEST ("Timer_Queue_Test"); - - ACE_Timer_Queue tq; Example_Handler eh; ACE_ASSERT (tq.is_empty ()); @@ -47,20 +47,108 @@ main (int, char *[]) int timer_id; timer_id = tq.schedule (&eh, (const void *) 1, ACE_OS::gettimeofday ()); - tq.schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ()); - tq.schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ()); - tq.cancel (timer_id); + ACE_ASSERT (timer_id != -1); + + ACE_ASSERT (tq.schedule (&eh, (const void *) 42, + ACE_OS::gettimeofday ()) != -1); + ACE_ASSERT (tq.schedule (&eh, (const void *) 42, + ACE_OS::gettimeofday ()) != -1); + ACE_ASSERT (tq.cancel (timer_id) == 1); ACE_ASSERT (!tq.is_empty ()); - tq.expire (ACE_OS::gettimeofday ()); + ACE_ASSERT (tq.expire (ACE_OS::gettimeofday () == 1)); - tq.schedule (&eh, (const void *) 4, ACE_OS::gettimeofday ()); - tq.schedule (&eh, (const void *) 5, ACE_OS::gettimeofday ()); - tq.cancel (&eh); + ACE_ASSERT (tq.schedule (&eh, (const void *) 4, ACE_OS::gettimeofday + ()) != -1); + ACE_ASSERT (tq.schedule (&eh, (const void *) 5, ACE_OS::gettimeofday + ()) != -1); + ACE_ASSERT (tq.cancel (&eh) == 2); ACE_ASSERT (tq.is_empty ()); - tq.expire (ACE_OS::gettimeofday ()); + ACE_ASSERT (tq.expire (ACE_OS::gettimeofday ()) == 0); +} + +static void +test_performance (ACE_Timer_Queue *tq, + const char *test_name) +{ + Example_Handler eh; + ACE_Profile_Timer timer; + int i; + + ACE_ASSERT (tq->is_empty ()); + ACE_ASSERT (ACE_Time_Value::zero == ACE_Time_Value (0)); + + timer.start (); + + // Test the amount of time required to schedule all the timers. + for (i = 0; i < MAX_ITERATIONS; i++) + tq->schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ()); + + ACE_Profile_Timer::ACE_Elapsed_Time et; + + timer.elapsed_time (et); + + ACE_DEBUG ((LM_DEBUG, "time to schedule %d timers for %s\n", + MAX_ITERATIONS, test_name)); + ACE_DEBUG ((LM_DEBUG, "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, "time per call = %f usecs\n", + (et.real_time / double (MAX_ITERATIONS)) * 1000000)); + + timer.start (); + + int timer_id = tq->schedule (&eh, (const void *) 42, + ACE_OS::gettimeofday ()); + + ACE_ASSERT (timer_id); + + // Test the amount of time required to cancel all the timers (this + // takes advantage of the fact that <timer_ids> are always allocated + // contiguously starting at 0. + for (i = 0; i < MAX_ITERATIONS + 1; i++) + tq->cancel (timer_id--); + + ACE_ASSERT (tq->is_empty ()); + + timer.elapsed_time (et); + + ACE_DEBUG ((LM_DEBUG, "time to cancel %d timers for %s\n", + MAX_ITERATIONS, test_name)); + ACE_DEBUG ((LM_DEBUG, "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, "time per call = %f usecs\n", + (et.real_time / double (MAX_ITERATIONS)) * 1000000)); + +} + +struct Timer_Queues +{ + ACE_Timer_Queue *queue_; + // Pointer to the subclass of <ACE_Timer_Queue> that we're testing. + + const char *name_; + // Name of the Queue that we're testing. +}; + +static Timer_Queues timer_queues[] = +{ + { new ACE_Timer_List, "ACE_Timer_List" }, + { new ACE_Timer_Heap, "ACE_Timer_Queue" }, + { 0, 0 }; +} + +int +main (int, char *[]) +{ + ACE_START_TEST ("Timer_Queue_Test"); + + for (int i = 0; timer_queues[i].name_ != 0; i++) + { + test_performance (timer_queues[i].queue_, timer_queues[i].name_); + test_functionality (timer_queues[i].queue_, timer_queues[i].name_); + delete timer_queues[i].queue_; + } ACE_END_TEST; return 0; } - |