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
73 EE_DEBUG ("", "handle_signal", 0);
75 // Dummy signal handler
78 class ReactorTask
: public ACE_Task_Base
81 ~ReactorTask () override
83 EE_DEBUG ("ReactorTask", "~ReactorTask", this);
88 EE_DEBUG ("ReactorTask", "svc", this);
90 // Register a valid signal handler
91 // so process doesn't die upon receiving signal
92 ACE_Sig_Action
sa ((ACE_SignalHandler
) &::handle_signal
, SIGUSR1
);
95 if (simulate_perform_work () == -1) {
96 ACE_ERROR_RETURN ((LM_ERROR
,
97 ACE_TEXT ("(%P|%t) ERROR: simulated_perform_work failed.\n"))
105 int simulate_perform_work ()
107 EE_DEBUG ("ReactorTask", "simulate_perform_work", this);
109 // Create a reactor which doesn't automatically restart
111 ACE_TP_Reactor
tp_reactor (ACE_TP_Reactor::DEFAULT_SIZE
, 0);
113 reactor_task_ready
= true;
115 // This will return upon signal interruption
116 return tp_reactor
.handle_events ();
121 run_main (int, ACE_TCHAR
*[])
123 ACE_START_TEST (ACE_TEXT ("Bug_2659_Regression_Test"));
124 EE_DEBUG ("", "run_main", 0);
126 ReactorTask reactor_task
;
128 #if !defined ACE_HAS_PTHREADS || !defined ACE_LACKS_PTHREAD_KILL
130 if (reactor_task
.activate () == -1)
132 ACE_ERROR_RETURN ((LM_ERROR
,
133 ACE_TEXT ("(%P|%t) Task activation failed.\n"))
137 ACE_Thread_Manager
*thread_manager
= reactor_task
.thr_mgr ();
138 if (thread_manager
== 0)
140 ACE_ERROR_RETURN ((LM_ERROR
,
141 ACE_TEXT ("(%P|%t) No Thread Manager found.\n"))
145 while (!reactor_task_ready
)
150 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Signalling task.\n")));
152 if (thread_manager
->kill_all (SIGUSR1
) == -1)
154 ACE_ERROR_RETURN ((LM_ERROR
,
155 ACE_TEXT ("(%P|%t) Task signalling failed.\n")),
159 // Wait 5 seconds for the other thread to exit, if it didn't exit the
160 // wait return -1 and we return with an error
161 ACE_Time_Value
timeout (5);
162 if (thread_manager
->wait (&timeout
, false, false) == -1)
164 ACE_ERROR_RETURN ((LM_ERROR
,
165 ACE_TEXT ("(%P|%t) Error, task wait failed.\n")),
177 run_main (int, ACE_TCHAR
*[])
179 ACE_START_TEST (ACE_TEXT ("Bug_2659_Regression_Test"));
181 ACE_TEXT ("The Unix Signals capability is not supported on this platform\n")));
185 #endif /* !defined (ACE_LACKS_UNIX_SIGNALS) */