Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
xbt_swag_foreach_safe is actually needed here.
[simgrid.git] / tools / tesh / tesh.c
index b8c5b1e..b4659fc 100644 (file)
@@ -6,13 +6,13 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "simgrid_config.h"     /* FILE for getline */
-
 /* specific to Borland Compiler */
 #ifdef __BORLANDDC__
 #pragma hdrstop
 #endif
 
+#include "simgrid_config.h" //For getline, keep that include first
+
 #include "tesh.h"
 #include "xbt.h"
 
@@ -21,8 +21,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(tesh, "TEst SHell utility");
 /*** Options ***/
 int timeout_value = 5;          /* child timeout value */
 int sort_len = 19;              /* length of the prefix to sort */
+char *option;
+int coverage = 0;                              /* whether the code coverage is enable */
 
+rctx_t rctx;
 const char *testsuite_name;
+
+xbt_dict_t env;
+
 static void handle_line(const char *filepos, char *line)
 {
   /* Search end */
@@ -85,7 +91,7 @@ static void handle_line(const char *filepos, char *line)
   }
 }
 
-static void handle_suite(const char *filename, FILE * FICIN)
+static void handle_suite(const char *filename, FILE * IN)
 {
   size_t len;
   int blankline;
@@ -100,7 +106,7 @@ static void handle_suite(const char *filename, FILE * FICIN)
   buff = xbt_strbuff_new();
   rctx = rctx_new();
 
-  while (getline(&line, &len, FICIN) != -1) {
+  while (getline(&line, &len, IN) != -1) {
     line_num++;
 
     /* Count the line length while checking wheather it's blank */
@@ -190,7 +196,7 @@ static void parse_environ()
 
 int main(int argc, char *argv[])
 {
-  FILE *FICIN = NULL;
+  FILE *IN = NULL;
   int i;
   char *suitename = NULL;
   struct sigaction newact;
@@ -227,7 +233,7 @@ int main(int argc, char *argv[])
         exit(1);
       }
       char *eq = strchr(argv[i+1], '=');
-      xbt_assert1(eq,"The argument of --setenv must contain a '=' (got %s instead)",argv[i+1]);
+      xbt_assert(eq,"The argument of --setenv must contain a '=' (got %s instead)",argv[i+1]);
       char *key = bprintf("%.*s", (int) (eq - argv[i+1]), argv[i+1]);
       xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
       XBT_INFO("setting environment variable '%s' to '%s'", key, eq+1);
@@ -250,6 +256,13 @@ int main(int argc, char *argv[])
       argc -= 2;
       i -= 2;
     }
+    else if (!strcmp(argv[i], "--enable-coverage" )){
+       coverage = 1;
+       XBT_INFO("Enable coverage");
+       memmove(argv + i, argv + i + 1, (argc - i - 1) * sizeof(char *));
+       argc -= 1;
+       i -= 1;
+    }
   }
 
   /* Find the description file */
@@ -272,15 +285,15 @@ int main(int argc, char *argv[])
 
       XBT_INFO("Test suite `%s'", suitename);
       testsuite_name = suitename;
-      FICIN = fopen(argv[i], "r");
-      if (!FICIN) {
+      IN = fopen(argv[i], "r");
+      if (!IN) {
         perror(bprintf("Impossible to open the suite file `%s'", argv[i]));
         XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
         rctx_armageddon(rctx, 1);
       }
-      handle_suite(suitename, FICIN);
+      handle_suite(suitename, IN);
       rctx_wait_bg();
-      fclose(FICIN);
+      fclose(IN);
       XBT_INFO("Test suite `%s' OK", suitename);
       free(suitename);
     }