7 #include <errno.h> /* for error code */
8 #include <stdlib.h> /* for calloc() */
11 #include <sys/resource.h>
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
18 /* the unique tesh runner */
22 /* wait for the tesh runner terminaison */
27 runner_start_routine(void* p);
30 /* check the syntax of the tesh files if
31 * the want_check_syntax is specified. Returns
32 * 0 if the syntax is clean.
43 runner_start_routine(void* p)
48 li.QuadPart=- runner->timeout * 10000000; /* 10000000 = 10 000 000 * 100 nanoseconds = 1 second */
50 /* create the waitable timer */
51 timer_handle = CreateWaitableTimer(NULL, TRUE, NULL);
53 /* set a timer to wait for timeout seconds */
54 SetWaitableTimer(timer_handle, &li, 0, NULL, NULL, 0);
56 /* wait for the timer */
57 WaitForSingleObject(timer_handle, INFINITE);
61 exit_code = ELEADTIME;
62 runner->timeouted = 1;
63 xbt_os_sem_release(units_sem);
71 runner_start_routine(void* p)
75 ts.tv_sec = runner->timeout;
81 }while(EINTR == errno);
85 /* TODO process the error */
91 exit_code = ELEADTIME;
92 runner->timeouted = 1;
93 xbt_os_sem_release(units_sem);
103 runner_init(int want_check_syntax, int timeout, fstreams_t fstreams)
108 char buffer[MAX_PATH + 1] = {0};
113 if(!(runner = (runner_t)calloc(1, sizeof(s_runner_t))))
117 if(!(runner->units = units_new(runner, fstreams)))
124 runner->timeout = timeout;
125 runner->timeouted = 0;
126 runner->interrupted = 0;
127 runner->number_of_ended_units = 0;
128 runner->number_of_runned_units = 0;
131 runner->total_of_tests = 0;
132 runner->total_of_successeded_tests = 0;
133 runner->total_of_failed_tests = 0;
134 runner->total_of_interrupted_tests = 0;
136 runner->total_of_units = 0;
137 runner->total_of_successeded_units = 0;
138 runner->total_of_failed_units = 0;
139 runner->total_of_interrupted_units = 0;
141 runner->total_of_suites = 0;
142 runner->total_of_successeded_suites = 0;
143 runner->total_of_failed_suites = 0;
144 runner->total_of_interrupted_suites = 0;
146 /* initialize the vector of variables */
147 runner->variables = vector_new(32, (fn_finalize_t)variable_free);
150 for(i = 0; environ[i] != NULL; i++)
152 val = strchr(environ[i], '=');
159 strncpy(buffer, environ[i], (val - environ[i] -1));
161 variable = variable_new(buffer, val);
164 /*printf("Add the environment variable %s %s\n", variable->name, variable->val);*/
166 vector_push_back(runner->variables, variable);
172 while((cstr = error_get_at(i++, &code)))
174 sprintf(buffer,"%d",code);
175 variable = variable_new(cstr, buffer);
177 vector_push_back(runner->variables, variable);
181 if(want_check_syntax)
191 units_free((void**)(&(runner->units)));
192 vector_free(&runner->variables);
196 CloseHandle(timer_handle);
200 xbt_os_thread_join(runner->thread, NULL);
210 xbt_os_mutex_t mutex;
212 mutex = xbt_os_mutex_init();
214 units_run_all(runner->units, mutex);
219 /* if the runner is timeouted or receive a interruption request
220 * , interrupt all the active units.
222 if(runner->timeouted || interrupted)
225 units_join_all(runner->units);
227 xbt_os_mutex_destroy(mutex);
234 if(runner->timeout > 0)
235 runner->thread = xbt_os_thread_create("", runner_start_routine, NULL);
236 /* signal that the runner is waiting */
239 /* wait for the end of all the units */
240 xbt_os_sem_acquire(units_sem);
248 * interrupt all the active units.
249 * this function is called when the lead time of the execution is reached
250 * or when a failed unit requests an interruption of the execution.
253 runner_interrupt(void)
255 units_interrupt_all(runner->units);
259 runner_display_status(void)
264 struct rusage r_usage;
266 /*printf("\033[1m");*/
267 printf("\n TEst SHell utility - mini shell specialized in running test units.\n");
268 printf(" =============================================================================\n");
269 /*printf("\033[0m");*/
271 units_verbose(runner->units);
273 /*printf("\033[1m");*/
274 printf(" =====================================================================%s\n",
275 runner->total_of_failed_tests ? "== FAILED": (runner->total_of_interrupted_tests || runner->total_of_interrupted_units) ? "==== INTR" : "====== OK");
277 printf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok",
278 (runner->total_of_suites ? (1-((double)runner->total_of_failed_suites + (double)runner->total_of_interrupted_suites)/(double)runner->total_of_suites)*100.0 : 100.0),
279 runner->total_of_suites, runner->total_of_successeded_suites);
281 if(runner->total_of_failed_suites > 0)
282 printf(", %d failed", runner->total_of_failed_suites);
284 if(runner->total_of_interrupted_suites > 0)
285 printf(", %d interrupted)", runner->total_of_interrupted_suites);
289 printf(" Unit(s): %.0f%% ok (%d unit(s): %d ok",
290 (runner->total_of_units ? (1-((double)runner->total_of_failed_units + (double)runner->total_of_interrupted_units)/(double)runner->total_of_units)*100.0 : 100.0),
291 runner->total_of_units, runner->total_of_successeded_units);
293 if(runner->total_of_failed_units > 0)
294 printf(", %d failed", runner->total_of_failed_units);
296 if(runner->total_of_interrupted_units > 0)
297 printf(", %d interrupted)", runner->total_of_interrupted_units);
301 printf(" Test(s): %.0f%% ok (%d test(s): %d ok",
302 (runner->total_of_tests ? (1-((double)runner->total_of_failed_tests + (double)runner->total_of_interrupted_tests)/(double)runner->total_of_tests)*100.0 : 100.0),
303 runner->total_of_tests, runner->total_of_successeded_tests);
305 if(runner->total_of_failed_tests > 0)
306 printf(", %d failed", runner->total_of_failed_tests);
308 if(runner->total_of_interrupted_tests > 0)
309 printf(", %d interrupted)", runner->total_of_interrupted_tests);
314 if(!getrusage(RUSAGE_SELF, &r_usage))
317 printf(" Total tesh user time used: %ld second(s) %ld microsecond(s)\n", r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec);
318 printf(" Total tesh system time used: %ld second(s) %ld microsecond(s)\n\n", r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec);
320 if(!getrusage(RUSAGE_CHILDREN, &r_usage))
322 printf(" Total children user time used: %ld second(s) %ld microsecond(s)\n", r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec);
323 printf(" Total children system time used: %ld second(s) %ld microsecond(s)\n\n", r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec);
328 /*printf("\033[0m");*/
333 ERROR0("Syntax error detected");
353 INFO0("syntax checked (OK)");
355 units_reset_all(runner->units);
362 WARN0("mismatch in the syntax : --just-check-syntax and --check-syntax options at same time");