diff options
author | Steve Huston <shuston@riverace.com> | 2007-03-22 18:26:23 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2007-03-22 18:26:23 +0000 |
commit | 0cfc57efce5ab8e59fc9a88028dbd12fa3b72085 (patch) | |
tree | 7d0bcf5c893837333f36b2ee14be27f9a9f2abcb /ACE/tests | |
parent | 4ad6a0f5590825e705aa811a27a906d48656a0ff (diff) | |
download | ATCD-0cfc57efce5ab8e59fc9a88028dbd12fa3b72085.tar.gz |
ChangeLogTag:Thu Mar 22 18:25:01 UTC 2007 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ACE/tests')
-rw-r--r-- | ACE/tests/Auto_Event_Test.cpp | 47 | ||||
-rw-r--r-- | ACE/tests/Bug_1890_Regression_Test.cpp | 167 | ||||
-rw-r--r-- | ACE/tests/Makefile.am | 21 | ||||
-rw-r--r-- | ACE/tests/Message_Queue_Test_Ex.cpp | 101 | ||||
-rw-r--r-- | ACE/tests/Message_Queue_Test_Ex.h | 5 | ||||
-rw-r--r-- | ACE/tests/Semaphore_Test.cpp | 46 | ||||
-rw-r--r-- | ACE/tests/run_test.lst | 1 | ||||
-rw-r--r-- | ACE/tests/tests.mpc | 8 |
8 files changed, 301 insertions, 95 deletions
diff --git a/ACE/tests/Auto_Event_Test.cpp b/ACE/tests/Auto_Event_Test.cpp index b7fd8c59049..e2ed56f46a8 100644 --- a/ACE/tests/Auto_Event_Test.cpp +++ b/ACE/tests/Auto_Event_Test.cpp @@ -79,8 +79,15 @@ test_timeout (void) wait.sec (wait.sec () + wait_secs); if (evt.wait (&wait) == -1) - ACE_ASSERT (errno == ETIME); - + { + if (errno != ETIME) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("test_timeout should be ETIME but is"))); + status = -1; + } + } ACE_Time_Value wait_diff = ACE_OS::gettimeofday () - begin; msecs_waited = wait_diff.msec (); @@ -89,12 +96,13 @@ test_timeout (void) if (msecs_diff > ACE_ALLOWED_SLACK) { - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Timed wait fails length test\n"))); - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Value: %d ms, actual %d ms\n"), - msecs_expected, - msecs_waited)); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Expected %d ms, actual %d ms; %d allowed\n"), + (int)msecs_expected, + (int)msecs_waited, + (int)ACE_ALLOWED_SLACK)); status = -1; } @@ -149,19 +157,27 @@ worker (void *) if (evt.wait (&tv) == -1) { // verify that we have ETIME - ACE_ASSERT(ACE_OS::last_error() == ETIME); - ++timeouts; + if (ACE_OS::last_error() != ETIME) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("Worker should be ETIME but is"))); + } + else + ++timeouts; ACE_Time_Value diff = ACE_OS::gettimeofday (); diff = diff - tv; // tv should have been reset to time acquired long diff_msec = diff.msec (); if (diff_msec > ACE_ALLOWED_SLACK) { - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Acquire fails time reset test\n"))); - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Diff btw now and returned time: %d ms\n"), - diff.msec ())); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Diff btw now and returned time: %d ms; ") + ACE_TEXT ("%d allowed\n"), + (int)diff_msec, + (int)ACE_ALLOWED_SLACK)); test_result = 1; } // Hold the lock for a while. @@ -212,9 +228,10 @@ int run_main (int argc, ACE_TCHAR *argv[]) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Worker threads timed out %d percent of the time\n"), - percent)); + (int)percent)); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Auto_Event Test successful\n"))); + if (test_result == 0) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Auto_Event Test successful\n"))); #else ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); diff --git a/ACE/tests/Bug_1890_Regression_Test.cpp b/ACE/tests/Bug_1890_Regression_Test.cpp index 9e94a1ebb2d..a2d735f4230 100644 --- a/ACE/tests/Bug_1890_Regression_Test.cpp +++ b/ACE/tests/Bug_1890_Regression_Test.cpp @@ -95,6 +95,8 @@ run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Bug_1890_Regression_Test")); + bool success = true; + ACE_Reactor * reactor = ACE_Reactor::instance(); // Create the timer, this is the main driver for the test @@ -102,25 +104,26 @@ run_main (int, ACE_TCHAR *[]) // Initialize the timer and register with the reactor if (-1 == timer->open(reactor)) - { - ACE_ERROR_RETURN ((LM_ERROR, "Cannot initialize timer\n"), -1); - } + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("Cannot initialize timer")), + -1); + } reactor->run_reactor_event_loop(); // Verify that the results are what we expect - if (!timer->check_expected_results()) - { - ACE_ERROR_RETURN ((LM_ERROR, "Test failed\n"), -1); - } + if (!(success = timer->check_expected_results ())) + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test failed\n"))); // Cleanup - timer->close(); + timer->close (); delete timer; ACE_END_TEST; - return 0; + return success ? 0 : -1; } Handler::Handler() @@ -129,41 +132,45 @@ Handler::Handler() { } -int Handler:: -open(ACE_Reactor * r) +int +Handler::open (ACE_Reactor * r) { - if(-1 == the_pipe_.open(handles_)) + if (-1 == the_pipe_.open (handles_)) { return -1; } - if(-1 == r->register_handler(this, ACE_Event_Handler::READ_MASK)) + if (-1 == r->register_handler (this, ACE_Event_Handler::READ_MASK)) { return -1; } return 0; } -size_t Handler::handle_input_count() const +size_t +Handler::handle_input_count() const { - return handle_input_count_; + return handle_input_count_; } -void Handler::send_dummy_data() +void +Handler::send_dummy_data() { - char buf[] = "dummy"; - (void) the_pipe_.send(buf, sizeof(buf)); + char buf[] = "dummy"; + (void) the_pipe_.send (buf, sizeof (buf)); } -ACE_HANDLE Handler::get_handle() const +ACE_HANDLE +Handler::get_handle() const { - return the_pipe_.read_handle(); + return the_pipe_.read_handle (); } -int Handler::handle_input(ACE_HANDLE) +int +Handler::handle_input(ACE_HANDLE) { - ++handle_input_count_; - // ACE_DEBUG((LM_DEBUG, "Handler::handle_input called for %d\n", h)); - return 0; + ++handle_input_count_; + // ACE_DEBUG((LM_DEBUG, "Handler::handle_input called for %d\n", h)); + return 0; } int const initial_iterations = 5; @@ -177,109 +184,137 @@ Timer::Timer() { } -int Timer::open(ACE_Reactor * r) +int +Timer::open (ACE_Reactor * r) { - this->reactor(r); + this->reactor (r); // Initialize both handles and register them with the reactor for reading. - for(int i = 0; i != nhandlers; ++i) - { - if (-1 == handler_[i].open(r)) - { - ACE_ERROR_RETURN ((LM_ERROR, "Could not open dummy handler %d\n", i), -1); - } - } + for (int i = 0; i != nhandlers; ++i) + { + if (-1 == handler_[i].open (r)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Could not open dummy handler %d %p\n"), + i, + ACE_TEXT ("")), + -1); + } + } ACE_Time_Value const interval(0, ACE_ONE_SECOND_IN_USECS / 10); ACE_Time_Value const startup (0, ACE_ONE_SECOND_IN_USECS / 20); - if ( -1 == r->schedule_timer( - this, 0, startup, interval)) - { - ACE_ERROR_RETURN((LM_ERROR, "Could not schedule timer\n"), -1); - } + if (-1 == r->schedule_timer (this, 0, startup, interval)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("Could not schedule timer")), + -1); + } return 0; } -void Timer::close() +void +Timer::close() { - for(int i = 0; i != nhandlers; ++i) - { - reactor()->remove_handler(&handler_[i], ACE_Event_Handler::ALL_EVENTS_MASK); - } - reactor()->cancel_timer(this); + for (int i = 0; i != nhandlers; ++i) + { + this->reactor ()->remove_handler (&handler_[i], + ACE_Event_Handler::ALL_EVENTS_MASK | + ACE_Event_Handler::DONT_CALL); + } + this->reactor ()->cancel_timer (this); } -bool Timer::check_expected_results() const +bool +Timer::check_expected_results() const { - if(recorded_count_ < special_handler().handle_input_count()) + if (this->recorded_count_ < this->special_handler ().handle_input_count ()) { - return true; + return true; } - return false; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("recorded_count %B, special_handler count %B\n"), + this->recorded_count_, + this->special_handler ().handle_input_count ())); + return false; } -int Timer::handle_timeout(ACE_Time_Value const &, void const *) +int +Timer::handle_timeout(ACE_Time_Value const &, void const *) { - if (iteration_ == 0) + if (iteration_ == 0) { send_data_through_handlers(); } - ++iteration_; - if (iteration_ < initial_iterations) + ++iteration_; + if (iteration_ < initial_iterations) { return 0; } - if (iteration_ == initial_iterations) + if (iteration_ == initial_iterations) { remove_some_handlers(); recorded_count_ = special_handler().handle_input_count(); return 0; } - if (iteration_ < total_iterations) + if (iteration_ < total_iterations) { return 0; } - reactor()->end_reactor_event_loop(); + reactor()->end_reactor_event_loop(); - return 0; + return 0; } -void Timer::send_data_through_handlers() +void +Timer::send_data_through_handlers() { - for(int i = 0; i != nhandlers; ++i) + for (int i = 0; i != nhandlers; ++i) { handler_[i].send_dummy_data(); } } -void Timer::remove_some_handlers() +void +Timer::remove_some_handlers() { - for(int i = 0; i != nhandlers; ++i) + // The reactor may not get around to callbacks on deletion until the test + // is over. + ACE_Reactor_Mask mask = + ACE_Event_Handler::ALL_EVENTS_MASK | ACE_Event_Handler::DONT_CALL; + for (int i = 0; i != nhandlers; ++i) { - if (-1 == reactor()->remove_handler(&handler_[i], ACE_Event_Handler::ALL_EVENTS_MASK)) + if (-1 == reactor()->remove_handler(&handler_[i], mask)) { - ACE_ERROR((LM_ERROR, "Cannot remove handler %d in timeout\n", i)); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Cannot remove handler %d in %p\n"), + i, + ACE_TEXT ("timeout"))); } } - if (-1 == reactor()->register_handler(&special_handler(), ACE_Event_Handler::ALL_EVENTS_MASK)) + if (-1 == reactor()->register_handler(&special_handler(), + ACE_Event_Handler::ALL_EVENTS_MASK)) { - ACE_ERROR((LM_ERROR, "Cannot add back special handler in timeout\n")); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Cannot add back special handler in %p\n"), + ACE_TEXT ("timeout"))); } } Handler & Timer::special_handler() { - return handler_[special_handler_index]; + return handler_[special_handler_index]; } Handler const & Timer::special_handler() const { - return handler_[special_handler_index]; + return handler_[special_handler_index]; } diff --git a/ACE/tests/Makefile.am b/ACE/tests/Makefile.am index 72f1f504760..19f469328a3 100644 --- a/ACE/tests/Makefile.am +++ b/ACE/tests/Makefile.am @@ -1244,6 +1244,27 @@ Log_Msg_Test_LDADD = \ endif !BUILD_ACE_FOR_TAO + +## Makefile.Log_Msg_Backend_Test.am + +if !BUILD_ACE_FOR_TAO + +noinst_PROGRAMS += Log_Msg_Backend_Test + +Log_Msg_Backend_Test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +Log_Msg_Backend_Test_SOURCES = \ + $(ACE_ROOT)/tests/Main.cpp \ + Log_Msg_Backend_Test.cpp + +Log_Msg_Backend_Test_LDADD = \ + libTest_Output.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + ## Makefile.Logging_Strategy_Test.am noinst_PROGRAMS += Logging_Strategy_Test diff --git a/ACE/tests/Message_Queue_Test_Ex.cpp b/ACE/tests/Message_Queue_Test_Ex.cpp index fd4f714a42b..1bd1803d23f 100644 --- a/ACE/tests/Message_Queue_Test_Ex.cpp +++ b/ACE/tests/Message_Queue_Test_Ex.cpp @@ -27,6 +27,7 @@ #include "test_config.h" #include "ace/Thread_Manager.h" +#include "ace/Auto_Ptr.h" #include "ace/Message_Queue.h" #include "ace/Synch_Traits.h" #include "ace/Null_Mutex.h" @@ -623,6 +624,100 @@ int basic_queue_test (ACE_Message_Queue_Ex<User_Class, ACE_SYNCH>& q) return status; } +int queue_priority_test (ACE_Message_Queue_Ex<User_Class, ACE_SYNCH>& q) +{ + int status = 0; + if (!q.is_empty ()) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Prio test queue not empty\n")), 1); + + // Set up a few objects with names for how they should come out of the queue. + auto_ptr<User_Class> b1, b2, b3, b4; + b1.reset (new User_Class ("first")); + b2.reset (new User_Class ("second")); + b3.reset (new User_Class ("third")); + b4.reset (new User_Class ("fourth")); + unsigned long prio = + ACE_Message_Queue_Ex<User_Class, ACE_SYNCH>::DEFAULT_PRIORITY; + + prio += 1; + if (-1 == q.enqueue_prio (b2.get (), 0, prio)) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("b2")), 1); + if (-1 == q.enqueue_prio (b3.get (), 0, prio)) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("b3")), 1); + prio -= 1; + if (-1 == q.enqueue_prio (b4.get (), 0, prio)) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("b4")), 1); + prio += 5; + if (-1 == q.enqueue_prio (b1.get (), 0, prio)) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("b1")), 1); + + User_Class *b = 0; + if (q.dequeue_head (b) == -1) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("dequeue 1"))); + ++status; + } + else + { + if (ACE_OS::strcmp (b->message (), "first") != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("First dequeued was %C\n"), + b->message ())); + ++status; + } + } + if (q.dequeue_head (b) == -1) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("dequeue 2"))); + ++status; + } + else + { + if (ACE_OS::strcmp (b->message (), "second") != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Second dequeued was %C\n"), + b->message ())); + ++status; + } + } + if (q.dequeue_head (b) == -1) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("dequeue 3"))); + ++status; + } + else + { + if (ACE_OS::strcmp (b->message (), "third") != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Third dequeued was %C\n"), + b->message ())); + ++status; + } + } + if (q.dequeue_head (b) == -1) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("dequeue 4"))); + ++status; + } + else + { + if (ACE_OS::strcmp (b->message (), "fourth") != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Fourth dequeued was %C\n"), + b->message ())); + ++status; + } + } + + if (status == 0) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Priority queueing test: OK\n"))); + return status; +} + int run_main (int argc, ACE_TCHAR *argv[]) { @@ -647,6 +742,12 @@ run_main (int argc, ACE_TCHAR *argv[]) ++status; } + // Check priority operations. + if (0 != queue_priority_test (q1)) + { + ++status; + } + ACE_NEW_RETURN (timer, ACE_High_Res_Timer, -1); diff --git a/ACE/tests/Message_Queue_Test_Ex.h b/ACE/tests/Message_Queue_Test_Ex.h index 408d62277d2..38d076ac729 100644 --- a/ACE/tests/Message_Queue_Test_Ex.h +++ b/ACE/tests/Message_Queue_Test_Ex.h @@ -35,6 +35,11 @@ public: ~User_Class (void) { delete [] this->message_; } + const char *message (void) const + { + return this->message_; + } + // This is for checking the ACE_Message_Queue_Ex_N User_Class *next () const { diff --git a/ACE/tests/Semaphore_Test.cpp b/ACE/tests/Semaphore_Test.cpp index fb5ccc36dce..d2815b5cf57 100644 --- a/ACE/tests/Semaphore_Test.cpp +++ b/ACE/tests/Semaphore_Test.cpp @@ -83,7 +83,15 @@ test_timeout (void) wait.sec (wait.sec () + wait_secs); if (s.acquire (wait) == -1) - ACE_ASSERT (errno == ETIME); + { + if (errno != ETIME) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("test_timeout should be ETIME but is"))); + status = -1; + } + } ACE_Time_Value wait_diff = ACE_OS::gettimeofday () - begin; @@ -93,12 +101,13 @@ test_timeout (void) if (msecs_diff > ACE_ALLOWED_SLACK) { - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Timed wait fails length test\n"))); - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Value: %d ms, actual %d ms\n"), - msecs_expected, - msecs_waited)); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Expected %d ms, actual %d ms; %d allowed\n"), + (int)msecs_expected, + (int)msecs_waited, + (int)ACE_ALLOWED_SLACK)); status = -1; } @@ -158,19 +167,27 @@ worker (void *) if (s.acquire (tv) == -1) { // verify that we have ETIME - ACE_ASSERT(ACE_OS::last_error() == ETIME); - ++timeouts; + if (ACE_OS::last_error() != ETIME) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("Worker should be ETIME but is"))); + } + else + ++timeouts; ACE_Time_Value diff = ACE_OS::gettimeofday (); diff = diff - tv; // tv should have been reset to time acquired long diff_msec = diff.msec (); if (diff_msec > ACE_ALLOWED_SLACK) { - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Acquire fails time reset test\n"))); - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Diff btw now and returned time: %d ms\n"), - diff.msec ())); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Diff btw now and returned time: %d ms; ") + ACE_TEXT ("%d allowed\n"), + (int)diff_msec, + (int)ACE_ALLOWED_SLACK)); test_result = 1; } // Hold the lock for a while. @@ -230,10 +247,11 @@ int run_main (int argc, ACE_TCHAR *argv[]) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Worker threads timed out %d percent of the time\n"), - percent)); + (int)percent)); # endif /* ACE_HAS_STHREADS && ACE_HAS_POSIX_SEM */ - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Semaphore Test successful\n"))); + if (test_result == 0) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Semaphore Test successful\n"))); #else ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); diff --git a/ACE/tests/run_test.lst b/ACE/tests/run_test.lst index a9e36f266f0..1c6e29d8b7a 100644 --- a/ACE/tests/run_test.lst +++ b/ACE/tests/run_test.lst @@ -73,6 +73,7 @@ IOStream_Test Integer_Truncate_Test Lazy_Map_Manager_Test Log_Msg_Test: !ACE_FOR_TAO +Log_Msg_Backend_Test: !ACE_FOR_TAO Logging_Strategy_Test: !DISABLE_ToFix_LynxOS_PPC !STATIC !ST Manual_Event_Test: !DISABLE_ToFix_LynxOS_PPC MEM_Stream_Test: !DISABLE_ToFix_LynxOS_PPC !DISABLE_ToFix_LynxOS_x86 !VxWorks !nsk !ACE_FOR_TAO diff --git a/ACE/tests/tests.mpc b/ACE/tests/tests.mpc index e9b4437b94a..61bd364467b 100644 --- a/ACE/tests/tests.mpc +++ b/ACE/tests/tests.mpc @@ -488,6 +488,14 @@ project(Log Msg Test) : acetest { } } +project(Log Msg Backend Test) : acetest { + avoids += ace_for_tao + exename = Log_Msg_Backend_Test + Source_Files { + Log_Msg_Backend_Test.cpp + } +} + project(Logging Strategy Test) : acetest { exename = Logging_Strategy_Test Source_Files { |