Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Bug_2659_Regression_Test.cpp
blobf5ae94fa881dd03903d7ac646936c83767d168a5
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
70 static void
71 handle_signal (int )
73 EE_DEBUG ("", "handle_signal", 0);
75 // Dummy signal handler
78 class ReactorTask : public ACE_Task_Base
80 public:
81 ~ReactorTask () override
83 EE_DEBUG ("ReactorTask", "~ReactorTask", this);
86 int svc ( ) override
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);
93 ACE_UNUSED_ARG (sa);
95 if (simulate_perform_work () == -1) {
96 ACE_ERROR_RETURN ((LM_ERROR,
97 ACE_TEXT ("(%P|%t) ERROR: simulated_perform_work failed.\n"))
98 , -1);
101 return 0;
104 private:
105 int simulate_perform_work ()
107 EE_DEBUG ("ReactorTask", "simulate_perform_work", this);
109 // Create a reactor which doesn't automatically restart
110 // upon interruption
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"))
134 , -1);
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"))
142 , -1);
145 while (!reactor_task_ready)
147 ACE_OS::sleep (1);
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")),
156 -1);
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")),
166 -1);
169 #endif
170 ACE_END_TEST;
172 return 0;
175 #else
177 run_main (int, ACE_TCHAR *[])
179 ACE_START_TEST (ACE_TEXT ("Bug_2659_Regression_Test"));
180 ACE_ERROR ((LM_INFO,
181 ACE_TEXT ("The Unix Signals capability is not supported on this platform\n")));
182 ACE_END_TEST;
183 return 0;
185 #endif /* !defined (ACE_LACKS_UNIX_SIGNALS) */