Logo AND Algorithmique Numérique Distribuée

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