File: Runtime.hh

package info (click to toggle)
eclipse-titan 6.1.0-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 79,084 kB
  • ctags: 29,092
  • sloc: cpp: 210,764; ansic: 44,862; yacc: 21,034; sh: 12,594; makefile: 12,225; lex: 8,972; xml: 5,348; java: 4,849; perl: 3,780; python: 2,834; php: 175
file content (355 lines) | stat: -rw-r--r-- 13,189 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/******************************************************************************
 * Copyright (c) 2000-2016 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Baji, Laszlo
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Delic, Adam
 *   Forstner, Matyas
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Szabo, Bence Janos
 *   Szabo, Janos Zoltan – initial implementation
 *   Zalanyi, Balazs Andor
 *
 ******************************************************************************/
#ifndef RUNTIME_HH
#define RUNTIME_HH

#include <sys/types.h>
#include "Types.h"

class Text_Buf;
class COMPONENT;
class VERDICTTYPE;
class CHARSTRING;

extern "C" {
typedef void (*signal_handler_type)(int);
}

/** @brief
*/
class TTCN_Runtime {
public:
  enum executor_state_enum {
    UNDEFINED_STATE, // 0

    SINGLE_CONTROLPART, SINGLE_TESTCASE, // 1,2

    HC_INITIAL, HC_IDLE, HC_CONFIGURING, HC_ACTIVE, HC_OVERLOADED, // 3-7
    HC_OVERLOADED_TIMEOUT, HC_EXIT, // 8-9

    MTC_INITIAL, MTC_IDLE, MTC_CONTROLPART, MTC_TESTCASE, // 10-13
    MTC_TERMINATING_TESTCASE, MTC_TERMINATING_EXECUTION, MTC_PAUSED, // 14-16
    MTC_CREATE, MTC_START, MTC_STOP, MTC_KILL, MTC_RUNNING, MTC_ALIVE, // 17-22
    MTC_DONE, MTC_KILLED, MTC_CONNECT, MTC_DISCONNECT, MTC_MAP, MTC_UNMAP, // 23-28
    MTC_CONFIGURING, MTC_EXIT, // 30

    PTC_INITIAL, PTC_IDLE, PTC_FUNCTION, PTC_CREATE, PTC_START, PTC_STOP, // 31-36
    PTC_KILL, PTC_RUNNING, PTC_ALIVE, PTC_DONE, PTC_KILLED, PTC_CONNECT, // 37-42
    PTC_DISCONNECT, PTC_MAP, PTC_UNMAP, PTC_STOPPED, PTC_EXIT // 43-47
  };
private:
  static executor_state_enum executor_state;

  static qualified_name component_type;
  static char *component_name;
  static boolean is_alive;

  static const char *control_module_name;
  static qualified_name testcase_name;

  static char *host_name;

  static verdicttype local_verdict;
  static unsigned int verdict_count[5], control_error_count;
  static CHARSTRING verdict_reason;

  /** TTCN_TryBlock uses the private member in_ttcn_try_block */
  friend class TTCN_TryBlock;
  /** true if execution is currently inside a TTCN-3 try{} */
  static boolean in_ttcn_try_block;

  static char *begin_controlpart_command, *end_controlpart_command,
  *begin_testcase_command, *end_testcase_command;

  static component create_done_killed_compref;
  static boolean running_alive_result;

  static alt_status any_component_done_status, all_component_done_status,
  any_component_killed_status, all_component_killed_status;
  static int component_status_table_size;
  static component component_status_table_offset;
  struct component_status_table_struct;
  static component_status_table_struct *component_status_table;

  struct component_process_struct;
  static component_process_struct **components_by_compref,
  **components_by_pid;

public:
  inline static executor_state_enum get_state() { return executor_state; }
  inline static void set_state(executor_state_enum new_state)
  { executor_state = new_state; }

