2 * include/types.h - types representing the tesh concepts.
\r
4 * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved.
\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
10 * This file declares the types used to run a set of tesh files.
\r
19 #include <portable.h>
\r
20 #include <xbt/xbt_os_thread.h>
\r
21 #include <xbt/strbuff.h>
\r
31 * byte type definition
\r
33 #ifndef __BYTE_T_DEFINED
\r
34 typedef unsigned char byte;
\r
35 #define __BYTE_T_DEFINED
\r
39 * file descriptor and pid types for portability.
\r
44 #ifndef __FD_T_DEFINED
\r
45 typedef HANDLE fd_t;
\r
46 #define __FD_T_DEFINED
\r
49 #ifndef __PID_T_DEFINED
\r
50 typedef HANDLE pid_t;
\r
51 #define __PID_T_DEFINED
\r
56 #ifndef __FD_T_DEFINED
\r
58 #define __FD_T_DEFINED
\r
61 #ifndef __PID_T_DEFINED
\r
63 #define __PID_T_DEFINED
\r
67 /* forward declarations */
\r
69 struct s_unit; /* this structure represents a tesh unit */
\r
77 struct s_directories;
\r
89 * declaration of the tesh unit type which represents a tesh file
\r
92 typedef struct s_unit
\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
121 * declaration of the tesh file stream type used to manage the tesh file.
\r
123 typedef struct s_fstream
\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
134 typedef enum e_command_status
\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
148 * reason of the status of the command
\r
150 typedef enum e_command_status_raison
\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
174 typedef struct s_xerror
\r
176 const char* reason;
\r
178 const char* command;
\r
180 }s_xerror_t,* xerror_t;
\r
183 typedef struct s_variable
\r
190 }s_variable_t,* variable_t;
\r
193 * declaration of the tesh timer type
\r
195 typedef struct s_timer
\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
204 * declaration of the tesh reader type
\r
206 typedef struct s_reader
\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
213 xbt_os_sem_t started;
\r
214 }s_reader_t,* reader_t;
\r
217 * declaration of the tesh writer type
\r
219 typedef struct s_writer
\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
228 }s_writer_t,* writer_t;
\r
231 typedef struct s_units
\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
237 }s_units_t,* units_t;
\r
240 * declaration of the tesh runner type
\r
242 typedef struct s_runner
\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
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
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
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
271 typedef struct s_fstreams
\r
274 }s_fstreams_t,* fstreams_t;
\r
277 typedef struct s_excludes
\r
280 }s_excludes_t,* excludes_t;
\r
282 typedef struct s_directory
\r
286 }s_directory_t,* directory_t;
\r
288 typedef struct s_directories
\r
291 }s_directories_t,* directories_t;
\r
299 }output_handling_t;
\r
301 * declaration of the tesh context type
\r
303 typedef struct s_context
\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
317 * declaration of the tesh command type
\r
319 typedef struct s_command
\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
338 unsigned long stat_val;
\r
342 char* signal; /* the signal raised by the command if any */
\r
343 xbt_os_mutex_t mutex;
\r
346 int killed; /* if 1, the command was killed */
\r
350 }s_command_t,* command_t;
\r
356 #endif /* !__TYPES_H */
\r