+++ /dev/null
-/*\r
- * src/unit.c - type representing the tesh unit concept.\r
- *\r
- * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved. \r
- *\r
- * This program is free software; you can redistribute it and/or modify it \r
- * under the terms of the license (GNU LGPL) which comes with this package.\r
- *\r
- * Purpose:\r
- * This file contains all the definitions of the functions related with\r
- * the tesh unit concept.\r
- *\r
- */\r
- \r
-#include <unit.h>\r
-#include <command.h>\r
-#include <context.h>\r
-#include <fstream.h>\r
-#include <variable.h>\r
-#include <str_replace.h>\r
-#include <xerrno.h>\r
-\r
-\r
-\r
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);\r
-\r
-/*! \brief unit_start - start the processing of the tesh file representing by the unit\r
- *\r
- * \param p A void pointer to the unit representing the tesh file to process.\r
- *\r
- * \return This function (thread routine always returns NULL)\r
- *\r
- * Scenario :\r
- * \r
- * 1) The unit increment the number of running unit of the runner.\r
- * 2) The unit wait for the jobs semaphore to realy start its job.\r
- * 3) The unit runs the parsing of its tesh file using an fstream object.\r
- * 3.1) The fstream object parse the tesh file an launch each command with its context of execution.\r
- * 3.2) If a syntax error is detected the fstream object handle the failure and signals it by setting\r
- * the flag interrupted of the unit to one (depending of the keep-going and keep-going-unit flag values)\r
- * 3.3) If a command failed (exit code do not match, timeout, ouptupt different from the expected..)\r
- * the command handle the failure (see command_handle_failure() for more details).\r
- * 4) After the parsing of the tesh file.\r
- * 4.1) If all commands are successeded the last command release the unit by releasing its semaphore. \r
- * 4.2) If a command failed or if the tesh file is malformated the unit interrupt all the commands in progress.\r
- * 5) The unit wait for the end of all the threads associated with a command.\r
- * 6) Its release the next waiting unit (if any) by releasing the jobs semaphore.\r
- * 7) If its the last unit, it release the runner by releasing the semaphore used to wait for the end of all the units.\r
- * \r
- */\r
-static void*\r
-unit_start(void* p) \r
-{\r
- xbt_os_thread_t thread;\r
- xbt_os_mutex_t mutex;\r
- unit_t include, suite;\r
- unsigned int itc, itu, its;\r
- int include_nb, suite_nb;\r
- command_t command;\r
- \r
- unit_t root = (unit_t)p;\r
- \r
- /* increment the number of running units */\r
- xbt_os_mutex_acquire(root->mutex);\r
- root->runner->number_of_runned_units++;\r
- xbt_os_mutex_release(root->mutex);\r
-\r
- /* must acquire the jobs semaphore to start */\r
- xbt_os_sem_acquire(jobs_sem);\r
- \r
- /* initialize the mutex used to synchronize the access to the properties of this unit */\r
- mutex = xbt_os_mutex_init();\r
- \r
- if(!dry_run_flag)\r
- INFO1("Test unit from %s",root->fstream->name);\r
- else\r
- INFO1("Checking unit %s...",root->fstream->name); \r
- \r
- /* launch the parsing of the unit */\r
- fstream_parse(root->fstream, mutex);\r
- \r
- /* if the unit is not interrupted and not failed the unit, all the file is parsed\r
- * so all the command are launched\r
- */\r
- if(!root->interrupted)\r
- {\r
- root->parsed = 1;\r
- \r
- /* all the commands have terminated before the end of the parsing of the tesh file\r
- * so the unit release the semaphore itself\r
- */\r
- if(!root->released && (root->started_cmd_nb == (root->failed_cmd_nb + root->interrupted_cmd_nb + root->successeded_cmd_nb)))\r
- xbt_os_sem_release(root->sem); \r
- }\r
- \r
- /* wait the end of all the commands or a command failure or an interruption */\r
-\r
- xbt_os_sem_acquire(root->sem);\r
- \r
-\r
- if(root->interrupted)\r
- {\r
-\r
- xbt_dynar_foreach(root->commands, itc , command)\r
- {\r
- if(command->status == cs_in_progress)\r
- command_interrupt(command);\r
- }\r
-\r
- /* interrupt all the running commands of the included units */\r
- include_nb = xbt_dynar_length(root->includes);\r
- \r
- xbt_dynar_foreach(root->includes, itu, include)\r
- {\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- if(command->status == cs_in_progress)\r
- command_interrupt(command);\r
- }\r
- }\r
- \r
- /* interrupt all the running commands of the unit */\r
- suite_nb = xbt_dynar_length(root->suites);\r
- \r
- xbt_dynar_foreach(root->suites, its, suite)\r
- {\r
- include_nb = xbt_dynar_length(suite->includes);\r
-\r
- xbt_dynar_foreach(suite->includes, itu, include)\r
- {\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- if(command->status == cs_in_progress)\r
- command_interrupt(command);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /* wait the end of the command threads of the unit */\r
- xbt_dynar_foreach(root->commands, itc, command)\r
- {\r
- thread = command->thread;\r
- \r
- if(thread)\r
- xbt_os_thread_join(thread,NULL);\r
- }\r
- \r
- /* wait the end of the command threads of the included units of the unit */\r
- include_nb = xbt_dynar_length(root->includes);\r
- \r
- xbt_dynar_foreach(root->includes, itu, include)\r
- {\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- thread = command->thread;\r
- \r
- if(thread)\r
- xbt_os_thread_join(thread,NULL);\r
- }\r
-\r
- if(!dry_run_flag)\r
- {\r
- if(!include->exit_code && !include->interrupted)\r
- INFO1("Include from %s OK",include->fstream->name);\r
- else if(include->exit_code)\r
- ERROR4("Include `(%s)' NOK : (<%s> %s (%d))", include->fstream->name, command->context->line, error_to_string(include->exit_code, include->err_kind), include->exit_code);\r
- else if(include->interrupted && !include->exit_code)\r
- INFO1("Include `(%s)' INTR",include->fstream->name);\r
- }\r
- }\r
- \r
- /* interrupt all the running commands of the unit */\r
- suite_nb = xbt_dynar_length(root->suites);\r
- \r
- xbt_dynar_foreach(root->suites, its, suite)\r
- {\r
- include_nb = xbt_dynar_length(suite->includes);\r
-\r
- if(!include_nb)\r
- {\r
- if(!suite->exit_code)\r
- {\r
- unit_set_error(suite, ESYNTAX, 1);\r
- ERROR2("[%s] Empty suite `(%s)' detected (no includes added)", suite->filepos, suite->description);\r
-\r
- /* if the --keep-going option is not specified */\r
- if(!keep_going_flag)\r
- {\r
- if(!interrupted)\r
- {\r
- /* request an global interruption by the runner */\r
- interrupted = 1;\r
-\r
- /* release the runner */\r
- xbt_os_sem_release(units_sem);\r
- }\r
- }\r
- }\r
- }\r
- \r
- xbt_dynar_foreach(suite->includes, itu, include)\r
- {\r
- xbt_dynar_foreach(include->commands, itc, command)\r
- {\r
- thread = command->thread;\r
- \r
- if(thread)\r
- xbt_os_thread_join(thread,NULL);\r
- }\r
- \r
- if(!include->exit_code && !include->interrupted)\r
- {\r
- if(!dry_run_flag)\r
- INFO1("Include from %s OK",include->fstream->name);\r
- }\r
- else if(include->exit_code)\r
- {\r
- if(!dry_run_flag)\r
- ERROR3("Include `(%s)' NOK : (<%s> %s)", include->fstream->name, command->context->pos, error_to_string(include->exit_code, include->err_kind));\r
-\r
- suite->exit_code = include->exit_code;\r
- suite->err_kind = include->err_kind;\r
- }\r
- else if(include->interrupted && !include->exit_code)\r
- {\r
- if(!dry_run_flag)\r
- INFO1("Include `(%s)' INTR",include->fstream->name);\r
-\r
- suite->interrupted = 1;\r
- }\r
- \r
- }\r
- \r
- if(!dry_run_flag )\r
- {\r
- if(!suite->exit_code && !suite->interrupted)\r
- INFO1("Test suite from %s OK",suite->description);\r
- else if(suite->exit_code)\r
- ERROR3("Test suite `(%s)' NOK : (<%s> %s) ", suite->description, suite->filepos, error_to_string(suite->exit_code, suite->err_kind));\r
- else if(suite->interrupted && !suite->exit_code)\r
- INFO1("Test suite `(%s)' INTR",suite->description);\r
- }\r
- }\r
- \r
- /* you can now destroy the mutex used to synchrone the command accesses to the properties of the unit */\r
- xbt_os_mutex_destroy(mutex);\r
-\r
- /* update the number of ended units of the runner */\r
- xbt_os_mutex_acquire(root->mutex);\r
- \r
- /* increment the number of ended units */\r
- root->runner->number_of_ended_units++;\r
- \r
- if(!dry_run_flag )\r
- {\r
- if(root->interrupted && !root->exit_code)\r
- INFO1("Test unit from %s INTR",root->fstream->name);\r
- else if(!root->exit_code)\r
- INFO1("Test unit from %s OK",root->fstream->name);\r
- else if(root->exit_code)\r
- ERROR2("Test unit `(%s)' : NOK (%s)",root->fstream->name, 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)*/)\r
- root->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\r
- xbt_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
- \r
- return NULL;\r
-\r
-}\r
-\r
-\r
-unit_t\r
-unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream)\r
-{\r
- unit_t unit;\r
- \r
- unit = 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
- \r
- if(fstream)\r
- fstream->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
- \r
- unit->thread = NULL;\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->owner = owner;\r
- unit->is_running_suite = 0;\r
- unit->description = NULL;\r
- unit->sem = NULL;\r
- unit->exit_code = 0;\r
- unit->err_kind = 0;\r
- unit->filepos = NULL;\r
- \r
- \r
-\r
- return unit;\r
-}\r
-\r
-void\r
-unit_set_error(unit_t unit, int errcode, int kind)\r
-{\r
- if(!unit->exit_code)\r
- {\r
- unit->exit_code = errcode;\r
- unit->err_kind = kind;\r
-\r
- if(unit->root && !unit->root->exit_code)\r
- {\r
- unit->root->exit_code = errcode;\r
- unit->root->err_kind = kind;\r
- }\r
- \r
- if(!exit_code)\r
- {\r
- \r
- exit_code = errcode;\r
- err_kind = kind;\r
- }\r
- }\r
- \r
-}\r
-\r
-int\r
-unit_free(unit_t* ptr)\r
-{\r
- if(!(*ptr))\r
- {\r
- errno = EINVAL;\r
- return -1;\r
- }\r
- \r
- if((*ptr)->commands)\r
- xbt_dynar_free(&((*ptr)->commands));\r
- \r
- if((*ptr)->includes)\r
- xbt_dynar_free(&((*ptr)->includes));\r
- \r
- if((*ptr)->suites)\r
- xbt_dynar_free(&((*ptr)->suites));\r
- \r
- /* if the unit is interrupted during its run, the semaphore is NULL */\r
- if((*ptr)->sem)\r
- xbt_os_sem_destroy((*ptr)->sem);\r
- \r
- if((*ptr)->description)\r
- free((*ptr)->description);\r
-\r
- if((*ptr)->filepos)\r
- free((*ptr)->filepos);\r
-\r
- free(*ptr);\r
- *ptr = NULL;\r
- \r
- return 0;\r
-}\r
-\r
-int\r
-unit_run(unit_t unit, xbt_os_mutex_t mutex)\r
-{\r
- /* check the parameters */\r
- if(!(unit) || !mutex)\r
- {\r
- errno = EINVAL;\r
- return -1;\r
- }\r
- \r
- if(!interrupted)\r
- {\r
- unit->mutex = mutex;\r
- \r
- unit->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
- /* 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;\r
- \r
- return 0;\r
- \r
-}\r
-\r
-int\r
-unit_interrupt(unit_t unit)\r
-{\r
- /* check the parameter */\r
- if(!(unit))\r
- {\r
- errno = EINVAL;\r
- return -1;\r
- }\r
- \r
- /* if the unit is already interrupted, signal the error */\r
- if(unit->interrupted)\r
- {\r
- errno = EALREADY;\r
- return -1;\r
- }\r
- \r
- /* 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)\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 ? 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 ? 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
-\r
- unit->exit_code = 0;\r
- \r
- return 0;\r
-}\r