Doxygen changes
[ACE_TAO.git] / ACE / tests / Bug_2659_Regression_Test.cpp
blobce6ac4f1301b4372133c8bbad5c4fd79a0de0c7b
2 //=============================================================================
3 /**
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"
17 #include "ace/Task.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;
27 //#define RUN_DEBUG 1
29 #if defined RUN_DEBUG
31 #define EE_DEBUG(CNAME,MNAME,LOC) \
32 EntryExit ee (CNAME,MNAME,LOC)
34 class EntryExit
36 public:
37 EntryExit (const ACE_TCHAR* class_name,
38 const ACE_TCHAR *method_name,
39 void *location = 0)
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);
45 location_ = location;
47 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Entry %@ %s::%s\n")
48 , location, class_name, method_name));
51 ~EntryExit ()
53 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Exit %@ %s::%s\n")
54 , location_, class_name_, method_name_));
57 private:
58 ACE_TCHAR class_name_[21];
59 ACE_TCHAR method_name_[21];
60 void *location_;
63 #else
65 #define EE_DEBUG(CNAME,MNAME,LOC)
67 #endif // if defined RUN_DEBUG
71 static void
72 handle_signal (int )
74 EE_DEBUG ("", "handle_signal", 0);
76 // Dummy signal handler
79 class ReactorTask : public ACE_Task_Base
81 public:
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);
95 ACE_UNUSED_ARG (sa);
97 if (simulate_perform_work () == -1) {
98 ACE_ERROR_RETURN ((LM_ERROR,
99 ACE_TEXT ("(%P|%t) ERROR: simulated_perform_work failed.\n"))
100 , -1);
103 return 0;
106 private:
107 int simulate_perform_work ()
109 EE_DEBUG ("ReactorTask", "simulate_perform_work", this);
111 // Create a reactor which doesn't automatically restart
112 // upon interruption
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"))
136 , -1);
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"))
144 , -1);
147 while (!reactor_task_ready)
149 ACE_OS::sleep (1);
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")),
158 -1);
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")),
168 -1);
171 #endif
172 ACE_END_TEST;
174 return 0;
177 #else
179 run_main (int, ACE_TCHAR *[])
181 ACE_START_TEST (ACE_TEXT ("Bug_2659_Regression_Test"));
182 ACE_ERROR ((LM_INFO,
183 ACE_TEXT ("The Unix Signals capability is not supported on this platform\n")));
184 ACE_END_TEST;
185 return 0;
187 #endif /* !defined (ACE_LACKS_UNIX_SIGNALS) */