Logo AND Algorithmique Numérique Distribuée

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