clang specific define in Runtime.cc
[deliverable/titan.core.git] / core / Runtime.hh
CommitLineData
d44e3c4f 1/******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Baji, Laszlo
10 * Balasko, Jeno
11 * Baranyi, Botond
12 * Delic, Adam
13 * Forstner, Matyas
14 * Kovacs, Ferenc
15 * Raduly, Csaba
16 * Szabados, Kristof
efbe586d 17 * Szabo, Bence Janos
d44e3c4f 18 * Szabo, Janos Zoltan – initial implementation
19 * Zalanyi, Balazs Andor
20 *
21 ******************************************************************************/
970ed795
EL
22#ifndef RUNTIME_HH
23#define RUNTIME_HH
24
25#include <sys/types.h>
26#include "Types.h"
27
28class Text_Buf;
29class COMPONENT;
30class VERDICTTYPE;
31class CHARSTRING;
32
33extern "C" {
34typedef void (*signal_handler_type)(int);
35}
36
37/** @brief
38*/
39class TTCN_Runtime {
40public:
41 enum executor_state_enum {
42 UNDEFINED_STATE, // 0
43
44 SINGLE_CONTROLPART, SINGLE_TESTCASE, // 1,2
45
46 HC_INITIAL, HC_IDLE, HC_CONFIGURING, HC_ACTIVE, HC_OVERLOADED, // 3-7
47 HC_OVERLOADED_TIMEOUT, HC_EXIT, // 8-9
48
49 MTC_INITIAL, MTC_IDLE, MTC_CONTROLPART, MTC_TESTCASE, // 10-13
50 MTC_TERMINATING_TESTCASE, MTC_TERMINATING_EXECUTION, MTC_PAUSED, // 14-16
51 MTC_CREATE, MTC_START, MTC_STOP, MTC_KILL, MTC_RUNNING, MTC_ALIVE, // 17-22
52 MTC_DONE, MTC_KILLED, MTC_CONNECT, MTC_DISCONNECT, MTC_MAP, MTC_UNMAP, // 23-28
53 MTC_EXIT, // 29
54
55 PTC_INITIAL, PTC_IDLE, PTC_FUNCTION, PTC_CREATE, PTC_START, PTC_STOP, // 30-35
56 PTC_KILL, PTC_RUNNING, PTC_ALIVE, PTC_DONE, PTC_KILLED, PTC_CONNECT, // 36-41
57 PTC_DISCONNECT, PTC_MAP, PTC_UNMAP, PTC_STOPPED, PTC_EXIT // 42-46
58 };
59private:
60 static executor_state_enum executor_state;
61
62 static qualified_name component_type;
63 static char *component_name;
64 static boolean is_alive;
65
66 static const char *control_module_name;
67 static qualified_name testcase_name;
68
69 static char *host_name;
70
71 static verdicttype local_verdict;
72 static unsigned int verdict_count[5], control_error_count;
73 static CHARSTRING verdict_reason;
74
75 /** TTCN_TryBlock uses the private member in_ttcn_try_block */
76 friend class TTCN_TryBlock;
77 /** true if execution is currently inside a TTCN-3 try{} */
78 static boolean in_ttcn_try_block;
79
80 static char *begin_controlpart_command, *end_controlpart_command,
81 *begin_testcase_command, *end_testcase_command;
82
83 static component create_done_killed_compref;
84 static boolean running_alive_result;
85
86 static alt_status any_component_done_status, all_component_done_status,
87 any_component_killed_status, all_component_killed_status;
88 static int component_status_table_size;
89 static component component_status_table_offset;
90 struct component_status_table_struct;
91 static component_status_table_struct *component_status_table;
92
93 struct component_process_struct;
94 static component_process_struct **components_by_compref,
95 **components_by_pid;
96
97public:
98 inline static executor_state_enum get_state() { return executor_state; }
99 inline static void set_state(executor_state_enum new_state)
100 { executor_state = new_state; }
101
102 /** @name Identifying the type
103 * @{
104 */
105 inline static boolean is_hc()
106 { return executor_state >= HC_INITIAL && executor_state <= HC_EXIT; }
107 inline static boolean is_mtc()
108 { return executor_state >= MTC_INITIAL && executor_state <= MTC_EXIT; }
109 inline static boolean is_ptc()
110 { return executor_state >= PTC_INITIAL && executor_state <= PTC_EXIT; }
111 inline static boolean is_tc()
112 { return executor_state >= MTC_INITIAL && executor_state <= PTC_EXIT; }
113 inline static boolean is_single()
114 { return executor_state >= SINGLE_CONTROLPART &&
115 executor_state <= SINGLE_TESTCASE; }
3abe9331 116 inline static boolean is_undefined() /* e.g.: when listing test cases (<EXE> -l) */
117 { return executor_state == UNDEFINED_STATE; }
970ed795
EL
118 static boolean is_idle();
119 inline static boolean is_overloaded()
120 { return executor_state == HC_OVERLOADED ||
121 executor_state == HC_OVERLOADED_TIMEOUT; }
122 /** @} */
123
124 static boolean is_in_ttcn_try_block() { return in_ttcn_try_block; }
125
126private:
127 inline static boolean in_controlpart()
128 { return executor_state == SINGLE_CONTROLPART ||
129 executor_state == MTC_CONTROLPART; }
130 /** Whether verdict operations are allowed */
131 static boolean verdict_enabled();
132 static void wait_for_state_change();
133 static void clear_qualified_name(qualified_name& q_name);
134 static void clean_up();
135
136 static void initialize_component_type();
137 static void terminate_component_type();
138
139public:
140 static void set_component_type(const char *component_type_module,
141 const char *component_type_name);
142 static void set_component_name(const char *new_component_name);
143 inline static void set_alive_flag(boolean par_is_alive)
144 { is_alive = par_is_alive; }
145 static void set_testcase_name(const char *par_module_name,
146 const char *par_testcase_name);
147
148 inline static const char *get_component_type()
149 { return component_type.definition_name; }
150 inline static const char *get_component_name()
151 { return component_name; }
152 inline static const char *get_testcase_name()
153 { return testcase_name.definition_name; }
154
155 /// Returns a string which must not be freed.
156 static const char *get_host_name();
efbe586d 157
158 static CHARSTRING get_host_address(const CHARSTRING& type);
970ed795
EL
159
160 static CHARSTRING get_testcase_id_macro();
161 static CHARSTRING get_testcasename();
162
163 static void load_logger_plugins();
164 static void set_logger_parameters();
165
166 static const char *get_signal_name(int signal_number);
167private:
168 static void set_signal_handler(int signal_number, const char *signal_name,
169 signal_handler_type signal_handler);
170 static void restore_default_handler(int signal_number,
171 const char *signal_name);
172 static void ignore_signal(int signal_number, const char *signal_name);
173 static void enable_interrupt_handler();
174 static void disable_interrupt_handler();
175public:
176 static void install_signal_handlers();
177 static void restore_signal_handlers();
178
179public:
180 static int hc_main(const char *local_addr, const char *MC_addr,
181 unsigned short MC_port);
182 static int mtc_main();
183 static int ptc_main();
184
185 static component create_component(const char *created_component_type_module,
186 const char *created_component_type_name,
187 const char *created_component_name,
188 const char *created_component_location,
189 boolean created_component_alive);
190 static void prepare_start_component(const COMPONENT& component_reference,
191 const char *module_name, const char *function_name,
192 Text_Buf& text_buf);
193 static void send_start_component(Text_Buf& text_buf);
194 static void start_function(const char *module_name,
195 const char *function_name, Text_Buf& text_buf);
196 static void function_started(Text_Buf& text_buf);
197 static void prepare_function_finished(const char *return_type,
198 Text_Buf& text_buf);
199 static void send_function_finished(Text_Buf& text_buf);
200 static void function_finished(const char *function_name);
201
202 static alt_status component_done(component component_reference);
203 static alt_status component_done(component component_reference,
204 const char *return_type, Text_Buf*& text_buf);
205 static alt_status component_killed(component component_reference);
206 static boolean component_running(component component_reference);
207 static boolean component_alive(component component_reference);
208 static void stop_component(component component_reference);
209 static void stop_execution()
210 __attribute__ ((__noreturn__));
211 static void kill_component(component component_reference);
212 static void kill_execution()
213 __attribute__ ((__noreturn__));
214
215private:
216 static alt_status ptc_done(component component_reference);
217 static alt_status any_component_done();
218 static alt_status all_component_done();
219 static alt_status ptc_killed(component component_reference);
220 static alt_status any_component_killed();
221 static alt_status all_component_killed();
222 static boolean ptc_running(component component_reference);
223 static boolean any_component_running();
224 static boolean all_component_running();
225 static boolean ptc_alive(component component_reference);
226 static boolean any_component_alive();
227 static boolean all_component_alive();
228 static void stop_mtc()
229 __attribute__ ((__noreturn__));
230 static void stop_ptc(component component_reference);
231 static void stop_all_component();
232 static void kill_ptc(component component_reference);
233 static void kill_all_component();
234
235 static void check_port_name(const char *port_name,
236 const char *operation_name, const char *which_argument);
237public:
238 static void connect_port(
239 const COMPONENT& src_compref, const char *src_port,
240 const COMPONENT& dst_compref, const char *dst_port);
241 static void disconnect_port(
242 const COMPONENT& src_compref, const char *src_port,
243 const COMPONENT& dst_compref, const char *dst_port);
244 static void map_port(
245 const COMPONENT& src_compref, const char *src_port,
246 const COMPONENT& dst_compref, const char *dst_port);
247 static void unmap_port(
248 const COMPONENT& src_compref, const char *src_port,
249 const COMPONENT& dst_compref, const char *dst_port);
250
251 static void begin_controlpart(const char *module_name);
252 static void end_controlpart();
253 static void check_begin_testcase(boolean has_timer, double timer_value);
254 static void begin_testcase(
255 const char *par_module_name, const char *par_testcase_name,
256 const char *mtc_comptype_module, const char *mtc_comptype_name,
257 const char *system_comptype_module, const char *system_comptype_name,
258 boolean has_timer, double timer_value);
259 static verdicttype end_testcase();
260 static void log_verdict_statistics();
261
262 static void begin_action();
263 static void end_action();
264
265 static void setverdict(verdicttype new_value, const char* reason = "");
266 static void setverdict(const VERDICTTYPE& new_value,
267 const char* reason = "");
268 static void set_error_verdict();
269 static verdicttype getverdict();
270private:
271 static void setverdict_internal(verdicttype new_value,
272 const char* reason = "");
273
274public:
275 /** @name Manipulating external commands
276 * @{
277 */
278 static void set_begin_controlpart_command(const char *new_command);
279 static void set_end_controlpart_command(const char *new_command);
280 static void set_begin_testcase_command(const char *new_command);
281 static void set_end_testcase_command(const char *new_command);
282 static void clear_external_commands();
283 /** @} */
284private:
285 static char *shell_escape(const char *command_str);
286 static void execute_command(const char *command_name,
287 const char *argument_string);
288
289public:
290 static void process_create_mtc();
291 static void process_create_ptc(component component_reference,
292 const char *component_type_module, const char *component_type_name,
293 const char *par_component_name, boolean par_is_alive,
294 const char *current_testcase_module, const char *current_testcase_name);
295
296 static void process_create_ack(component new_component);
297 static void process_running(boolean result_value);
298 static void process_alive(boolean result_value);
299 static void process_done_ack(boolean done_status,
300 const char *return_type, int return_value_len,
301 const void *return_value);
302 static void process_killed_ack(boolean killed_status);
303 static void process_ptc_verdict(Text_Buf& text_buf);
304 static void process_kill();
305 static void process_kill_process(component component_reference);
306
307 static void set_component_done(component component_reference,
308 const char *return_type, int return_value_len,
309 const void *return_value);
310 static void set_component_killed(component component_reference);
311 static void cancel_component_done(component component_reference);
312
313private:
314 static int get_component_status_table_index(component component_reference);
315 static alt_status get_killed_status(component component_reference);
316 static boolean in_component_status_table(component component_reference);
317 static void clear_component_status_table();
318
319 static void initialize_component_process_tables();
320 static void add_component(component component_reference, pid_t process_id);
321 static void remove_component(component_process_struct *comp);
322 static component_process_struct *get_component_by_compref(component
323 component_reference);
324 static component_process_struct *get_component_by_pid(pid_t process_id);
325 static void clear_component_process_tables();
326
327 static void successful_process_creation();
328 static void failed_process_creation();
329
330public:
331 static void wait_terminated_processes();
332 static void check_overload();
333};
334
335/** TTCN_TryBlock must be used only as a local variable of a TTCN-3 try{} block.
336 It handles the value of TTCN_Runtime::in_ttcn_try_block using C++'s RAII feature */
337class TTCN_TryBlock {
338 boolean outmost_try;
339public:
340 TTCN_TryBlock() {
341 if (TTCN_Runtime::in_ttcn_try_block) {
342 outmost_try = FALSE;
343 } else {
344 outmost_try = TRUE;
345 TTCN_Runtime::in_ttcn_try_block = TRUE;
346 }
347 }
348 ~TTCN_TryBlock() {
349 if (outmost_try) {
350 TTCN_Runtime::in_ttcn_try_block = FALSE;
351 }
352 }
353};
354
355#endif
This page took 0.036882 seconds and 5 git commands to generate.