Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore another generated file
[simgrid.git] / tools / tesh / run_context.c
index f58c80e..6f046df 100644 (file)
@@ -1,6 +1,6 @@
 /* run_context -- stuff in which TESH runs a command                        */
 
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007-2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -85,7 +85,7 @@ void rctx_init(void)
   sigwaiter_mutex = xbt_os_mutex_init();
   sigwaiter_cond = xbt_os_cond_init();
   xbt_os_mutex_acquire(sigwaiter_mutex);
-  sigwaiter_thread = xbt_os_thread_create("Armaggedon request waiter",
+  sigwaiter_thread = xbt_os_thread_create("Armageddon request waiter",
                                           armageddon_sigwaiter, NULL, NULL);
   /* Wait for thread to start... */
   xbt_os_cond_wait(sigwaiter_cond, sigwaiter_mutex);
@@ -742,7 +742,7 @@ void *rctx_wait(void *r)
      return NULL;
      xbt_os_mutex_acquire(rctx->interruption); */
 
-  {
+  { // Sorting output got
     xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
     xbt_dynar_t b = xbt_dynar_new(sizeof(char *), NULL);
     unsigned cpt;
@@ -777,10 +777,24 @@ void *rctx_wait(void *r)
     xbt_dynar_free(&a);
   }
 
+  if (rctx->output_sort) { // Sorting output wanted
+    char *newbuf;
+    xbt_dynar_t a = xbt_str_split(rctx->output_wanted->data, "\n");
+
+    stable_sort(a);
+    /* If empty lines moved in first position, remove them */
+    while (!xbt_dynar_is_empty(a) && *xbt_dynar_getfirst_as(a, char*) == '\0')
+        xbt_dynar_shift(a, NULL);
+
+    newbuf = xbt_str_join(a, "\n");
+    strcpy(rctx->output_wanted->data, newbuf);
+    rctx->output_wanted->used = strlen(newbuf);
+    xbt_free(newbuf);
+
+    xbt_dynar_free(&a);
+  }
   xbt_strbuff_chomp(rctx->output_got);
   xbt_strbuff_chomp(rctx->output_wanted);
-  xbt_strbuff_trim(rctx->output_got);
-  xbt_strbuff_trim(rctx->output_wanted);
 
   /* Check for broken pipe */
   if (rctx->brokenpipe)
@@ -855,7 +869,7 @@ void *rctx_wait(void *r)
     xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
     char *out = xbt_str_join(a, "\n||");
     xbt_dynar_free(&a);
-    XBT_INFO("Output of <%s> so far: \n||%s", rctx->filepos, out);
+    XBT_INFO("Output of <%s> so far:\n||%s", rctx->filepos, out);
     free(out);
   } else if (rctx->output == e_output_check
              && (rctx->output_got->used != rctx->output_wanted->used
@@ -877,7 +891,7 @@ void *rctx_wait(void *r)
     xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
     char *out = xbt_str_join(a, "\n||");
     xbt_dynar_free(&a);
-    XBT_INFO("Here is the (ignored) command output: \n||%s", out);
+    XBT_INFO("Here is the (ignored) command output:\n||%s", out);
     free(out);
   }