Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
We need cmake 2.8 to compile simgrid
[simgrid.git] / tools / tesh / tesh.c
index 1e2034c..0a6bbf3 100644 (file)
@@ -20,8 +20,9 @@ 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 *testsuite_name;
+const char *testsuite_name;
 static void handle_line(const char *filepos, char *line)
 {
   /* Search end */
@@ -193,7 +194,6 @@ int main(int argc, char *argv[])
   int i;
   char *suitename = NULL;
   struct sigaction newact;
-
   xbt_init(&argc, argv);
   rctx_init();
   parse_environ();
@@ -221,14 +221,43 @@ int main(int argc, char *argv[])
       memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
       argc -= 2;
       i -= 2;
+    } else if (!strcmp(argv[i], "--setenv" )) {
+      if (i == argc - 1) {
+        ERROR0("--setenv argument requires an argument");
+        exit(1);
+      }
+      char *eq = strchr(argv[i+1], '=');
+      xbt_assert1(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);
+      INFO2("setting environment variable '%s' to '%s'", key, eq+1);
+      free(key);
+      memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
+      argc -= 2;
+      i -= 2;
+    } else if (!strcmp(argv[i], "--cfg" )) {
+      if (i == argc - 1) {
+            ERROR0("--cfg argument requires an argument");
+            exit(1);
+      }
+      if(!option){ //if option is NULL
+       option = bprintf("--cfg=%s",argv[i+1]);
+      }else{
+       option = bprintf("%s --cfg=%s",option,argv[i+1]);
+      }
+      INFO1("Add option \'--cfg=%s\' to command line",argv[i+1]);
+      memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
+      argc -= 2;
+      i -= 2;
     }
   }
 
   /* Find the description file */
   if (argc == 1) {
     INFO0("Test suite from stdin");
-    testsuite_name = xbt_strdup("(stdin)");
-    handle_suite("stdin", stdin);
+    testsuite_name = "(stdin)";
+    handle_suite(testsuite_name, stdin);
+    rctx_wait_bg();
     INFO0("Test suite from stdin OK");
 
   } else {
@@ -259,5 +288,6 @@ int main(int argc, char *argv[])
 
   rctx_exit();
   xbt_dict_free(&env);
+  xbt_free_f(option);
   return 0;
 }