Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Last corrections of Tesh tool.
[simgrid.git] / tools / tesh2 / src / unit.c
index b016d41..ddd362a 100644 (file)
@@ -71,8 +71,10 @@ unit_start(void* p)
        /* 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("checking unit %s...",root->fstream->name); \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
@@ -92,16 +94,19 @@ unit_start(void* p)
        }\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
+\r
                /* interrupt all the running commands of the included units */\r
                include_nb = xbt_dynar_length(root->includes);\r
                \r
@@ -131,7 +136,7 @@ unit_start(void* p)
                        }\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
@@ -153,6 +158,16 @@ unit_start(void* p)
                        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
@@ -161,6 +176,28 @@ unit_start(void* p)
        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
@@ -171,25 +208,67 @@ unit_start(void* p)
                                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
+\r
        /* update the number of ended units of the runner */\r
        xbt_os_mutex_acquire(root->mutex);\r
-\r
+       \r
        /* increment the number of ended units */\r
        root->runner->number_of_ended_units++;\r
        \r
-       /* if itc's the last unit, release the runner */\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)\r
-                       root->successeded = 1;\r
-\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
@@ -212,8 +291,6 @@ unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream)
 {\r
        unit_t unit;\r
        \r
-       /* TODO : check the parameters */\r
-       \r
        unit = xbt_new0(s_unit_t, 1);\r
        \r
        /* instantiate the vector used to store all the commands of the unit */\r
@@ -256,27 +333,56 @@ unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream)
        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
-       \r
-       /* check the parameter */\r
        if(!(*ptr))\r
     {\r
         errno = EINVAL;\r
         return -1;\r
     }\r
-\r
-       xbt_dynar_free(&((*ptr)->commands));\r
        \r
-       xbt_dynar_free(&((*ptr)->includes));\r
-\r
-       xbt_dynar_free(&((*ptr)->suites));\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
@@ -285,6 +391,9 @@ unit_free(unit_t* ptr)
        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
@@ -407,7 +516,6 @@ unit_summuarize(unit_t unit)
        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
-       \r
        /* check the parameter */\r
        if(!(unit))\r
     {\r
@@ -462,7 +570,7 @@ unit_summuarize(unit_t unit)
                                : command->status == cs_successeded ? "PASS  " \r
                                : "UNKNWN",\r
                                command->context->command_line, \r
-                               command->context->line);\r
+                               command->context->pos);\r
                                \r
                        if(detail_summary_flag)\r
                                command_summarize(command);\r
@@ -546,7 +654,7 @@ unit_summuarize(unit_t unit)
                                : command->status == cs_successeded ? "PASS  " \r
                                : "UNKNWN",\r
                                command->context->command_line, \r
-                               command->context->line);\r
+                               command->context->pos);\r
                                \r
                                command_summarize(command);\r
                        }\r
@@ -655,7 +763,7 @@ unit_summuarize(unit_t unit)
                                        : command->status == cs_successeded ? "PASS  " \r
                                        : "UNKNWN",\r
                                        command->context->command_line, \r
-                                       command->context->line);\r
+                                       command->context->pos);\r
                                        \r
                                        command_summarize(command);\r
                                }\r
@@ -770,9 +878,45 @@ unit_summuarize(unit_t unit)
 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