2 //=============================================================================
4 * @file Bug_2659_Regression_Test.cpp
6 * Reproduces the problems reported in bug 2659:
7 * http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=2659
9 * @author Ciju John <johnc at ociweb>
11 //=============================================================================
14 #include "test_config.h"
16 #include "ace/Log_Msg.h"
18 #include "ace/OS_NS_unistd.h"
19 #include "ace/Thread_Manager.h"
20 #include "ace/TP_Reactor.h"
22 #if !defined (ACE_LACKS_UNIX_SIGNALS)
24 bool reactor_task_ready
= false;
31 #define EE_DEBUG(CNAME,MNAME,LOC) \
32 EntryExit ee (CNAME,MNAME,LOC)
37 EntryExit (const ACE_TCHAR
* class_name
,
38 const ACE_TCHAR
*method_name
,
41 class_name_
[20] = method_name_
[20] = 0;
43 ACE_OS::strncpy (class_name_
, class_name
, 20);
44 ACE_OS::strncpy (method_name_
, method_name
, 20);
47 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Entry %@ %s::%s\n")
48 , location
, class_name
, method_name
));
53 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Exit %@ %s::%s\n")
54 , location_
, class_name_
, method_name_
));
58 ACE_TCHAR class_name_
[21];
59 ACE_TCHAR method_name_
[21];
65 #define EE_DEBUG(CNAME,MNAME,LOC)
67 #endif // if defined RUN_DEBUG
74 EE_DEBUG ("", "handle_signal", 0);
76 // Dummy signal handler
79 class ReactorTask
: public ACE_Task_Base
83 virtual ~ReactorTask ()
85 EE_DEBUG ("ReactorTask", "~ReactorTask", this);
88 virtual int svc (void )
90 EE_DEBUG ("ReactorTask", "svc", this);
92 // Register a valid signal handler
93 // so process doesn't die upon receiving signal
94 ACE_Sig_Action
sa ((ACE_SignalHandler
) &::handle_signal
, SIGUSR1
);
97 if (simulate_perform_work () == -1) {
98 ACE_ERROR_RETURN ((LM_ERROR
,
99 ACE_TEXT ("(%P|%t) ERROR: simulated_perform_work failed.\n"))
107 int simulate_perform_work ()
109 EE_DEBUG ("ReactorTask", "simulate_perform_work", this);
111 // Create a reactor which doesn't automatically restart
113 ACE_TP_Reactor
tp_reactor (ACE_TP_Reactor::DEFAULT_SIZE
, 0);
115 reactor_task_ready
= true;
117 // This will return upon signal interruption
118 return tp_reactor
.handle_events ();
123 run_main (int, ACE_TCHAR
*[])
125 ACE_START_TEST (ACE_TEXT ("Bug_2659_Regression_Test"));
126 EE_DEBUG ("", "run_main", 0);
128 ReactorTask reactor_task
;
130 #if !defined ACE_HAS_PTHREADS || !defined ACE_LACKS_PTHREAD_KILL
132 if (reactor_task
.activate () == -1)
134 ACE_ERROR_RETURN ((LM_ERROR
,
135 ACE_TEXT ("(%P|%t) Task activation failed.\n"))
139 ACE_Thread_Manager
*thread_manager
= reactor_task
.thr_mgr ();
140 if (thread_manager
== 0)
142 ACE_ERROR_RETURN ((LM_ERROR
,
143 ACE_TEXT ("(%P|%t) No Thread Manager found.\n"))
147 while (!reactor_task_ready
)
152 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Signalling task.\n")));
154 if (thread_manager
->kill_all (SIGUSR1
) == -1)
156 ACE_ERROR_RETURN ((LM_ERROR
,
157 ACE_TEXT ("(%P|%t) Task signalling failed.\n")),
161 // Wait 5 seconds for the other thread to exit, if it didn't exit the
162 // wait return -1 and we return with an error
163 ACE_Time_Value
timeout (5);
164 if (thread_manager
->wait (&timeout
, false, false) == -1)
166 ACE_ERROR_RETURN ((LM_ERROR
,
167 ACE_TEXT ("(%P|%t) Error, task wait failed.\n")),
179 run_main (int, ACE_TCHAR
*[])
181 ACE_START_TEST (ACE_TEXT ("Bug_2659_Regression_Test"));
183 ACE_TEXT ("The Unix Signals capability is not supported on this platform\n")));
187 #endif /* !defined (ACE_LACKS_UNIX_SIGNALS) */