summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-09-06 05:57:00 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-09-06 05:57:00 +0000
commitfa6da6ce2a6b2dfa0c82e04bebe98a1ee83d667d (patch)
tree73a37acf28f2d139413d0444b24f5d5d9b2e0a99 /tests
parenta65bc4fd24d3bea82c517e765695de420eaa560f (diff)
downloadATCD-fa6da6ce2a6b2dfa0c82e04bebe98a1ee83d667d.tar.gz
*** empty log message ***
Diffstat (limited to 'tests')
-rw-r--r--tests/Reactors_Test.cpp49
-rw-r--r--tests/Thread_Manager_Test.cpp5
2 files changed, 37 insertions, 17 deletions
diff --git a/tests/Reactors_Test.cpp b/tests/Reactors_Test.cpp
index 358acb370bb..50d2dba5068 100644
--- a/tests/Reactors_Test.cpp
+++ b/tests/Reactors_Test.cpp
@@ -10,10 +10,10 @@
//
// = DESCRIPTION
// This is a test that performs a torture test of multiple
-// ACE_Reactors and ACE_Tasks in the same process.
+// <ACE_Reactors> and <ACE_Tasks> in the same process.
//
// = AUTHOR
-// Prashant Jain and Detlef Becker
+// Prashant Jain, Detlef Becker, and Douglas C. Schmidt
//
// ============================================================================
@@ -27,38 +27,46 @@
static const int MAX_TASKS = 20;
class Test_Task : public ACE_Task<ACE_MT_SYNCH>
+ // = TITLE
+ // Exercise the tasks.
{
public:
+ // = Initialization and termination methods.
Test_Task (void);
~Test_Task (void);
+ // = Task hooks.
virtual int open (void *args = 0);
virtual int close (u_long flags = 0);
virtual int svc (void);
+ // = Event Handler hooks.
virtual int handle_input (ACE_HANDLE handle);
virtual int handle_close (ACE_HANDLE fd,
ACE_Reactor_Mask close_mask);
private:
- ACE_Reactor *r_;
int handled_;
+ // Number of iterations handled.
static int task_count_;
+ // Number of tasks running.
};
+// Static data member initialization.
int Test_Task::task_count_ = 0;
static ACE_Atomic_Op<ACE_Thread_Mutex, int> done_count = MAX_TASKS * 2;
-static ACE_Recursive_Thread_Mutex reclock_;
+static ACE_Recursive_Thread_Mutex recursive_lock;
Test_Task::Test_Task (void)
: handled_ (0)
{
- ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, reclock_);
+ ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, recursive_lock);
Test_Task::task_count_++;
+
ACE_DEBUG ((LM_DEBUG,
"(%t) TT+ Test_Task::task_count_ = %d\n",
Test_Task::task_count_));
@@ -66,30 +74,34 @@ Test_Task::Test_Task (void)
Test_Task::~Test_Task (void)
{
- ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, reclock_);
+ ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, recursive_lock);
ACE_DEBUG ((LM_DEBUG,
"(%t) TT- Test_Task::task_count_ = %d\n",
Test_Task::task_count_));
+
ACE_ASSERT (Test_Task::task_count_ == 0);
}
int
Test_Task::open (void *args)
{
- r_ = (ACE_Reactor *) args;
+ this->reactor ((ACE_Reactor *) args);
return this->activate (THR_NEW_LWP);
}
int
Test_Task::close (u_long)
{
- ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, reclock_, -1);
+ ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, recursive_lock, -1);
Test_Task::task_count_--;
ACE_DEBUG ((LM_DEBUG,
"(%t) close Test_Task::task_count_ = %d\n",
Test_Task::task_count_));
+
+ if (Test_Task::task_count_ < 0)
+ abort ();
return 0;
}
@@ -107,7 +119,9 @@ Test_Task::svc (void)
// Only wait up to 10 milliseconds to notify the Reactor.
ACE_Time_Value timeout (0, 10 * 1000);
- if (r_->notify (this, ACE_Event_Handler::READ_MASK, &timeout) == -1)
+ if (this->reactor ()->notify (this,
+ ACE_Event_Handler::READ_MASK,
+ &timeout) == -1)
{
if (errno == ETIME)
ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", "notify() timed out"));
@@ -152,11 +166,11 @@ worker (void *args)
// Make this thread the owner of the Reactor's event loop.
reactor->owner (ACE_Thread::self ());
+ // Use a timeout to inform the Reactor when to shutdown.
ACE_Time_Value timeout (4);
for (;;)
{
- // Use a timeout to inform the Reactor when to shutdown.
switch (reactor->handle_events (timeout))
{
case -1:
@@ -168,7 +182,7 @@ worker (void *args)
}
}
- ACE_NOTREACHED(return 0);
+ ACE_NOTREACHED (return 0);
}
#endif /* ACE_HAS_THREADS */
@@ -191,20 +205,25 @@ main (int, char *[])
Test_Task tt1[MAX_TASKS];
Test_Task tt2[MAX_TASKS];
+ // Activate all of the Tasks.
+
for (int i = 0; i < MAX_TASKS; i++)
{
- tt1[i].open (ACE_Reactor::instance());
+ tt1[i].open (ACE_Reactor::instance ());
tt2[i].open (reactor);
}
+ // Spawn two threads each running a different reactor.
+
if (ACE_Thread_Manager::instance ()->spawn
- (ACE_THR_FUNC (worker), (void *) ACE_Reactor::instance(),
- THR_NEW_LWP | THR_DETACHED) == -1)
+ (ACE_THR_FUNC (worker),
+ (void *) ACE_Reactor::instance (),
+ THR_BOUND | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), -1);
else if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (worker), (void *) reactor,
- THR_NEW_LWP | THR_DETACHED) == -1)
+ THR_BOUND | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), -1);
ACE_Thread_Manager::instance ()->wait ();
diff --git a/tests/Thread_Manager_Test.cpp b/tests/Thread_Manager_Test.cpp
index 7b9940d70e5..1cc25dbc6a3 100644
--- a/tests/Thread_Manager_Test.cpp
+++ b/tests/Thread_Manager_Test.cpp
@@ -152,12 +152,13 @@ main (int, char *[])
// Perform a barrier wait until all the threads have shut down.
thr_mgr->wait ();
+
+ delete signal_catcher;
+
#else
ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n"));
#endif /* ACE_HAS_THREADS */
- delete signal_catcher;
-
ACE_END_TEST;
return 0;
}