Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6c4cff8d0c1c6f627638fe36375c081f4fb0a40b
[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
75
76 /* 
77  * command status 
78  */
79 typedef enum e_command_status
80 {
81         cs_initialized                                  = 0,            /* the is initialized                                                                                           */
82         cs_started                                              = 1,            /* the command is started                                                                                       */      
83         cs_in_progress                                  = 2,            /* the command is execited                                                                                      */
84         cs_waiting                                              = 3,            /* the command is waiting the writer, the reader and the timer          */                              
85         cs_interrupted                                  = 4,            /* the command is interrupted                                                                           */      
86         cs_failed                                               = 5,            /* the command is failed                                                                                        */
87         cs_successeded                                  = 6,            /* the command is successeded                                                                           */
88         cs_killed                                               = 7                     /* the command is killed                                                                                        */
89 }command_status_t;
90
91 /* 
92  * reason of the status of the command 
93  */
94 typedef enum e_command_status_raison
95 {
96         csr_unknown                                             = 0,            /* unknown reason                                                                                                       */
97         csr_read_failure                                = 1,            /* a read operation failed                                                                                      */
98         csr_read_pipe_broken                    = 2,            /* the pipe used to read from the stdout of the command is broken       */
99         csr_timeout                                             = 3,            /* timeout                                                                                                                      */
100         csr_write_failure                               = 4,            /* a write operation failed                                                                                     */
101         csr_write_pipe_broken                   = 5,            /* the pipe used to write to the stdin of the command is broken         */
102         csr_exec_failure                                = 6,            /* can't execute the command                                                                            */
103         csr_wait_failure                                = 8,            /* the wait process function failed                                                                     */
104         csr_interruption_request                = 9,            /* the command has received an interruption request                                     */
105         csr_command_not_found                   = 10,           /* the command is not found                                                                                     */
106         csr_exit_codes_dont_match               = 11,
107         csr_outputs_dont_match                  = 12,
108         csr_signals_dont_match                  = 13,
109         csr_unexpected_signal_caught    = 14,
110         csr_expected_signal_not_receipt = 15,
111         csr_pipe_function_failed                = 16            /* the function pipe() or CreatePipe() fails                                            */
112 }cs_reason_t;
113
114
115 struct s_command;
116 struct s_variable;
117 struct s_variables;
118
119
120 /* 
121  * declaration of the tesh timer type 
122  */
123 typedef struct s_timer
124 {
125         xbt_os_thread_t thread;                         /* asynchronous timer                                                                                                   */
126         struct s_command* command;                                      /* the timed command                                                                                                    */
127         int timeouted;                                          /* if 1, the timer is timeouted                                                                                 */
128         xbt_os_sem_t started;
129 }s_timer_t,* ttimer_t;
130
131 /* 
132  * declaration of the tesh reader type 
133  */
134 typedef struct s_reader
135 {
136         xbt_os_thread_t thread;                         /* asynchonous reader                                                                                                   */
137         struct s_command* command;                                      /* the command of the reader                                                                                    */
138         int failed;                                                     /* if 1, the reader failed                                                                                              */
139         int broken_pipe;                                        /* if 1, the pipe used by the reader is broken                                                  */
140         xbt_os_sem_t started;
141 }s_reader_t,* reader_t;
142
143 /* 
144  * declaration of the tesh writer type 
145  */
146 typedef struct s_writer
147 {
148         xbt_os_thread_t thread;                         /* asynchronous writer                                                                                                  */
149         struct s_command* command;                                      /* the command of the writer                                                                                    */
150         int failed;                                                     /* if 1, the writer failed                                                                                              */
151         int broken_pipe;                                        /* if 1, the pipe used by the writer is broken                                                  */
152         xbt_os_sem_t started;
153 }s_writer_t,* writer_t;
154
155 typedef struct s_units
156 {
157         vector_t items;                                 /* used to store the units                                                                                              */
158         int number_of_runned_units;             /* the number of units runned                                                                                   */
159         int number_of_ended_units;              /* the number of units over                                                                                             */
160         
161 }s_units_t,* units_t;
162
163 /* 
164  * declaration of the tesh unit type 
165  */
166 typedef struct s_unit
167 {
168         struct s_fstream* fstream;
169         struct s_runner* runner;                                        /* the runner of the unit                                                                                           */
170         vector_t commands;
171         int number_of_commands;                         /* number of created commands of the unit                                                               */      
172         int number_of_started_commands;         /* number of runned commands of the unit                                                                */
173         int number_of_interrupted_commands;     /* number of interrupted commands of the unit                                                   */      
174         int number_of_failed_commands;          /* number of failed commands of the unit                                                                */
175         int number_of_successeded_commands;     /* number of successeded commands of the unit                                                   */
176         int number_of_terminated_commands;      /* number of ended commands                                                                                             */
177         xbt_os_thread_t thread;                         /* all the units run in its own thread                                                                  */
178         xbt_os_sem_t sem;                                       /* used by the commands of the unit to signal the end of the unit               */
179         xbt_os_mutex_t mutex;                           /* used to synchronously access to the properties of the runner                 */
180         int interrupted;                                        /* if 1, the unit is interrupted by the runner                                                  */
181         int failed;                                                     /* if 1, the unit is failed                                                                                             */
182         int successeded;                                        /* if 1, the unit is successeded                                                                                */
183         int parsed;                                                     /* if 1, the tesh file of the unit is parsed                                                    */
184         int released;
185         int parsing_include_file;
186         struct s_suite* owner;                                          /* the suite containing the unit if any                                                                 */
187         vector_t suites;
188         int number;                                                     /* the number of suites                                                                                                 */
189         int capacity;                                           /* the number of suites that the unit can contain                                               */
190         int running_suite;                                      /* if 1, the suite running a suite                                                                              */                                                                      
191 }s_unit_t,* unit_t;
192
193
194 /* 
195  * declaration of tesh suite type
196  */
197 typedef struct s_suite
198 {
199         const char* description;                        /* the name of the suite                                                                                                */
200         struct s_unit* owner;                                           /* the unit owning the suite                                                                                    */
201         vector_t units;                                         /* the units of the suite                                                                                               */              
202         int number;                                                     /* the numnber of suites contained by the suite                                                 */                      
203         int capacity;                                           /* the number of suites that the vector can contain                                     */
204         int number_of_successed_units;          /* the number of successeded units of the suite                                                 */
205         int number_of_failed_units;                     /* the number of failed units of the suite                                                              */      
206 }s_suite_t,* suite_t;
207
208 /* 
209  * declaration of the tesh runner type 
210  */
211 typedef struct s_runner
212 {
213         
214         /*vector_t units;*/                                             /* the vector containing all the units launched by the runner                   */
215         struct s_units* units;
216         int timeouted;                                          /* if 1, the runner is timeouted                                                                                */
217         int timeout;                                            /* the timeout of the runner                                                                                    */
218         int interrupted;                                        /* if 1, the runner failed                                                                                              */
219         int number_of_runned_units;                     /* the number of units runned by the runner                                                             */
220         int number_of_ended_units;                      /* the number of ended units                                                                                    */
221         int waiting;                                            /* if 1, the runner is waiting the end of all the units                                 */
222         xbt_os_thread_t thread;                         /* the timer thread                                                                                                             */
223 }s_runner_t,* runner_t;
224
225
226 typedef struct s_fstreams
227 {
228         vector_t items;
229 }s_fstreams_t,* fstreams_t;
230
231
232 typedef struct s_fstream
233 {
234         char* name;
235         char* directory;
236         FILE* stream;
237 }s_fstream_t,* fstream_t;
238
239 typedef struct s_excludes
240 {
241         vector_t items;
242 }s_excludes_t,* excludes_t;
243
244 typedef struct s_directory
245 {
246         char* name;
247         DIR* stream;
248         int load;
249 }s_directory_t,* directory_t;
250
251 typedef struct s_directories
252 {
253         vector_t items;
254 }s_directories_t,* directories_t;
255
256
257 typedef enum 
258 {
259         oh_check, 
260         oh_display, 
261         oh_ignore
262 }output_handling_t;
263 /* 
264  * declaration of the tesh context type 
265  */
266 typedef struct s_context
267 {
268         const char* command_line;                       /* the command line of the command to execute                                                   */
269         const char* line;                                       /* the current parsed line                                                                                              */
270         int exit_code;                                          /* the expected exit code of the command                                                                */
271         char* signal;                                           /* the expected signal raised by the command                                                    */
272         int timeout;                                            /* the timeout of the test                                                                                              */
273         xbt_strbuff_t input;                            /* the input to write in the stdin of the command to run                                */
274         xbt_strbuff_t output;                           /* the expected output of the command of the test                                               */
275         output_handling_t output_handling;
276         int async;                                                      /* if 1, the command is asynchronous                                                                    */
277 }s_context_t,* context_t;
278
279 /* 
280  * declaration of the tesh command type 
281  */
282 typedef struct s_command
283 {
284         unit_t unit;                                            /* the unit of the command                                                                                              */
285         struct s_context* context;                                      /* the context of the execution of the command                                                  */
286         xbt_os_thread_t thread;                         /* asynchronous command                                                                                                 */
287         struct s_writer* writer;                                        /* the writer used to write in the command stdin                                                */
288         struct s_reader* reader;                                        /* the reader used to read from the command stout                                               */
289         struct s_timer* timer;                                          /* the timer used for the command                                                                               */
290         command_status_t status;                        /* the current status of the command                                                                    */
291         cs_reason_t reason;                                     /* the reason of the state of the command                                                               */
292         int successeded;                                        /* if 1, the command is successeded                                                                             */
293         int interrupted;                                        /* if 1, the command is interrupted                                                                             */
294         int failed;                                                     /* if 1, the command is failed                                                                                  */
295         pid_t pid;                                                      /* the program id of the command                                                                                */
296         xbt_strbuff_t output;                           /* the output of the command                                                                                    */
297         fd_t stdout_fd;                                         /* the stdout fd of the command                                                                                 */
298         fd_t stdin_fd;                                          /* the stdin fd of the command                                                                                  */
299         int exit_code;                                          /* the exit code of the command                                                                                 */
300         #ifdef WIN32
301         unsigned long stat_val;
302         #else
303         int stat_val;
304         #endif
305         char* signal;                                           /* the signal raised by the command if any                                                              */
306         xbt_os_mutex_t mutex;
307         #ifndef WIN32
308         int killed;                                                     /* if 1, the command was killed                                                                                 */
309         #endif
310 }s_command_t,* command_t;
311
312 #ifdef _cplusplus
313 }
314 #endif
315
316
317 #endif /* !__TYPES_H */