5 #include <errno.h> /* for error code */
6 #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 = ELEADTIME;
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 = ELEADTIME;
85 runner->timeouted = 1;
86 xbt_os_sem_release(units_sem);
96 runner_init(int want_check_syntax, int timeout, fstreams_t fstreams)
101 ERROR0("Runner is already initialized");
106 runner = xbt_new0(s_runner_t, 1);
108 if(!(runner->units = units_new(runner, fstreams)))
110 ERROR0("Runner initialization failed");
117 runner->timeout = timeout;
118 runner->timeouted = 0;
119 runner->interrupted = 0;
120 runner->number_of_ended_units = 0;
121 runner->number_of_runned_units = 0;
124 if(want_check_syntax)
126 if((errno = check_syntax()))
137 units_free((void**)(&(runner->units)));
140 CloseHandle(timer_handle);
144 xbt_os_thread_join(runner->thread, NULL);
154 xbt_os_mutex_t mutex;
156 mutex = xbt_os_mutex_init();
158 units_run_all(runner->units, mutex);
163 /* if the runner is timeouted or receive a interruption request
164 * , interrupt all the active units.
166 if(runner->timeouted || interrupted)
169 units_join_all(runner->units);
171 xbt_os_mutex_destroy(mutex);
178 if(runner->timeout > 0)
179 runner->thread = xbt_os_thread_create("", runner_start_routine, NULL);
180 /* signal that the runner is waiting */
183 /* wait for the end of all the units */
184 xbt_os_sem_acquire(units_sem);
192 * interrupt all the active units.
193 * this function is called when the lead time of the execution is reached
194 * or when a failed unit requests an interruption of the execution.
197 runner_interrupt(void)
199 units_interrupt_all(runner->units);
203 runner_display_status(void)
211 printf("Status informations :\n");
213 printf(" number of units %d\n",units_get_size(runner->units));
214 printf(" exit code %d (%s)\n",exit_code, exit_code ? error_to_string(exit_code) : "success");
216 units_verbose(runner->units);
221 ERROR0("Syntax error detected");
222 else if(exit_code == 0)
241 INFO0("syntax checked (OK)");
243 units_reset_all(runner->units);
250 WARN0("mismatch in the syntax : --just-check-syntax and --check-syntax options at same time");