2 * include/types.h - types representing the tesh concepts.
4 * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved.
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.
10 * This file declares the types used to run a set of tesh files.
20 #include <xbt/xbt_os_thread.h>
21 #include <xbt/strbuff.h>
31 * byte type definition
33 #ifndef __BYTE_T_DEFINED
34 typedef unsigned char byte;
35 #define __BYTE_T_DEFINED
39 * file descriptor and pid types for portability.
44 #ifndef __FD_T_DEFINED
46 #define __FD_T_DEFINED
49 #ifndef __PID_T_DEFINED
51 #define __PID_T_DEFINED
56 #ifndef __FD_T_DEFINED
58 #define __FD_T_DEFINED
61 #ifndef __PID_T_DEFINED
63 #define __PID_T_DEFINED
67 /* forward declarations */
69 struct s_unit; /* this structure represents a tesh unit */
89 * declaration of the tesh unit type which represents a tesh file
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 */
120 xbt_dynar_t includes;
125 * declaration of the tesh file stream type used to manage the tesh file.
127 typedef struct s_fstream
129 char* name; /* the name of the file stream (same as the name of the tesh file) */
130 char* directory; /* the directory containing the tesh file */
131 FILE* stream; /* the system file stream */
132 struct s_unit* unit; /* a reference to the unit using the file stream object */
134 }s_fstream_t,* fstream_t;
139 typedef enum e_command_status
141 cs_initialized = 0, /* the is initialized */
142 cs_started = 1, /* the command is started */
143 cs_in_progress = 2, /* the command is execited */
144 cs_waiting = 3, /* the command is waiting the writer, the reader and the timer */
145 cs_interrupted = 4, /* the command is interrupted */
146 cs_failed = 5, /* the command is failed */
147 cs_successeded = 6, /* the command is successeded */
148 cs_killed = 7, /* the command is killed */
149 csr_fcntl_function_failed = 8 /* the fcntl function failed */
153 * reason of the status of the command
155 typedef enum e_command_status_raison
157 csr_unknown = 0, /* unknown reason */
158 csr_read_failure = 1, /* a read operation failed */
159 csr_read_pipe_broken = 2, /* the pipe used to read from the stdout of the command is broken */
160 csr_timeout = 3, /* timeout */
161 csr_write_failure = 4, /* a write operation failed */
162 csr_write_pipe_broken = 5, /* the pipe used to write to the stdin of the command is broken */
163 csr_fork_function_failure = 6, /* can't execute the command */
164 csr_wait_failure = 8, /* the wait process function failed */
165 csr_interruption_request = 9, /* the command has received an interruption request */
166 csr_command_not_found = 10, /* the command is not found */
167 csr_exit_codes_dont_match = 11,
168 csr_outputs_dont_match = 12,
169 csr_signals_dont_match = 13,
170 csr_unexpected_signal_caught = 14,
171 csr_expected_signal_not_received = 15,
172 csr_pipe_function_failed = 16, /* the function pipe() or CreatePipe() fails */
173 csr_dup2_function_failure = 17,
174 csr_execlp_function_failure = 18,
175 csr_create_process_function_failure = 19,
176 csr_waitpid_function_failure = 20,
177 csr_get_exit_code_process_function_failure = 21,
178 csr_shell_failed = 22
184 typedef struct s_variable
191 }s_variable_t,* variable_t;
194 * declaration of the tesh timer type
196 typedef struct s_timer
198 xbt_os_thread_t thread; /* asynchronous timer */
199 struct s_command* command; /* the timed command */
200 int timeouted; /* if 1, the timer is timeouted */
201 xbt_os_sem_t started;
202 }s_timer_t,* ttimer_t;
205 * declaration of the tesh reader type
207 typedef struct s_reader
209 xbt_os_thread_t thread; /* asynchonous reader */
210 struct s_command* command; /* the command of the reader */
211 int failed; /* if 1, the reader failed */
212 int broken_pipe; /* if 1, the pipe used by the reader is broken */
214 xbt_os_sem_t started;
215 }s_reader_t,* reader_t;
218 * declaration of the tesh writer type
220 typedef struct s_writer
222 xbt_os_thread_t thread; /* asynchronous writer */
223 struct s_command* command; /* the command of the writer */
224 int failed; /* if 1, the writer failed */
225 int broken_pipe; /* if 1, the pipe used by the writer is broken */
226 xbt_os_sem_t written;
227 xbt_os_sem_t can_write;
229 }s_writer_t,* writer_t;
232 typedef struct s_units
235 int number_of_runned_units; /* the number of units runned */
236 int number_of_ended_units; /* the number of units over */
238 }s_units_t,* units_t;
241 * declaration of the tesh runner type
243 typedef struct s_runner
245 struct s_units* units;
246 int timeouted; /* if 1, the runner is timeouted */
247 int timeout; /* the timeout of the runner */
248 int interrupted; /* if 1, the runner failed */
249 int number_of_runned_units; /* the number of units runned by the runner */
250 int number_of_ended_units; /* the number of ended units */
251 int waiting; /* if 1, the runner is waiting the end of all the units */
252 xbt_os_thread_t thread; /* the timer thread */
253 xbt_dynar_t variables;
256 int total_of_successeded_tests;
257 int total_of_failed_tests;
258 int total_of_interrupted_tests;
261 int total_of_successeded_units;
262 int total_of_failed_units;
263 int total_of_interrupted_units;
266 int total_of_successeded_suites;
267 int total_of_failed_suites;
268 int total_of_interrupted_suites;
271 }s_runner_t,* runner_t;
274 typedef struct s_fstreams
277 }s_fstreams_t,* fstreams_t;
280 typedef struct s_excludes
283 }s_excludes_t,* excludes_t;
285 typedef struct s_directory
289 }s_directory_t,* directory_t;
291 typedef struct s_directories
294 }s_directories_t,* directories_t;
304 * declaration of the tesh context type
306 typedef struct s_context
308 char* command_line; /* the command line of the command to execute */
309 const char* line; /* the current parsed line */
311 int exit_code; /* the expected exit code of the command */
312 char* signal; /* the expected signal raised by the command */
313 int timeout; /* the timeout of the test */
314 xbt_strbuff_t input; /* the input to write in the stdin of the command to run */
315 xbt_strbuff_t output; /* the expected output of the command of the test */
316 output_handling_t output_handling;
317 int async; /* if 1, the command is asynchronous */
320 char* t_command_line; /* translate the command line on Windows */
321 unsigned is_not_found:1;
324 }s_context_t,* context_t;
327 * declaration of the tesh command type
329 typedef struct s_command
332 unit_t unit; /* the unit of the command */
333 struct s_context* context; /* the context of the execution of the command */
334 xbt_os_thread_t thread; /* asynchronous command */
335 struct s_writer* writer; /* the writer used to write in the command stdin */
336 struct s_reader* reader; /* the reader used to read from the command stout */
337 struct s_timer* timer; /* the timer used for the command */
338 command_status_t status; /* the current status of the command */
339 cs_reason_t reason; /* the reason of the state of the command */
340 int successeded; /* if 1, the command is successeded */
341 int interrupted; /* if 1, the command is interrupted */
342 int failed; /* if 1, the command is failed */
343 pid_t pid; /* the program id of the command */
344 xbt_strbuff_t output; /* the output of the command */
345 fd_t stdout_fd; /* the stdout fd of the command */
346 fd_t stdin_fd; /* the stdin fd of the command */
347 int exit_code; /* the exit code of the command */
349 unsigned long stat_val;
353 char* signal; /* the signal raised by the command if any */
354 xbt_os_mutex_t mutex;
357 int killed; /* if 1, the command was killed */
361 }s_command_t,* command_t;
367 #endif /* !__TYPES_H */