- /* interrupt the run of the specified unit */\r
- unit->interrupted = 1;\r
- xbt_os_sem_release(unit->sem);\r
- \r
- return 0;\r
-}\r
-\r
-/* just print the title of the root unit or a suite (if any) */\r
-static void \r
-print_title(const char* description)\r
-{\r
- register int i;\r
- char title[80];\r
- size_t len = strlen(description);\r
- \r
- title[0]=' ';\r
- \r
- for (i = 1; i < 79; i++)\r
- title[i]='=';\r
- \r
- title[i++]='\n';\r
- title[79]='\0';\r
- \r
- sprintf(title + 40 - (len + 4)/2, "[ %s ]",description);\r
- title[40 + (len + 5 ) / 2] = '=';\r
- \r
- printf("\n%s\n",title); \r
-}\r
-\r
-int\r
-unit_summuarize(unit_t unit)\r
-{\r
- command_t command;\r
- unsigned int itc, itu, its;\r
- unit_t include;\r
- unit_t suite;\r
- char* p;\r
- char title[PATH_MAX + 1] = {0};\r
- \r
- int number_of_tests = 0; /* number of tests of a unit contained by this unit */\r
- int number_of_failed_tests = 0; /* number of failed test of a unit contained by this unit */\r
- int number_of_successeded_tests = 0; /* number of successeded tests of a unit contained by this unit */\r
- int number_of_interrupted_tests = 0; /* number of interrupted tests of a unit contained by this unit */\r
- \r
- int number_of_tests_of_suite = 0; /* number of tests of a suite contained by this unit */\r
- int number_of_interrupted_tests_of_suite = 0; /* number of interrupted tests of a suite contained by this unit */ \r
- int number_of_failed_tests_of_suite = 0; /* number of failed tests of a suite contained by this unit */\r
- int number_of_successeded_tests_of_suite = 0; /* number of successeded tests of a suite contained by this */\r
- \r
- int number_of_units = 0; /* number of units contained by a suite */\r
- int number_of_failed_units = 0; /* number of failed units contained by a suite */\r
- int number_of_successeded_units = 0; /* number of successeded units contained by a suite */\r
- int number_of_interrupted_units = 0; /* number of interrupted units contained by a suite */\r
- \r
- int total_of_tests = 0; /* total of the tests contained by this unit */\r
- int total_of_failed_tests = 0; /* total of failed tests contained by this unit */\r
- int total_of_successeded_tests = 0; /* total of successeded tests contained by this unit */\r
- int total_of_interrupted_tests = 0; /* total of interrupted tests contained by this unit */\r
- \r
- int total_of_units = 0; /* total of units contained by this unit */\r
- int total_of_failed_units = 0; /* total of failed units contained by this unit */\r
- int total_of_successeded_units = 0; /* total of successeded units contained by this unit */\r
- int total_of_interrupted_units = 0; /* total of interrutped units contained by this unit */\r
- \r
- int total_of_suites = 0; /* total of suites contained by this unit */\r
- int total_of_failed_suites = 0; /* total of failed suites contained by this unit */\r
- int total_of_successeded_suites = 0; /* total of successeded suites contained by this unit */ \r
- int total_of_interrupted_suites = 0; /* total of interrupted suites contained by this unit */\r
- \r
- /* check the parameter */\r
- if(!(unit))\r
- {\r
- errno = EINVAL;\r
- return -1;\r
- }\r
- \r
- if((unit->description) && strlen(unit->description) < 78)\r
- strcpy(title, unit->description);\r
- else\r
- sprintf(title, "file : %s",unit->fstream->name);\r
- \r
- if(unit->interrupted)\r
- strcat(title, " (interrupted)");\r
- \r
- print_title(title);\r
- \r
- number_of_tests = xbt_dynar_length(unit->commands);\r
- \r
- /* tests */\r
- xbt_dynar_foreach(unit->commands, itc, command)\r
- {\r
- if(command->status == cs_interrupted)\r
- number_of_interrupted_tests++;\r
- else if(command->status == cs_failed)\r
- number_of_failed_tests++;\r
- else if(command->status == cs_successeded)\r
- number_of_successeded_tests++;\r
- }\r
-\r
- \r
- if(number_of_tests)\r
- {\r
- asprintf(&p," Test(s): .........................................................................");\r
- \r
- p[70] = '\0';\r
- printf("%s", p);\r
- free(p); \r
- \r
- if(number_of_failed_tests > 0) \r
- printf(".. failed\n");\r
- else if(number_of_interrupted_tests > 0) \r
- printf("interrupt\n");\r
- else \r
- printf(".... ..ok\n"); \r
-\r
- xbt_dynar_foreach(unit->commands, itc, command)\r
- {\r
- printf(" %s: %s [%s]\n", \r
- command->status == cs_interrupted ? "INTR " \r
- : command->status == cs_failed ? "FAILED" \r
- : command->status == cs_successeded ? "PASS " \r
- : "UNKNWN",\r
- command->context->command_line, \r
- command->context->pos);\r
- \r
- if(detail_summary_flag)\r
- command_summarize(command);\r
- }\r
- \r
- printf(" =====================================================================%s\n",\r
- number_of_failed_tests ? "== FAILED": number_of_interrupted_tests ? "==== INTR" : "====== OK");\r
- \r
- printf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok",\r
- ((1-((double)number_of_failed_tests + (double)number_of_interrupted_tests)/(double)number_of_tests)*100.0),\r
- number_of_tests, number_of_successeded_tests);\r
- \r
- if(number_of_failed_tests > 0)\r
- printf(", %d failed", number_of_failed_tests);\r
- \r
- if(number_of_interrupted_tests > 0)\r
- printf(", %d interrupted)", number_of_interrupted_tests);\r
- \r
- printf(")\n\n");\r
- \r
- total_of_tests = number_of_tests;\r
- total_of_failed_tests = number_of_failed_tests;\r
- total_of_interrupted_tests = number_of_interrupted_tests;\r
- total_of_successeded_tests = number_of_successeded_tests;\r
- }\r
- \r
- \r
- \r
- /* includes */\r
- total_of_failed_units = total_of_interrupted_units = total_of_successeded_units = 0;\r
- number_of_failed_units = number_of_successeded_units = number_of_interrupted_units = 0;\r
- number_of_units = xbt_dynar_length(unit->includes);\r
- \r
- xbt_dynar_foreach(unit->includes, itu, include)\r
- {\r
- \r
- number_of_interrupted_tests = number_of_failed_tests = number_of_successeded_tests = 0;\r
- \r
- number_of_tests = xbt_dynar_length(include->commands);\r
-\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- if(command->status == cs_interrupted)\r
- number_of_interrupted_tests++;\r
- else if(command->status == cs_failed)\r
- number_of_failed_tests++;\r
- else if(command->status == cs_successeded)\r
- number_of_successeded_tests++; \r
- }\r
- \r
- asprintf(&p," Unit: %s ............................................................................", include->description && strlen(include->description) < 60 ? include->description : include->fstream->name);\r
- \r
- p[70] = '\0';\r
- printf("%s", p);\r
- free(p); \r
- \r
- if(number_of_failed_tests > 0) \r
- {\r
- total_of_failed_units++;\r
- printf(".. failed\n");\r
- }\r
- else if(number_of_interrupted_tests > 0) \r
- {\r
- total_of_interrupted_units++;\r
- printf("interrupt\n");\r
- }\r
- else \r
- {\r
- total_of_successeded_units++;\r
- printf(".... ..ok\n"); \r
- }\r
- \r
- if(detail_summary_flag)\r
- { \r
-\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- printf(" %s: %s [%s]\n", \r
- command->status == cs_interrupted ? "INTR " \r
- : command->status == cs_failed ? "FAILED" \r
- : command->status == cs_successeded ? "PASS " \r
- : "UNKNWN",\r
- command->context->command_line, \r
- command->context->pos);\r
- \r
- command_summarize(command);\r
- }\r
- \r
- \r
- }\r
- \r
- printf(" =====================================================================%s\n",\r
- number_of_failed_tests ? "== FAILED": number_of_interrupted_tests ? "==== INTR" : "====== OK");\r
- \r
- \r
- printf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok",\r
- (number_of_tests ? (1-((double)number_of_failed_tests + (double)number_of_interrupted_tests)/(double)number_of_tests)*100.0 : 100.0),\r
- number_of_tests, number_of_successeded_tests);\r
- \r
- if(number_of_failed_tests > 0)\r
- printf(", %d failed", number_of_failed_tests);\r
- \r
- if(number_of_interrupted_tests > 0)\r
- printf(", %d interrupted)", number_of_interrupted_tests);\r
- \r
- printf(")\n\n"); \r
- \r
- \r
- total_of_tests += number_of_tests;\r
- total_of_failed_tests += number_of_failed_tests;\r
- total_of_interrupted_tests += number_of_interrupted_tests;\r
- total_of_successeded_tests += number_of_successeded_tests;\r
- }\r
- \r
- /* suites */\r
- total_of_units = number_of_units;\r
- \r
- total_of_failed_suites = total_of_successeded_suites = total_of_interrupted_suites = 0;\r
- \r
- total_of_suites = xbt_dynar_length(unit->suites);\r
-\r
- xbt_dynar_foreach(unit->suites, its, suite)\r
- {\r
- print_title(suite->description);\r
- \r
- number_of_tests_of_suite = number_of_interrupted_tests_of_suite = number_of_failed_tests_of_suite = number_of_successeded_tests_of_suite = 0;\r
- \r
- number_of_interrupted_units = number_of_failed_units = number_of_successeded_units = 0;\r
- \r
- number_of_units = xbt_dynar_length(suite->includes);\r
- \r
- xbt_dynar_foreach(suite->includes, itu, include)\r
- {\r
- number_of_interrupted_tests = number_of_failed_tests = number_of_successeded_tests = 0;\r
- \r
- number_of_tests = xbt_dynar_length(include->commands);\r
- \r
- \r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- if(command->status == cs_interrupted)\r
- number_of_interrupted_tests++;\r
- else if(command->status == cs_failed)\r
- number_of_failed_tests++;\r
- else if(command->status == cs_successeded)\r
- number_of_successeded_tests++;\r
- }\r
- \r
- asprintf(&p," Unit: %s ............................................................................", include->description && strlen(include->description) < 60 ? include->description : include->fstream->name);\r
- \r
- p[70] = '\0';\r
- printf("%s", p);\r
- free(p); \r
- \r
- if(number_of_failed_tests > 0) \r
- {\r
- number_of_failed_units++;\r
- printf(".. failed\n");\r
- }\r
- else if(number_of_interrupted_tests > 0) \r
- {\r
- number_of_interrupted_units++;\r
- printf("interrupt\n");\r
- }\r
- else \r
- {\r
- number_of_successeded_units++;\r
- printf(".... ..ok\n"); \r
- } \r
- \r
- number_of_interrupted_tests_of_suite += number_of_interrupted_tests;\r
- number_of_failed_tests_of_suite += number_of_failed_tests;\r
- number_of_successeded_tests_of_suite += number_of_successeded_tests;\r
- \r
- number_of_tests_of_suite += number_of_tests;\r
- \r
- total_of_tests += number_of_tests;\r
- total_of_failed_tests += number_of_failed_tests;\r
- total_of_interrupted_tests += number_of_interrupted_tests;\r
- total_of_successeded_tests += number_of_successeded_tests;\r
- \r
- if(detail_summary_flag)\r
- {\r
-\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- printf(" %s: %s [%s]\n", \r
- command->status == cs_interrupted ? "INTR " \r
- : command->status == cs_failed ? "FAILED" \r
- : command->status == cs_successeded ? "PASS " \r
- : "UNKNWN",\r
- command->context->command_line, \r
- command->context->pos);\r
- \r
- command_summarize(command);\r
- }\r
- \r
- \r
- }\r
- \r
- }\r
- \r
- printf(" =====================================================================%s\n",\r
- number_of_failed_tests_of_suite ? "== FAILED": number_of_interrupted_tests_of_suite ? "==== INTR" : "====== OK");\r
- \r
- if(number_of_failed_tests_of_suite > 0)\r
- total_of_failed_suites++;\r
- else if(number_of_interrupted_tests_of_suite)\r
- total_of_interrupted_suites++;\r
- else\r
- total_of_successeded_suites++;\r
- \r
- total_of_failed_units += number_of_failed_units;\r
- total_of_interrupted_units += number_of_interrupted_units;\r
- total_of_successeded_units += number_of_successeded_units;\r
- \r
- total_of_units += number_of_units;\r
- \r
- printf(" Summary: Unit(s): %.0f%% ok (%d unit(s): %d ok",\r
- (number_of_units ? (1-((double)number_of_failed_units + (double)number_of_interrupted_units)/(double)number_of_units)*100.0 : 100.0),\r
- number_of_units, number_of_successeded_units);\r
- \r
- if(number_of_failed_units > 0)\r
- printf(", %d failed", number_of_failed_units);\r
- \r
- if(number_of_interrupted_units > 0)\r
- printf(", %d interrupted)", number_of_interrupted_units);\r
- \r
- printf(")\n"); \r
- \r
- printf(" Test(s): %.0f%% ok (%d test(s): %d ok",\r
- (number_of_tests_of_suite ? (1-((double)number_of_failed_tests_of_suite + (double)number_of_interrupted_tests_of_suite)/(double)number_of_tests_of_suite)*100.0 : 100.0),\r
- number_of_tests_of_suite, number_of_successeded_tests_of_suite);\r
- \r
- if(number_of_failed_tests_of_suite > 0)\r
- printf(", %d failed", number_of_failed_tests_of_suite);\r
- \r
- if(number_of_interrupted_tests_of_suite > 0)\r
- printf(", %d interrupted)", number_of_interrupted_tests_of_suite);\r
- \r
- printf(")\n\n"); \r
- }\r
- \r
- printf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok",\r
- (total_of_suites ? (1-((double)total_of_failed_suites + (double)total_of_interrupted_suites)/(double)total_of_suites)*100.0 : 100.0),\r
- total_of_suites, total_of_successeded_suites);\r
- \r
- if(total_of_failed_suites > 0)\r
- printf(", %d failed", total_of_failed_suites);\r
- \r
- if(total_of_interrupted_suites > 0)\r
- printf(", %d interrupted)", total_of_interrupted_suites);\r
- \r
- printf(")\n"); \r
- \r
- printf(" Unit(s): %.0f%% ok (%d unit(s): %d ok",\r
- (total_of_units ? (1-((double)total_of_failed_units + (double)total_of_interrupted_units)/(double)total_of_units)*100.0 : 100.0),\r
- total_of_units, total_of_successeded_units);\r
- \r
- if(total_of_failed_units > 0)\r
- printf(", %d failed", total_of_failed_units);\r
- \r
- if(total_of_interrupted_units > 0)\r
- printf(", %d interrupted)", total_of_interrupted_units);\r
- \r
- printf(")\n");\r
- \r
- printf(" Test(s): %.0f%% ok (%d test(s): %d ok",\r
- (total_of_tests ? (1-((double)total_of_failed_tests + (double)total_of_interrupted_tests)/(double)total_of_tests)*100.0 : 100.0),\r
- total_of_tests, total_of_successeded_tests); \r
- \r
- if(total_of_failed_tests > 0)\r
- printf(", %d failed", total_of_failed_tests);\r
- \r
- if(total_of_interrupted_tests > 0)\r
- printf(", %d interrupted)", total_of_interrupted_tests);\r
- \r
- printf(")\n\n");\r
- \r
- if(unit->interrupted)\r
- unit->runner->total_of_interrupted_units++;\r
- else if(total_of_failed_tests > 0)\r
- unit->runner->total_of_failed_units++;\r
- else\r
- unit->runner->total_of_successeded_units++;\r
- \r
- unit->runner->total_of_tests += total_of_tests;\r
- unit->runner->total_of_failed_tests += total_of_failed_tests;\r
- unit->runner->total_of_successeded_tests += total_of_successeded_tests;\r
- unit->runner->total_of_interrupted_tests += total_of_interrupted_tests;\r
- \r
- unit->runner->total_of_units += total_of_units + 1;\r
- unit->runner->total_of_successeded_units += total_of_successeded_units;\r
- unit->runner->total_of_failed_units += total_of_failed_units;\r
- unit->runner->total_of_interrupted_units += total_of_interrupted_units;\r
- \r
- unit->runner->total_of_suites += total_of_suites;\r
- unit->runner->total_of_successeded_suites += total_of_successeded_suites;\r
- unit->runner->total_of_failed_suites += total_of_failed_suites;\r
- unit->runner->total_of_interrupted_suites += total_of_interrupted_suites;\r
- \r
- return 0;\r
-}\r
-\r
-int\r
-unit_reset(unit_t unit)\r
-{\r
- unit_t cur;\r
- unsigned int i;\r
-\r
- /* reset all the suites of the unit */\r
- xbt_dynar_foreach(unit->suites, i, cur)\r
- {\r
- unit_reset(cur);\r
- }\r
-\r
-\r
- /* reset all the includes of the unit */\r
- xbt_dynar_foreach(unit->includes, i, cur)\r
- {\r
- unit_reset(cur);\r
- }\r
-\r
- fseek(unit->fstream->stream,0L, SEEK_SET);\r
- unit->parsed = 0;\r
- unit->cmd_nb = 0;\r
- unit->started_cmd_nb = 0;\r
- unit->interrupted_cmd_nb = 0;\r
- unit->failed_cmd_nb = 0;\r
- unit->successeded_cmd_nb = 0;\r
- unit->terminated_cmd_nb = 0;\r
- unit->waiting_cmd_nb = 0;\r
- unit->interrupted = 0;\r
- unit->failed = 0;\r
- unit->successeded = 0;\r
- unit->parsed = 0;\r
- unit->released = 0;\r
- unit->is_running_suite = 0;\r
- \r
- if(unit->description)\r
- {\r
- free(unit->description);\r
- unit->description = NULL;\r
- }\r
+ else if (root->exit_code)
+ \rERROR3("Test unit `%s': NOK (<%s> %s)", root->fstream->name,
+ root->err_line, error_to_string(root->exit_code,
+ root->err_kind));
+ \r}
+ \r\r
+ /* if it's the last unit, release the runner */ \r
+ if ((root->runner->number_of_runned_units ==
+ root->runner->number_of_ended_units))
+ \r {
+ \r
+ /* if all the commands of the unit are successeded itc's a successeded unit */ \r
+ if (root->successeded_cmd_nb == root->cmd_nb
+ && !root->
+ exit_code /* case of only one cd : nb = successeded = 0) */ )
+ \rroot->successeded = 1;
+ \r\r
+ /* first release the mutex */ \r
+ xbt_os_mutex_release(root->mutex);
+ \r\r
+ /* release the runner */ \r
+ xbt_os_sem_release(units_sem);
+ \r}
+ \r
+ else
+ \rxbt_os_mutex_release(root->mutex);
+ \r\r
+ /* release the jobs semaphore, then the next waiting unit can start */ \r
+ xbt_os_sem_release(jobs_sem);
+ \r\rreturn NULL;
+\r\r}
+
+\r\r\runit_t \r
+unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream) \r
+{
+ \runit_t unit;
+ \r\runit = xbt_new0(s_unit_t, 1);
+ \r\r
+ /* instantiate the vector used to store all the commands of the unit */ \r
+ unit->commands =
+ xbt_dynar_new(sizeof(command_t), (void_f_pvoid_t) command_free);
+ \r\r
+ /* instantiate the vector used to store all the included units */ \r
+ unit->includes =
+ xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t) unit_free);
+ \r\r
+ /* instantiate the vector used to store all the included suites */ \r
+ unit->suites =
+ xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t) unit_free);
+ \r\r
+ /* the runner used to launch the tesh unit */ \r
+ unit->runner = runner;
+ \r\r
+ /* the file stream object to use to parse the tesh file */ \r
+ unit->fstream = fstream;
+ \r\rif (fstream)
+ \rfstream->unit = unit;
+ \r\r
+ /* if no root parameter specified assume that itc's the root of all the units */ \r
+ unit->root = root ? root : unit;
+ \r\r
+ /* the owner of the suite */ \r
+ unit->owner = owner;
+ \r\runit->thread = NULL;
+ \runit->started_cmd_nb = 0;
+ \runit->interrupted_cmd_nb = 0;
+ \runit->failed_cmd_nb = 0;
+ \runit->successeded_cmd_nb = 0;
+ \runit->terminated_cmd_nb = 0;
+ \runit->waiting_cmd_nb = 0;
+ \runit->interrupted = 0;
+ \runit->failed = 0;
+ \runit->successeded = 0;
+ \runit->parsed = 0;
+ \runit->released = 0;
+ \runit->owner = owner;
+ \runit->is_running_suite = 0;
+ \runit->description = NULL;
+ \runit->sem = NULL;
+ \runit->exit_code = 0;
+ \runit->err_kind = 0;
+ \runit->err_line = NULL;
+ \runit->filepos = NULL;
+ \r\r\r\rreturn unit;
+\r}
+
+\r\rvoid \r
+unit_set_error(unit_t unit, int errcode, int kind, const char *line) \r
+{
+ \rif (!unit->exit_code)
+ \r {
+ \runit->exit_code = errcode;
+ \runit->err_kind = kind;
+ \runit->err_line = strdup(line);
+ \r\rif (unit->root && !unit->root->exit_code)
+ \r {
+ \runit->root->exit_code = errcode;
+ \runit->root->err_kind = kind;
+ \runit->root->err_line = strdup(line);
+ \r}
+ \r\rif (!exit_code)
+ \r {
+ \r\rexit_code = errcode;
+ \rerr_kind = kind;
+ \rerr_line = strdup(line);
+ \r}
+ \r}
+\r\r}
+
+\r\rint \r unit_free(unit_t * ptr) \r
+{
+ \rif (!(*ptr))
+ \r {
+ \rerrno = EINVAL;
+ \rreturn -1;
+ \r}
+ \r\rif ((*ptr)->commands)
+ \rxbt_dynar_free(&((*ptr)->commands));
+ \r\rif ((*ptr)->includes)
+ \rxbt_dynar_free(&((*ptr)->includes));
+ \r\rif ((*ptr)->suites)
+ \rxbt_dynar_free(&((*ptr)->suites));
+ \r\r
+ /* if the unit is interrupted during its run, the semaphore is NULL */ \r
+ if ((*ptr)->sem)
+ \rxbt_os_sem_destroy((*ptr)->sem);
+ \r\rif ((*ptr)->description)
+ \rfree((*ptr)->description);
+ \r\rif ((*ptr)->err_line)
+ \rfree((*ptr)->err_line);
+ \r\rif ((*ptr)->filepos)
+ \rfree((*ptr)->filepos);
+ \r\rfree(*ptr);
+ \r*ptr = NULL;
+ \r\rreturn 0;
+\r}
+
+\r\rint \r unit_run(unit_t unit, xbt_os_mutex_t mutex) \r
+{
+ \r
+ /* check the parameters */ \r
+ if (!(unit) || !mutex)
+ \r {
+ \rerrno = EINVAL;
+ \rxbt_os_sem_release(jobs_sem);
+ \rreturn -1;
+ \r\r}
+ \r\rif (!interrupted)
+ \r {
+ \runit->mutex = mutex;
+ \r\runit->sem = xbt_os_sem_init(0);
+ \r\r
+ /* start the unit */ \r
+ unit->thread = xbt_os_thread_create("", unit_start, unit);
+ \r}
+ \r
+ else
+ \r {
+ \r
+ /* the unit is interrupted by the runner before its starting \r
+ * in this case the unit semaphore is NULL take care of that\r
+ * in the function unit_free()\r
+ */ \r
+ unit->interrupted = 1;
+ \rxbt_os_sem_release(jobs_sem);
+ \r}
+ \r\rreturn 0;
+\r\r}
+
+\r\rint \r unit_interrupt(unit_t unit) \r
+{
+ \r
+ /* check the parameter */ \r
+ if (!(unit))
+ \r {
+ \rerrno = EINVAL;
+ \rreturn -1;
+ \r}
+ \r\r
+ /* if the unit is already interrupted, signal the error */ \r
+ if (unit->interrupted)
+ \r {
+ \rerrno = EALREADY;
+ \rreturn -1;
+ \r}
+ \r\r
+ /* interrupt the run of the specified unit */ \r
+ unit->interrupted = 1;
+ \rxbt_os_sem_release(unit->sem);
+ \r\rreturn 0;
+\r}
+
+\r\r
+/* just print the title of the root unit or a suite (if any) */ \r
+static void \r print_title(const char *description) \r
+{
+ \rregister int i;
+ \rchar title[80];
+ \rsize_t len = strlen(description);
+ \r\rtitle[0] = ' ';
+ \r\rfor (i = 1; i < 79; i++)
+ \rtitle[i] = '=';
+ \r\rtitle[i++] = '\n';
+ \rtitle[79] = '\0';
+ \r\rsprintf(title + 40 - (len + 4) / 2, "[ %s ]", description);
+ \rtitle[40 + (len + 5) / 2] = '=';
+ \r\rprintf("\n%s\n", title);
+\r}
+
+\r\rint \r unit_summuarize(unit_t unit) \r
+{
+ \rcommand_t command;
+ \runsigned int itc, itu, its;
+ \runit_t include;
+ \runit_t suite;
+ \rchar *p;
+ \rchar title[PATH_MAX + 1] = { 0 };
+ \r\rint number_of_tests = 0; /* number of tests of a unit contained by this unit */
+ \rint number_of_failed_tests = 0; /* number of failed test of a unit contained by this unit */
+ \rint number_of_successeded_tests = 0; /* number of successeded tests of a unit contained by this unit */
+ \rint number_of_interrupted_tests = 0; /* number of interrupted tests of a unit contained by this unit */
+ \r\rint number_of_tests_of_suite = 0; /* number of tests of a suite contained by this unit */
+ \rint number_of_interrupted_tests_of_suite = 0; /* number of interrupted tests of a suite contained by this unit */
+ \rint number_of_failed_tests_of_suite = 0; /* number of failed tests of a suite contained by this unit */
+ \rint number_of_successeded_tests_of_suite = 0; /* number of successeded tests of a suite contained by this */
+ \r\rint number_of_units = 0; /* number of units contained by a suite */
+ \rint number_of_failed_units = 0; /* number of failed units contained by a suite */
+ \rint number_of_successeded_units = 0; /* number of successeded units contained by a suite */
+ \rint number_of_interrupted_units = 0; /* number of interrupted units contained by a suite */
+ \r\rint total_of_tests = 0; /* total of the tests contained by this unit */
+ \rint total_of_failed_tests = 0; /* total of failed tests contained by this unit */
+ \rint total_of_successeded_tests = 0; /* total of successeded tests contained by this unit */
+ \rint total_of_interrupted_tests = 0; /* total of interrupted tests contained by this unit */
+ \r\rint total_of_units = 0; /* total of units contained by this unit */
+ \rint total_of_failed_units = 0; /* total of failed units contained by this unit */
+ \rint total_of_successeded_units = 0; /* total of successeded units contained by this unit */
+ \rint total_of_interrupted_units = 0; /* total of interrutped units contained by this unit */
+ \r\rint total_of_suites = 0; /* total of suites contained by this unit */
+ \rint total_of_failed_suites = 0; /* total of failed suites contained by this unit */
+ \rint total_of_successeded_suites = 0; /* total of successeded suites contained by this unit */
+ \rint total_of_interrupted_suites = 0; /* total of interrupted suites contained by this unit */
+ \r\r
+ /* check the parameter */ \r
+ if (!(unit))
+ \r {
+ \rerrno = EINVAL;
+ \rreturn -1;
+ \r}
+ \r\rif ((unit->description) && strlen(unit->description) < 76)
+ \rstrcpy(title, unit->description);
+ \r
+ else
+ \rsprintf(title, "file : %s", unit->fstream->name);
+ \r\rif (unit->interrupted)
+ \r {
+ \rif (strlen(title) + strlen(" (interrupted)") < 76)
+ \rstrcat(title, " (interrupted)");
+ \r
+ else
+ \r {
+ \rmemset(title, 0, PATH_MAX + 1);
+ \rsprintf(title, "file : %s", unit->fstream->name);
+ \rstrcat(title, " (interrupted)");
+ \r\r}
+ \r}
+ \r\rprint_title(title);
+ \r\rnumber_of_tests = xbt_dynar_length(unit->commands);
+ \r\r
+ /* tests */ \r
+ xbt_dynar_foreach(unit->commands, itc, command) \r {
+ \rif (command->status == cs_interrupted)
+ \rnumber_of_interrupted_tests++;
+ \r
+ else if (command->status == cs_failed)
+ \rnumber_of_failed_tests++;
+ \r
+ else if (command->status == cs_successeded)
+ \rnumber_of_successeded_tests++;
+ \r}
+ \r\r\rif (number_of_tests)
+ \r {
+ \rasprintf(&p,
+ " Test(s): .........................................................................");
+ \r\rp[70] = '\0';
+ \rprintf("%s", p);
+ \rfree(p);
+ \r\rif (number_of_failed_tests > 0)
+ \rprintf(".. failed\n");
+ \r
+ else if (number_of_interrupted_tests > 0)
+ \rprintf("interrupt\n");
+ \r
+ else
+ \rprintf(".... ..ok\n");
+ \r\rxbt_dynar_foreach(unit->commands, itc, command) \r {
+ \rprintf(" %s: %s [%s]\n",
+ \rcommand->status ==
+ cs_interrupted ? "INTR " \r : command->status ==
+ cs_failed ? "FAILED" \r : command->status ==
+ cs_successeded ? "PASS " \r : "UNKNWN",
+ \rcommand->context->command_line, \rcommand->context->pos);
+ \r\rif (detail_summary_flag)
+ \rcommand_summarize(command);
+ \r}
+ \r\rprintf
+ (" =====================================================================%s\n",
+ \rnumber_of_failed_tests ? "== FAILED" :
+ number_of_interrupted_tests ? "==== INTR" : "====== OK");
+ \r\rprintf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok",
+ \r((1 -
+ ((double) number_of_failed_tests +
+ (double) number_of_interrupted_tests) /
+ (double) number_of_tests) * 100.0), \rnumber_of_tests,
+ number_of_successeded_tests);
+ \r\rif (number_of_failed_tests > 0)
+ \rprintf(", %d failed", number_of_failed_tests);
+ \r\rif (number_of_interrupted_tests > 0)
+ \rprintf(", %d interrupted)", number_of_interrupted_tests);
+ \r\rprintf(")\n\n");
+ \r\rtotal_of_tests = number_of_tests;
+ \rtotal_of_failed_tests = number_of_failed_tests;
+ \rtotal_of_interrupted_tests = number_of_interrupted_tests;
+ \rtotal_of_successeded_tests = number_of_successeded_tests;
+ \r}
+ \r\r\r\r
+ /* includes */ \r
+ total_of_failed_units = total_of_interrupted_units =
+ total_of_successeded_units = 0;
+ \rnumber_of_failed_units = number_of_successeded_units =
+ number_of_interrupted_units = 0;
+ \rnumber_of_units = xbt_dynar_length(unit->includes);
+ \r\rxbt_dynar_foreach(unit->includes, itu, include) \r {
+ \r\rnumber_of_interrupted_tests = number_of_failed_tests =
+ number_of_successeded_tests = 0;
+ \r\rnumber_of_tests = xbt_dynar_length(include->commands);
+ \r\rxbt_dynar_foreach(include->commands, itc, command) \r {
+ \rif (command->status == cs_interrupted)
+ \rnumber_of_interrupted_tests++;
+ \r
+ else if (command->status == cs_failed)
+ \rnumber_of_failed_tests++;
+ \r
+ else if (command->status == cs_successeded)
+ \rnumber_of_successeded_tests++;
+ \r}
+ \r\rasprintf(&p,
+ " Unit: %s ............................................................................",
+ include->description
+ && strlen(include->description) <
+ 60 ? include->description : include->fstream->name);
+ \r\rp[70] = '\0';
+ \rprintf("%s", p);
+ \rfree(p);
+ \r\rif (number_of_failed_tests > 0)
+ \r {
+ \rtotal_of_failed_units++;
+ \rprintf(".. failed\n");
+ \r}
+ \r
+ else if (number_of_interrupted_tests > 0)
+ \r {
+ \rtotal_of_interrupted_units++;
+ \rprintf("interrupt\n");
+ \r}
+ \r
+ else
+ \r {
+ \rtotal_of_successeded_units++;
+ \rprintf(".... ..ok\n");
+ \r}
+ \r\rif (detail_summary_flag)
+ \r {
+ \r\rxbt_dynar_foreach(include->commands, itc, command) \r {
+ \rprintf(" %s: %s [%s]\n",
+ \rcommand->status ==
+ cs_interrupted ? "INTR " \r : command->status ==
+ cs_failed ? "FAILED" \r : command->status ==
+ cs_successeded ? "PASS " \r : "UNKNWN",
+ \rcommand->context->command_line, \rcommand->context->pos);
+ \r\rcommand_summarize(command);
+ \r}
+ \r\r\r}
+ \r\rprintf
+ (" =====================================================================%s\n",
+ \rnumber_of_failed_tests ? "== FAILED" :
+ number_of_interrupted_tests ? "==== INTR" : "====== OK");
+ \r\r\rprintf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok",
+ \r(number_of_tests
+ ? (1 -
+ ((double) number_of_failed_tests +
+ (double) number_of_interrupted_tests) /
+ (double) number_of_tests) * 100.0 : 100.0),
+ \rnumber_of_tests, number_of_successeded_tests);
+ \r\rif (number_of_failed_tests > 0)
+ \rprintf(", %d failed", number_of_failed_tests);
+ \r\rif (number_of_interrupted_tests > 0)
+ \rprintf(", %d interrupted)", number_of_interrupted_tests);
+ \r\rprintf(")\n\n");
+ \r\r\rtotal_of_tests += number_of_tests;
+ \rtotal_of_failed_tests += number_of_failed_tests;
+ \rtotal_of_interrupted_tests += number_of_interrupted_tests;
+ \rtotal_of_successeded_tests += number_of_successeded_tests;
+ \r}
+ \r\r
+ /* suites */ \r
+ total_of_units = number_of_units;
+ \r\rtotal_of_failed_suites = total_of_successeded_suites =
+ total_of_interrupted_suites = 0;
+ \r\rtotal_of_suites = xbt_dynar_length(unit->suites);
+ \r\rxbt_dynar_foreach(unit->suites, its, suite) \r {
+ \rprint_title(suite->description);
+ \r\rnumber_of_tests_of_suite = number_of_interrupted_tests_of_suite =
+ number_of_failed_tests_of_suite =
+ number_of_successeded_tests_of_suite = 0;
+ \r\rnumber_of_interrupted_units = number_of_failed_units =
+ number_of_successeded_units = 0;
+ \r\rnumber_of_units = xbt_dynar_length(suite->includes);
+ \r\rxbt_dynar_foreach(suite->includes, itu, include) \r {
+ \rnumber_of_interrupted_tests = number_of_failed_tests =
+ number_of_successeded_tests = 0;
+ \r\rnumber_of_tests = xbt_dynar_length(include->commands);
+ \r\r\rxbt_dynar_foreach(include->commands, itc, command) \r {
+ \rif (command->status == cs_interrupted)
+ \rnumber_of_interrupted_tests++;
+ \r
+ else if (command->status == cs_failed)
+ \rnumber_of_failed_tests++;
+ \r
+ else if (command->status == cs_successeded)
+ \rnumber_of_successeded_tests++;
+ \r}
+ \r\rasprintf(&p,
+ " Unit: %s ............................................................................",
+ include->description
+ && strlen(include->description) <
+ 60 ? include->description : include->fstream->name);
+ \r\rp[70] = '\0';
+ \rprintf("%s", p);
+ \rfree(p);
+ \r\rif (number_of_failed_tests > 0)
+ \r {
+ \rnumber_of_failed_units++;
+ \rprintf(".. failed\n");
+ \r}
+ \r
+ else if (number_of_interrupted_tests > 0)
+ \r {
+ \rnumber_of_interrupted_units++;
+ \rprintf("interrupt\n");
+ \r}
+ \r
+ else
+ \r {
+ \rnumber_of_successeded_units++;
+ \rprintf(".... ..ok\n");
+ \r}
+ \r\rnumber_of_interrupted_tests_of_suite +=
+ number_of_interrupted_tests;
+ \rnumber_of_failed_tests_of_suite += number_of_failed_tests;
+ \rnumber_of_successeded_tests_of_suite += number_of_successeded_tests;
+ \r\rnumber_of_tests_of_suite += number_of_tests;
+ \r\rtotal_of_tests += number_of_tests;
+ \rtotal_of_failed_tests += number_of_failed_tests;
+ \rtotal_of_interrupted_tests += number_of_interrupted_tests;
+ \rtotal_of_successeded_tests += number_of_successeded_tests;
+ \r\rif (detail_summary_flag)
+ \r {
+ \r\rxbt_dynar_foreach(include->commands, itc, command) \r {
+ \rprintf(" %s: %s [%s]\n",
+ \rcommand->status ==
+ cs_interrupted ? "INTR " \r : command->status ==
+ cs_failed ? "FAILED" \r : command->status ==
+ cs_successeded ? "PASS " \r : "UNKNWN",
+ \rcommand->context->command_line, \rcommand->context->pos);
+ \r\rcommand_summarize(command);
+ \r}
+ \r\r\r}
+ \r\r}
+ \r\rprintf
+ (" =====================================================================%s\n",
+ \rnumber_of_failed_tests_of_suite ? "== FAILED" :
+ number_of_interrupted_tests_of_suite ? "==== INTR" : "====== OK");
+ \r\rif (number_of_failed_tests_of_suite > 0)
+ \rtotal_of_failed_suites++;
+ \r
+ else if (number_of_interrupted_tests_of_suite)
+ \rtotal_of_interrupted_suites++;
+ \r
+ else
+ \rtotal_of_successeded_suites++;
+ \r\rtotal_of_failed_units += number_of_failed_units;
+ \rtotal_of_interrupted_units += number_of_interrupted_units;
+ \rtotal_of_successeded_units += number_of_successeded_units;
+ \r\rtotal_of_units += number_of_units;
+ \r\rprintf(" Summary: Unit(s): %.0f%% ok (%d unit(s): %d ok", \r
+ (number_of_units
+ ? (1 -
+ ((double) number_of_failed_units +
+ (double) number_of_interrupted_units) /
+ (double) number_of_units) * 100.0 : 100.0),
+ \rnumber_of_units, number_of_successeded_units);
+ \r\rif (number_of_failed_units > 0)
+ \rprintf(", %d failed", number_of_failed_units);
+ \r\rif (number_of_interrupted_units > 0)
+ \rprintf(", %d interrupted)", number_of_interrupted_units);
+ \r\rprintf(")\n");
+ \r\rprintf(" Test(s): %.0f%% ok (%d test(s): %d ok", \r
+ (number_of_tests_of_suite
+ ? (1 -
+ ((double) number_of_failed_tests_of_suite +
+ (double) number_of_interrupted_tests_of_suite) /
+ (double) number_of_tests_of_suite) * 100.0 : 100.0),
+ \rnumber_of_tests_of_suite,
+ number_of_successeded_tests_of_suite);
+ \r\rif (number_of_failed_tests_of_suite > 0)
+ \rprintf(", %d failed", number_of_failed_tests_of_suite);
+ \r\rif (number_of_interrupted_tests_of_suite > 0)
+ \rprintf(", %d interrupted)", number_of_interrupted_tests_of_suite);
+ \r\rprintf(")\n\n");
+ \r}
+ \r\rprintf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok", \r
+ (total_of_suites
+ ? (1 -
+ ((double) total_of_failed_suites +
+ (double) total_of_interrupted_suites) /
+ (double) total_of_suites) * 100.0 : 100.0),
+ \rtotal_of_suites, total_of_successeded_suites);
+ \r\rif (total_of_failed_suites > 0)
+ \rprintf(", %d failed", total_of_failed_suites);
+ \r\rif (total_of_interrupted_suites > 0)
+ \rprintf(", %d interrupted)", total_of_interrupted_suites);
+ \r\rprintf(")\n");
+ \r\rprintf(" Unit(s): %.0f%% ok (%d unit(s): %d ok", \r
+ (total_of_units
+ ? (1 -
+ ((double) total_of_failed_units +
+ (double) total_of_interrupted_units) /
+ (double) total_of_units) * 100.0 : 100.0), \rtotal_of_units,
+ total_of_successeded_units);
+ \r\rif (total_of_failed_units > 0)
+ \rprintf(", %d failed", total_of_failed_units);
+ \r\rif (total_of_interrupted_units > 0)
+ \rprintf(", %d interrupted)", total_of_interrupted_units);
+ \r\rprintf(")\n");
+ \r\rprintf(" Test(s): %.0f%% ok (%d test(s): %d ok", \r
+ (total_of_tests
+ ? (1 -
+ ((double) total_of_failed_tests +
+ (double) total_of_interrupted_tests) /
+ (double) total_of_tests) * 100.0 : 100.0), \rtotal_of_tests,
+ total_of_successeded_tests);
+ \r\rif (total_of_failed_tests > 0)
+ \rprintf(", %d failed", total_of_failed_tests);
+ \r\rif (total_of_interrupted_tests > 0)
+ \rprintf(", %d interrupted)", total_of_interrupted_tests);
+ \r\rprintf(")\n\n");
+ \r\rif (unit->interrupted)
+ \runit->runner->total_of_interrupted_units++;
+ \r
+ else if (total_of_failed_tests > 0)
+ \runit->runner->total_of_failed_units++;
+ \r
+ else
+ \runit->runner->total_of_successeded_units++;
+ \r\runit->runner->total_of_tests += total_of_tests;
+ \runit->runner->total_of_failed_tests += total_of_failed_tests;
+ \runit->runner->total_of_successeded_tests += total_of_successeded_tests;
+ \runit->runner->total_of_interrupted_tests += total_of_interrupted_tests;
+ \r\runit->runner->total_of_units += total_of_units + 1;
+ \runit->runner->total_of_successeded_units += total_of_successeded_units;
+ \runit->runner->total_of_failed_units += total_of_failed_units;
+ \runit->runner->total_of_interrupted_units += total_of_interrupted_units;
+ \r\runit->runner->total_of_suites += total_of_suites;
+ \runit->runner->total_of_successeded_suites +=
+ total_of_successeded_suites;
+ \runit->runner->total_of_failed_suites += total_of_failed_suites;
+ \runit->runner->total_of_interrupted_suites +=
+ total_of_interrupted_suites;
+ \r\rreturn 0;
+\r}
+
+\r\rint \r unit_reset(unit_t unit) \r
+{
+ \runit_t cur;
+ \runsigned int i;
+ \r\r
+ /* reset all the suites of the unit */ \r
+ xbt_dynar_foreach(unit->suites, i, cur) \r {
+ \runit_reset(cur);
+ \r} \r\r\r
+ /* reset all the includes of the unit */ \r
+ xbt_dynar_foreach(unit->includes, i, cur) \r {
+ \runit_reset(cur);
+ \r} \r\rfseek(unit->fstream->stream, 0L, SEEK_SET);
+ \runit->parsed = 0;
+ \runit->cmd_nb = 0;
+ \runit->started_cmd_nb = 0;
+ \runit->interrupted_cmd_nb = 0;
+ \runit->failed_cmd_nb = 0;
+ \runit->successeded_cmd_nb = 0;
+ \runit->terminated_cmd_nb = 0;
+ \runit->waiting_cmd_nb = 0;
+ \runit->interrupted = 0;
+ \runit->failed = 0;
+ \runit->successeded = 0;
+ \runit->parsed = 0;
+ \runit->released = 0;
+ \runit->is_running_suite = 0;
+ \r\rif (unit->description)
+ \r {
+ \rfree(unit->description);
+ \runit->description = NULL;
+ \r}
+ \r\runit->exit_code = 0;
+ \r\rreturn 0;
+\r}
+