  /** @name Identifying the type
  *   @{
  */
  inline static boolean is_hc()
  { return executor_state >= HC_INITIAL && executor_state <= HC_EXIT; }
  inline static boolean is_mtc()
  { return executor_state >= MTC_INITIAL && executor_state <= MTC_EXIT; }
  inline static boolean is_ptc()
  { return executor_state >= PTC_INITIAL && executor_state <= PTC_EXIT; }
  inline static boolean is_tc()
  { return executor_state >= MTC_INITIAL && executor_state <= PTC_EXIT; }
  inline static boolean is_single()
  { return executor_state >= SINGLE_CONTROLPART &&
    executor_state <= SINGLE_TESTCASE; }
  inline static boolean is_undefined() /* e.g.: when listing test cases (<EXE> -l) */
  { return executor_state == UNDEFINED_STATE; }
  static boolean is_idle();
  inline static boolean is_overloaded()
  { return executor_state == HC_OVERLOADED ||
    executor_state == HC_OVERLOADED_TIMEOUT; }
  /** @} */

  static boolean is_in_ttcn_try_block() { return in_ttcn_try_block; }

private:
  inline static boolean in_controlpart()
  { return executor_state == SINGLE_CONTROLPART ||
    executor_state == MTC_CONTROLPART; }
  /** Whether verdict operations are allowed */
  static boolean verdict_enabled();
  static void wait_for_state_change();
  static void clear_qualified_name(qualified_name& q_name);
  static void clean_up();

  static void initialize_component_type();
  static void terminate_component_type();

public:
  static void set_component_type(const char *component_type_module,
    const char *component_type_name);
  static void set_component_name(const char *new_component_name);
  inline static void set_alive_flag(boolean par_is_alive)
  { is_alive = par_is_alive; }
  static void set_testcase_name(const char *par_module_name,
    const char *par_testcase_name);

  inline static const char *get_component_type()
  { return component_type.definition_name; }
  inline static const char *get_component_name()
  { return component_name; }
  inline static const char *get_testcase_name()
  { return testcase_name.definition_name; }

  /// Returns a string which must not be freed.
  static const char *get_host_name();
  
  static CHARSTRING get_host_address(const CHARSTRING& type);

  static CHARSTRING get_testcase_id_macro();
  static CHARSTRING get_testcasename();

  static void load_logger_plugins();
  static void set_logger_parameters();

  static const char *get_signal_name(int signal_number);
private:
  static void set_signal_handler(int signal_number, const char *signal_name,
    signal_handler_type signal_handler);
  static void restore_default_handler(int signal_number,
    const char *signal_name);
  static void ignore_signal(int signal_number, const char *signal_name);
  static void enable_interrupt_handler();
  static void disable_interrupt_handler();
public:
  static void install_signal_handlers();
  static void restore_signal_handlers();

public:
  static int hc_main(const char *local_addr, const char *MC_addr,
    unsigned short MC_port);
  static int mtc_main();
  static int ptc_main();

  static component create_component(const char *created_component_type_module,
    const char *created_component_type_name,
    const char *created_component_name,
    const char *created_component_location,
    boolean created_component_alive);
  static void prepare_start_component(const COMPONENT& component_reference,
    const char *module_name, const char *function_name,
    Text_Buf& text_buf);
  static void send_start_component(Text_Buf& text_buf);
  static void start_function(const char *module_name,
    const char *function_name, Text_Buf& text_buf);
  static void function_started(Text_Buf& text_buf);
  static void prepare_function_finished(const char *return_type,
    Text_Buf& text_buf);
  static void send_function_finished(Text_Buf& text_buf);
  static void function_finished(const char *function_name);

  static alt_status component_done(component component_reference);
  static alt_status component_done(component component_reference,
    const char *return_type, Text_Buf*& text_buf);
  static alt_status component_killed(component component_reference);
  static boolean component_running(component component_reference);
  static boolean component_alive(component component_reference);
  static void stop_component(component component_reference);
  static void stop_execution()
  __attribute__ ((__noreturn__));
  static void kill_component(component component_reference);
  static void kill_execution()
  __attribute__ ((__noreturn__));

private:
  static alt_status ptc_done(component component_reference);
  static alt_status any_component_done();
  static alt_status all_component_done();
  static alt_status ptc_killed(component component_reference);
  static alt_status any_component_killed();
  static alt_status all_component_killed();
  static boolean ptc_running(component component_reference);
  static boolean any_component_running();
  static boolean all_component_running();
  static boolean ptc_alive(component component_reference);
  static boolean any_component_alive();
  static boolean all_component_alive();
  static void stop_mtc()
  __attribute__ ((__noreturn__));
  static void stop_ptc(component component_reference);
  static void stop_all_component();
  static void kill_ptc(component component_reference);
  static void kill_all_component();

