summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1998-10-15 01:05:51 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1998-10-15 01:05:51 +0000
commit089bce98b5e351fa7ee2e1d6c98f38b365be985f (patch)
treec21e2ffe4cb71026d0f73b4737b37b21b92077ba
parent0c8a939f91872e48a9bdea1f65c46e0bdd1e9048 (diff)
downloadATCD-089bce98b5e351fa7ee2e1d6c98f38b365be985f.tar.gz
*** empty log message ***
-rw-r--r--ChangeLog-98b5
-rw-r--r--tests/MT_Reactor_Timer_Test.cpp115
-rw-r--r--tests/MT_Reactor_Timer_Test.h5
-rwxr-xr-xtests/run_tests.sh1
4 files changed, 101 insertions, 25 deletions
diff --git a/ChangeLog-98b b/ChangeLog-98b
index 0f0379e191b..55875fa66cf 100644
--- a/ChangeLog-98b
+++ b/ChangeLog-98b
@@ -1,5 +1,10 @@
Wed Oct 14 12:36:00 1998 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
+ * tests/run_tests.sh: Added the MT_Reactor_Timer_Test.
+
+ * tests/MT_Reactor_Timer_Test.cpp: Fixed a number of bugs with
+ this test. It seems to work fine on Solaris now.
+
* tests/MT_Reactor_Timer_Test.cpp (main): Added a test to make
sure that the ACE_Reactor::handle_events() method properly
counts the number of expired timers.
diff --git a/tests/MT_Reactor_Timer_Test.cpp b/tests/MT_Reactor_Timer_Test.cpp
index 0afd4de6e4e..32c2fa856e6 100644
--- a/tests/MT_Reactor_Timer_Test.cpp
+++ b/tests/MT_Reactor_Timer_Test.cpp
@@ -46,9 +46,12 @@ Time_Handler::Time_Handler (void)
void
Time_Handler::setup (void)
{
- this->timer_id_[1] = the_reactor->schedule_timer (this,
- (const void *) 1,
- ACE_Time_Value (5));
+ this->timer_id_[1] = the_reactor->schedule_timer
+ (this,
+ (const void *) 1,
+ ACE_Time_Value (5));
+
+ ACE_ASSERT (this->timer_id_[1] != -1);
}
// In the secondary thread, set a heartbeat timer to go off every
@@ -58,16 +61,36 @@ Time_Handler::setup (void)
int
Time_Handler::svc (void)
{
- ACE_Time_Value backstop (30);
+ ACE_Time_Value backstop (10);
+
+ this->timer_id_[2] = the_reactor->schedule_timer
+ (this,
+ (const void *) 2,
+ ACE_Time_Value (3));
+
+ ACE_ASSERT (this->timer_id_[2] != -1);
- this->timer_id_[2] = the_reactor->schedule_timer (this,
- (const void *) 2,
- ACE_Time_Value (3));
this->my_reactor_.owner (ACE_OS::thr_self ());
- this->my_reactor_.schedule_timer (this, (const void *) 0,
- ACE_Time_Value (1),
- ACE_Time_Value (1));
- this->my_reactor_.run_event_loop (backstop);
+
+ long result = this->my_reactor_.schedule_timer
+ (this,
+ (const void *) 0,
+ ACE_Time_Value (1),
+ ACE_Time_Value (1)) != -1;
+ ACE_ASSERT (result != -1);
+
+ for (;;)
+ {
+ result = this->my_reactor_.handle_events (backstop);
+ ACE_ASSERT (result != -1);
+ if (result == 0)
+ break;
+ }
+
+ ACE_ASSERT (result != -1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("%T (%t): leaving svc thread\n")));
return 0;
}
@@ -78,30 +101,41 @@ Time_Handler::handle_timeout (const ACE_Time_Value &tv,
long time_tag = ACE_reinterpret_cast (long, arg);
ACE_UNUSED_ARG(tv);
+ if (time_tag == -1)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("%T (%t): heartbeat from main thread\n")));
+ return 0;
+ }
if (time_tag == 0)
{ // Heartbeat.
int i;
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("%T (%t): heartbeat\n")));
+
// See if all of the timers have fired. If so, leave the
- // thread's reactor loop which will exit the thread and end the
+ // thread's reactor loop, which will exit the thread and end the
// test.
for (i = 0; i < Time_Handler::TIMER_SLOTS; i++)
if (this->timer_id_[i] != -1)
break;
+ // All timers should be gone.
if (i == Time_Handler::TIMER_SLOTS)
- { // All timers should be gone.
-
+ {
// Cancel heartbeat.
- ACE_ASSERT (this->my_reactor_.cancel_timer (this) == 1);
+ i = this->my_reactor_.cancel_timer (this);
+ ACE_ASSERT (i == 1);
+ i = the_reactor->cancel_timer (this);
// Shouldn't be any.
- ACE_ASSERT (the_reactor->cancel_timer (this) == 0);
+ ACE_ASSERT (i == 0);
+
this->my_reactor_.end_event_loop ();
}
+
return 0;
}
@@ -133,7 +167,9 @@ Dispatch_Count_Handler::Dispatch_Count_Handler (void)
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("register_handler")));
// Put something in our pipe and smoke it... ;-)
- else if (ACE_OS::write (this->pipe_.write_handle (), "z", 1) == -1)
+ else if (ACE_OS::write (this->pipe_.write_handle (),
+ "z",
+ 1) == -1)
ACE_ERROR ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("write")));
@@ -144,19 +180,42 @@ Dispatch_Count_Handler::Dispatch_Count_Handler (void)
ASYS_TEXT ("notify")));
}
+int
+Dispatch_Count_Handler::handle_close (ACE_HANDLE h,
+ ACE_Reactor_Mask m)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("%T (%t): handle_close\n")));
+
+ ACE_ASSERT (h == this->pipe_.read_handle ()
+ && m == ACE_Event_Handler::READ_MASK);
+
+ if (the_reactor->remove_handler (this->pipe_.read_handle (),
+ ACE_Event_Handler::READ_MASK
+ | ACE_Event_Handler::DONT_CALL) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ASYS_TEXT ("%p\n"),
+ ASYS_TEXT ("remove_handler")),
+ -1);
+ return 0;
+}
+
int
Dispatch_Count_Handler::handle_input (ACE_HANDLE h)
{
char c;
+
if (ACE_OS::read (h, &c, 1) != 1)
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("read")),
-1);
+
ACE_ASSERT (c == 'z');
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("%T (%t): handle_input\n")));
- return 0;
+ // Trigger the <handle_close> hook.
+ return -1;
}
int
@@ -213,13 +272,21 @@ main (int, ASYS_TCHAR *[])
other_thread.setup ();
// Schedule a timeout to expire in 5 seconds.
- the_reactor->schedule_timer (&other_thread,
- (const void *) 1,
- ACE_Time_Value (5));
+ result = the_reactor->schedule_timer (&other_thread,
+ (const void *) -1,
+ ACE_Time_Value (5));
+ ACE_ASSERT (result != -1);
+
+ result = other_thread.activate (THR_NEW_LWP | THR_JOINABLE);
+ ACE_ASSERT (result != -1);
+
+ // Note that we can only call run_event_loop() on the Singleton
+ // thread!
+ result = the_reactor->run_event_loop ();
+ ACE_ASSERT (result != -1);
- other_thread.activate (THR_NEW_LWP | THR_JOINABLE);
- the_reactor->run_event_loop ();
- other_thread.wait ();
+ result = other_thread.wait ();
+ ACE_ASSERT (result != -1);
#else
ACE_ERROR ((LM_ERROR,
ASYS_TEXT ("threads not supported on this platform\n")));
diff --git a/tests/MT_Reactor_Timer_Test.h b/tests/MT_Reactor_Timer_Test.h
index 05f51802c1d..8e62aedf074 100644
--- a/tests/MT_Reactor_Timer_Test.h
+++ b/tests/MT_Reactor_Timer_Test.h
@@ -48,7 +48,6 @@ private:
};
long timer_id_[TIMER_SLOTS];
- int step_;
ACE_Reactor my_reactor_;
};
@@ -60,6 +59,10 @@ class Dispatch_Count_Handler : public ACE_Event_Handler
public:
Dispatch_Count_Handler (void);
+ int handle_close (ACE_HANDLE h,
+ ACE_Reactor_Mask m);
+ // Clean up resources from the Reactor.
+
virtual int handle_timeout (const ACE_Time_Value &tv,
const void *arg);
// Keep track of the number of timeouts.
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 1af37bb0acc..5ed762c9274 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -97,6 +97,7 @@ test $chorus || run MM_Shared_Memory_Test # tests ACE_Shared_Memory_MM
run Sigset_Ops_Test # tests ACE_sigset*() functions
test $LynxOS || run Timer_Queue_Test # tests ACE_Event_Handler, ACE_Timer_Queue
+run MT_Reactor_Timer_Test # tests ACE_Reactor's timer mechanism.
run SOCK_Connector_Test # tests ACE_SOCK_Connector