4 #include <errno.h> /* for error code */
5 #include <stdlib.h> /* for calloc() */
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
11 /* the unique tesh runner */
15 /* wait for the tesh runner terminaison */
20 runner_start_routine(void* p);
23 /* check the syntax of the tesh files if
24 * the want_check_syntax is specified. Returns
25 * 0 if the syntax is clean.
36 runner_start_routine(void* p)
41 li.QuadPart=- runner->timeout * 10000000; /* 10000000 = 10 000 000 * 100 nanoseconds = 1 second */
43 /* create the waitable timer */
44 timer_handle = CreateWaitableTimer(NULL, TRUE, NULL);
46 /* set a timer to wait for timeout seconds */
47 SetWaitableTimer(timer_handle, &li, 0, NULL, NULL, 0);
49 /* wait for the timer */
50 WaitForSingleObject(timer_handle, INFINITE);
54 exit_code = E_GLOBAL_TIMEOUT;
55 runner->timeouted = 1;
56 xbt_os_sem_release(units_sem);
64 runner_start_routine(void* p)
68 ts.tv_sec = runner->timeout;
74 }while(EINTR == errno);
78 /* TODO process the error */
84 exit_code = E_GLOBAL_TIMEOUT;
85 runner->timeouted = 1;
86 xbt_os_sem_release(units_sem);
97 int want_check_syntax,
107 runner = xbt_new0(s_runner_t, 1);
109 runner->units = xbt_new0(unit_t, number_of_files);
113 /* TODO : display the error */
119 runner->number_of_units = number_of_files;
121 runner->timeout = timeout;
122 runner->timeouted = 0;
123 runner->interrupted = 0;
124 runner->number_of_ended_units = 0;
125 runner->number_of_runned_units = 0;
128 for(i = 0; i < files->number; i++)
131 (runner->units)[j++] = unit_new(runner, NULL, files->items[i], streams[i]);
135 if(want_check_syntax)
137 if((rv = check_syntax()))
150 size = runner->number_of_units;
152 for(i = 0; i < size; i++)
154 unit_free(&(runner->units[i]));
160 CloseHandle(timer_handle);
164 xbt_os_thread_join(runner->thread, NULL);
175 xbt_os_mutex_t mutex;
176 xbt_os_thread_t thread;
178 mutex = xbt_os_mutex_init();
180 for(i = 0; i < runner->number_of_units; i++)
182 if(!unit_run(runner->units[i], mutex))
184 ERROR1("Can't run the unit %s",runner->units[i]->file_name);
193 /* if the runner is timeouted or receive a interruption request
194 * , interrupt all the active units.
197 if(runner->timeouted || interrupted)
201 /*printf("the runner try to join all the units\n");*/
203 for(i = 0; i < runner->number_of_units; i++)
205 thread = runner->units[i]->thread;
208 xbt_os_thread_join(thread, NULL);
211 /*printf("the runner has joined all the units\n");*/
213 xbt_os_mutex_destroy(mutex);
220 if(runner->timeout > 0)
221 runner->thread = xbt_os_thread_create("", runner_start_routine, NULL);
223 /* signal that the runner is waiting */
226 /*printf("the runner try to acquire the units sem\n");*/
227 /* wait for the end of all the units */
228 xbt_os_sem_acquire(units_sem);
229 /*printf("the runner has acquired the units sem\n");*/
235 * interrupt all the active units.
236 * this function is called when the lead time of the execution is reached
237 * or when a failed unit requests an interruption of the execution.
240 runner_interrupt(void)
245 size = runner->number_of_units;
247 for(i = 0; i < size; i++)
248 if(!(runner->units[i]->successeded) && !(runner->units[i]->interrupted))
249 unit_interrupt(runner->units[i]);
253 runner_display_status(void)
259 size = runner->number_of_units;
262 printf("Status informations :\n");
264 printf(" number of units %d\n",size);
267 printf(" exit code %d (failure)\n",exit_code);
269 printf(" exit code %d (success)\n",exit_code);
272 for(i = 0; i < size; i++)
273 unit_display_status(runner->units[i]);
277 if(exit_code == E_SYNTAX)
278 ERROR0("Syntax error detected");
279 else if(exit_code == 0)
301 INFO0("syntax checked (OK)");
303 for(i = 0; i < runner->number_of_units; i++)
305 unit = runner->units[i];
307 fseek(unit->stream,0L, SEEK_SET);
309 unit->number_of_commands = 0;
317 WARN0("mismatch in the syntax : --just-check-syntax and --check-syntax options at same time");