Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
last version of tesh
[simgrid.git] / tools / tesh2 / include / types.h
1 #ifndef __TYPES_H       
2 #define __TYPES_H
3
4 #include <def.h>
5
6 #include <portable.h>
7 #include <xbt/xbt_os_thread.h>
8 #include <xbt/strbuff.h>
9 #include <xbt.h>
10
11 #include <dirent.h>
12
13 #include <lstrings.h>
14 #include <vector.h>
15 #include <dictionary.h>
16
17 #ifdef _cplusplus
18 extern "C" {
19 #endif
20
21 /* 
22  * byte type definition 
23  */
24 #ifndef __BYTE_T_DEFINED
25         typedef unsigned char byte;
26         #define __BYTE_T_DEFINED
27 #endif
28
29 /*
30  * file descriptor and pid types for portability.
31  */
32
33 #ifdef WIN32
34         
35         #ifndef __FD_T_DEFINED
36                 typedef HANDLE fd_t;
37                 #define __FD_T_DEFINED
38         #endif
39         
40         #ifndef __PID_T_DEFINED
41                 typedef HANDLE pid_t;
42                 #define __PID_T_DEFINED
43         #endif
44         
45 #else
46
47         #ifndef __FD_T_DEFINED
48                 typedef int fd_t;
49                 #define __FD_T_DEFINED
50         #endif
51         
52         #ifndef __PID_T_DEFINED
53                 typedef int pid_t;
54                 #define __PID_T_DEFINED
55         #endif
56 #endif
57
58
59 /* forward declarations */
60 struct s_runner;
61 struct s_units;
62 struct s_unit;
63 struct s_suites;
64 struct s_suite;
65 struct s_excludes;
66 struct s_fstreams;
67 struct s_fstream;
68 struct s_directories;
69 struct s_directory;
70 struct s_writer;
71 struct s_reader;
72 struct s_timer;
73 struct s_context;
74 struct s_command;
75 struct s_variable;
76 struct s_variables;
77
78
79
80 /* 
81  * command status 
82  */
83 typedef enum e_command_status
84 {
85         cs_initialized                                  = 0,            /* the is initialized                                                                                           */
86         cs_started                                              = 1,            /* the command is started                                                                                       */      
87         cs_in_progress                                  = 2,            /* the command is execited                                                                                      */
88         cs_waiting                                              = 3,            /* the command is waiting the writer, the reader and the timer          */                              
89         cs_interrupted                                  = 4,            /* the command is interrupted                                                                           */      
90         cs_failed                                               = 5,            /* the command is failed                                                                                        */
91         cs_successeded                                  = 6,            /* the command is successeded                                                                           */
92         cs_killed                                               = 7                     /* the command is killed                                                                                        */
93 }command_status_t;
94
95 /* 
96  * reason of the status of the command 
97  */
98 typedef enum e_command_status_raison
99 {
100         csr_unknown                                             = 0,            /* unknown reason                                                                                                       */
101         csr_read_failure                                = 1,            /* a read operation failed                                                                                      */
102         csr_read_pipe_broken                    = 2,            /* the pipe used to read from the stdout of the command is broken       */
103         csr_timeout                                             = 3,            /* timeout                                                                                                                      */
104         csr_write_failure                               = 4,            /* a write operation failed                                                                                     */
105         csr_write_pipe_broken                   = 5,            /* the pipe used to write to the stdin of the command is broken         */
106         csr_exec_failure                                = 6,            /* can't execute the command                                                                            */
107         csr_wait_failure                                = 8,            /* the wait process function failed                                                                     */
108         csr_interruption_request                = 9,            /* the command has received an interruption request                                     */
109         csr_command_not_found                   = 10,           /* the command is not found                                                                                     */
110         csr_exit_codes_dont_match               = 11,
111         csr_outputs_dont_match                  = 12,
112         csr_signals_dont_match                  = 13,
113         csr_unexpected_signal_caught    = 14,
114         csr_expected_signal_not_receipt = 15,
115         csr_pipe_function_failed                = 16            /* the function pipe() or CreatePipe() fails                                            */
116 }cs_reason_t;
117
118 typedef struct s_variable
119 {
120         char* name;
121         char* val;
122         int used:1;
123         int env:1;
124         int err:1;
125 }s_variable_t,* variable_t;
126
127 typedef struct s_variables
128 {
129         dictionary_t items;
130 }s_variables_t,* variables_t;
131
132 /* 
133  * declaration of the tesh timer type 
134  */
135 typedef struct s_timer
136 {
137         xbt_os_thread_t thread;                         /* asynchronous timer                                                                                                   */
138         struct s_command* command;                                      /* the timed command                                                                                                    */
139         int timeouted;                                          /* if 1, the timer is timeouted                                                                                 */
140         xbt_os_sem_t started;
141 }s_timer_t,* ttimer_t;
142
143 /* 
144  * declaration of the tesh reader type 
145  */
146 typedef struct s_reader
147 {
148         xbt_os_thread_t thread;                         /* asynchonous reader                                                                                                   */
149         struct s_command* command;                                      /* the command of the reader                                                                                    */
150         int failed;                                                     /* if 1, the reader failed                                                                                              */
151         int broken_pipe;                                        /* if 1, the pipe used by the reader is broken                                                  */
152         int done;
153         xbt_os_sem_t started;
154 }s_reader_t,* reader_t;
155
156 /* 
157  * declaration of the tesh writer type 
158  */
159 typedef struct s_writer
160 {
161         xbt_os_thread_t thread;                         /* asynchronous writer                                                                                                  */
162         struct s_command* command;                                      /* the command of the writer                                                                                    */
163         int failed;                                                     /* if 1, the writer failed                                                                                              */
164         int broken_pipe;                                        /* if 1, the pipe used by the writer is broken                                                  */
165         xbt_os_sem_t written;
166         xbt_os_sem_t can_write;
167         int done;
168 }s_writer_t,* writer_t;
169
170
171 typedef struct s_units
172 {
173         vector_t items;                                 /* used to store the units                                                                                              */
174         int number_of_runned_units;             /* the number of units runned                                                                                   */
175         int number_of_ended_units;              /* the number of units over                                                                                             */
176         
177 }s_units_t,* units_t;
178
179 /* 
180  * declaration of the tesh unit type 
181  */
182 typedef struct s_unit
183 {
184         char* description;
185         int is_suite;
186         struct s_fstream* fstream;
187         struct s_runner* runner;                                        /* the runner of the unit                                                                                           */
188         vector_t commands;
189         int number_of_commands;                         /* number of created commands of the unit                                                               */      
190         int number_of_started_commands;         /* number of runned commands of the unit                                                                */
191         int number_of_interrupted_commands;     /* number of interrupted commands of the unit                                                   */      
192         int number_of_failed_commands;          /* number of failed commands of the unit                                                                */
193         int number_of_successeded_commands;     /* number of successeded commands of the unit                                                   */
194         int number_of_terminated_commands;      /* number of ended commands                                                                                             */
195         int number_of_waiting_commands;
196         xbt_os_thread_t thread;                         /* all the units run in its own thread                                                                  */
197         xbt_os_sem_t sem;                                       /* used by the commands of the unit to signal the end of the unit               */
198         xbt_os_mutex_t mutex;                           /* used to synchronously access to the properties of the runner                 */
199         int interrupted;                                        /* if 1, the unit is interrupted by the runner                                                  */
200         int failed;                                                     /* if 1, the unit is failed                                                                                             */
201         int successeded;                                        /* if 1, the unit is successeded                                                                                */
202         int parsed;                                                     /* if 1, the tesh file of the unit is parsed                                                    */
203         int released;
204         int parsing_include_file;
205         struct s_unit* owner;                           /* the unit containing the unit if any                                                                  */
206         struct s_unit* root;
207         vector_t suites;
208         int number;                                                     /* the number of suites                                                                                                 */
209         int capacity;                                           /* the number of suites that the unit can contain                                               */
210         int running_suite;                                      /* if 1, the suite running a suite                                                                              */
211         vector_t includes;                                                              
212 }s_unit_t,* unit_t;
213
214
215
216
217 /* 
218  * declaration of tesh suite type
219  */
220 typedef struct s_suite
221 {
222         const char* description;                        /* the name of the suite                                                                                                */
223         struct s_unit* owner;                                           /* the unit owning the suite                                                                                    */
224         vector_t units;                                         /* the units of the suite                                                                                               */              
225         int number;                                                     /* the numnber of suites contained by the suite                                                 */                      
226         int capacity;                                           /* the number of suites that the vector can contain                                     */
227         int number_of_successed_units;          /* the number of successeded units of the suite                                                 */
228         int number_of_failed_units;                     /* the number of failed units of the suite                                                              */      
229 }s_suite_t,* suite_t;
230
231 /* 
232  * declaration of the tesh runner type 
233  */
234 typedef struct s_runner
235 {
236         
237         /*vector_t units;*/                                     /* the vector containing all the units launched by the runner                   */
238         struct s_units* units;
239         int timeouted;                                          /* if 1, the runner is timeouted                                                                                */
240         int timeout;                                            /* the timeout of the runner                                                                                    */
241         int interrupted;                                        /* if 1, the runner failed                                                                                              */
242         int number_of_runned_units;                     /* the number of units runned by the runner                                                             */
243         int number_of_ended_units;                      /* the number of ended units                                                                                    */
244         int waiting;                                            /* if 1, the runner is waiting the end of all the units                                 */
245         xbt_os_thread_t thread;                         /* the timer thread                                                                                                             */
246         vector_t variables;
247
248         int total_of_tests;
249         int total_of_successeded_tests;
250         int total_of_failed_tests;
251         int total_of_interrupted_tests;
252         
253         int total_of_units;
254         int total_of_successeded_units;
255         int total_of_failed_units;
256         int total_of_interrupted_units;
257         
258         int total_of_suites;
259         int total_of_successeded_suites;
260         int total_of_failed_suites;
261         int total_of_interrupted_suites;
262 }s_runner_t,* runner_t;
263
264
265 typedef struct s_fstreams
266 {
267         vector_t items;
268 }s_fstreams_t,* fstreams_t;
269
270
271 typedef struct s_fstream
272 {
273         char* name;
274         char* directory;
275         FILE* stream;
276 }s_fstream_t,* fstream_t;
277
278 typedef struct s_excludes
279 {
280         vector_t items;
281 }s_excludes_t,* excludes_t;
282
283 typedef struct s_directory
284 {
285         char* name;
286         DIR* stream;
287 }s_directory_t,* directory_t;
288
289 typedef struct s_directories
290 {
291         vector_t items;
292 }s_directories_t,* directories_t;
293
294
295 typedef enum 
296 {
297         oh_check, 
298         oh_display, 
299         oh_ignore
300 }output_handling_t;
301 /* 
302  * declaration of the tesh context type 
303  */
304 typedef struct s_context
305 {
306         const char* command_line;                       /* the command line of the command to execute                                                   */
307         const char* line;                                       /* the current parsed line                                                                                              */
308         int exit_code;                                          /* the expected exit code of the command                                                                */
309         char* signal;                                           /* the expected signal raised by the command                                                    */
310         int timeout;                                            /* the timeout of the test                                                                                              */
311         xbt_strbuff_t input;                            /* the input to write in the stdin of the command to run                                */
312         xbt_strbuff_t output;                           /* the expected output of the command of the test                                               */
313         output_handling_t output_handling;
314         int async;                                                      /* if 1, the command is asynchronous                                                                    */
315 }s_context_t,* context_t;
316
317
318 typedef void (*fn_sig_io_handler_t)(int);
319 /* 
320  * declaration of the tesh command type 
321  */
322 typedef struct s_command
323 {
324         unit_t unit;                                            /* the unit of the command                                                                                              */
325         struct s_context* context;                                      /* the context of the execution of the command                                                  */
326         xbt_os_thread_t thread;                         /* asynchronous command                                                                                                 */
327         struct s_writer* writer;                                        /* the writer used to write in the command stdin                                                */
328         struct s_reader* reader;                                        /* the reader used to read from the command stout                                               */
329         struct s_timer* timer;                                          /* the timer used for the command                                                                               */
330         command_status_t status;                        /* the current status of the command                                                                    */
331         cs_reason_t reason;                                     /* the reason of the state of the command                                                               */
332         int successeded;                                        /* if 1, the command is successeded                                                                             */
333         int interrupted;                                        /* if 1, the command is interrupted                                                                             */
334         int failed;                                                     /* if 1, the command is failed                                                                                  */
335         pid_t pid;                                                      /* the program id of the command                                                                                */
336         xbt_strbuff_t output;                           /* the output of the command                                                                                    */
337         fd_t stdout_fd;                                         /* the stdout fd of the command                                                                                 */
338         fd_t stdin_fd;                                          /* the stdin fd of the command                                                                                  */
339         int exit_code;                                          /* the exit code of the command                                                                                 */
340         #ifdef WIN32
341         unsigned long stat_val;
342         #else
343         int stat_val;
344         #endif
345         char* signal;                                           /* the signal raised by the command if any                                                              */
346         xbt_os_mutex_t mutex;
347         #ifndef WIN32
348         int killed;                                                     /* if 1, the command was killed                                                                                 */
349         #endif
350         
351         fn_sig_io_handler_t fn_sig_io_handler;
352 }s_command_t,* command_t;
353
354 #ifdef _cplusplus
355 }
356 #endif
357
358
359 #endif /* !__TYPES_H */