  static void check_port_name(const char *port_name,
    const char *operation_name, const char *which_argument);
public:
  static void connect_port(
    const COMPONENT& src_compref, const char *src_port,
    const COMPONENT& dst_compref, const char *dst_port);
  static void disconnect_port(
    const COMPONENT& src_compref, const char *src_port,
    const COMPONENT& dst_compref, const char *dst_port);
  static void map_port(
    const COMPONENT& src_compref, const char *src_port,
    const COMPONENT& dst_compref, const char *dst_port);
  static void unmap_port(
    const COMPONENT& src_compref, const char *src_port,
    const COMPONENT& dst_compref, const char *dst_port);

  static void begin_controlpart(const char *module_name);
  static void end_controlpart();
  static void check_begin_testcase(boolean has_timer, double timer_value);
  static void begin_testcase(
    const char *par_module_name, const char *par_testcase_name,
    const char *mtc_comptype_module, const char *mtc_comptype_name,
    const char *system_comptype_module, const char *system_comptype_name,
    boolean has_timer, double timer_value);
  static verdicttype end_testcase();
  static void log_verdict_statistics();

  static void begin_action();
  static void end_action();

  static void setverdict(verdicttype new_value, const char* reason = "");
  static void setverdict(const VERDICTTYPE& new_value,
    const char* reason = "");
  static void set_error_verdict();
  static verdicttype getverdict();
private:
  static void setverdict_internal(verdicttype new_value,
    const char* reason = "");

public:
  /** @name Manipulating external commands
  *   @{
  */
  static void set_begin_controlpart_command(const char *new_command);
  static void set_end_controlpart_command(const char *new_command);
  static void set_begin_testcase_command(const char *new_command);
  static void set_end_testcase_command(const char *new_command);
  static void clear_external_commands();
  /** @} */
private:
  static char *shell_escape(const char *command_str);
  static void execute_command(const char *command_name,
    const char *argument_string);

public:
  static void process_create_mtc();
  static void process_create_ptc(component component_reference,
    const char *component_type_module, const char *component_type_name,
    const char *par_component_name, boolean par_is_alive,
    const char *current_testcase_module, const char *current_testcase_name);

  static void process_create_ack(component new_component);
  static void process_running(boolean result_value);
  static void process_alive(boolean result_value);
  static void process_done_ack(boolean done_status,
    const char *return_type, int return_value_len,
    const void *return_value);
  static void process_killed_ack(boolean killed_status);
  static void process_ptc_verdict(Text_Buf& text_buf);
  static void process_kill();
  static void process_kill_process(component component_reference);

  static void set_component_done(component component_reference,
    const char *return_type, int return_value_len,
    const void *return_value);
  static void set_component_killed(component component_reference);
  static void cancel_component_done(component component_reference);

private:
  static int get_component_status_table_index(component component_reference);
  static alt_status get_killed_status(component component_reference);
  static boolean in_component_status_table(component component_reference);
  static void clear_component_status_table();

  static void initialize_component_process_tables();
  static void add_component(component component_reference, pid_t process_id);
  static void remove_component(component_process_struct *comp);
  static component_process_struct *get_component_by_compref(component
    component_reference);
  static component_process_struct *get_component_by_pid(pid_t process_id);
  static void clear_component_process_tables();

  static void successful_process_creation();
  static void failed_process_creation();

public:
  static void wait_terminated_processes();
  static void check_overload();
};

/** TTCN_TryBlock must be used only as a local variable of a TTCN-3 try{} block.
    It handles the value of TTCN_Runtime::in_ttcn_try_block using C++'s RAII feature */
class TTCN_TryBlock {
  boolean outmost_try;
public:
  TTCN_TryBlock() {
    if (TTCN_Runtime::in_ttcn_try_block) {
      outmost_try = FALSE;
    } else {
      outmost_try = TRUE;
      TTCN_Runtime::in_ttcn_try_block = TRUE;
    }
  }
  ~TTCN_TryBlock() {
    if (outmost_try) {
      TTCN_Runtime::in_ttcn_try_block = FALSE;
    }
  }
};

#endif