Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reindent
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 10 Sep 2008 08:20:39 +0000 (08:20 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 10 Sep 2008 08:20:39 +0000 (08:20 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5910 48e7efb5-ca39-0410-a469-dd3cf9ba447f

tools/tesh/run_context.c
tools/tesh/run_context.h
tools/tesh/signal.c
tools/tesh/tesh.c
tools/tesh/tesh.h

index 56c283f..3efdb7f 100644 (file)
@@ -43,9 +43,9 @@ void rctx_exit(void) {
   if (bg_jobs) {
     /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
     while (xbt_dynar_length(bg_jobs)) {
   if (bg_jobs) {
     /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
     while (xbt_dynar_length(bg_jobs)) {
-       rctx_t rctx;
-       xbt_dynar_pop(bg_jobs,&rctx);
-       kill_it(&rctx);
+      rctx_t rctx;
+      xbt_dynar_pop(bg_jobs,&rctx);
+      kill_it(&rctx);
     }
     xbt_dynar_free(&bg_jobs);
   }
     }
     xbt_dynar_free(&bg_jobs);
   }
@@ -56,9 +56,9 @@ void rctx_wait_bg(void) {
   if (bg_jobs) {
     /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
     while (xbt_dynar_length(bg_jobs)) {
   if (bg_jobs) {
     /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
     while (xbt_dynar_length(bg_jobs)) {
-       rctx_t rctx;
-       xbt_dynar_pop(bg_jobs,&rctx);
-       kill_it(&rctx);
+      rctx_t rctx;
+      xbt_dynar_pop(bg_jobs,&rctx);
+      kill_it(&rctx);
     }
     xbt_dynar_free(&bg_jobs);
   }
     }
     xbt_dynar_free(&bg_jobs);
   }
@@ -89,9 +89,9 @@ void rctx_armageddon(rctx_t initiator, int exitcode) {
       rctx->interrupted = 1;
       xbt_os_mutex_release(rctx->interruption);
       if (!rctx->reader_done) {
       rctx->interrupted = 1;
       xbt_os_mutex_release(rctx->interruption);
       if (!rctx->reader_done) {
-       kill(rctx->pid,SIGTERM);
-       usleep(100);
-       kill(rctx->pid,SIGKILL);
+        kill(rctx->pid,SIGTERM);
+        usleep(100);
+        kill(rctx->pid,SIGKILL);
       }
     }
   }
       }
     }
   }
@@ -109,8 +109,8 @@ void rctx_armageddon(rctx_t initiator, int exitcode) {
 # include <crt_externs.h>
 # define environ (*_NSGetEnviron())
 # else
 # include <crt_externs.h>
 # define environ (*_NSGetEnviron())
 # else
- /* the environment, as specified by the opengroup, used to initialize the process properties */
- extern char **environ;
+/* the environment, as specified by the opengroup, used to initialize the process properties */
+extern char **environ;
 # endif
 
 void rctx_empty(rctx_t rc) {
 # endif
 
 void rctx_empty(rctx_t rc) {
@@ -123,7 +123,7 @@ void rctx_empty(rctx_t rc) {
   if (rc->filepos)
     free(rc->filepos);
   if (rc->env)
   if (rc->filepos)
     free(rc->filepos);
   if (rc->env)
-     free(rc->env);
+    free(rc->env);
 
   for (i=0;*env_it;i++,env_it++);
   i++;
 
   for (i=0;*env_it;i++,env_it++);
   i++;
@@ -177,12 +177,12 @@ void rctx_free(rctx_t rctx) {
 
 void rctx_dump(rctx_t rctx, const char *str) {
   DEBUG9("%s RCTX %p={in%p={%d,%10s}, want={%d,%10s}, out={%d,%10s}}",
 
 void rctx_dump(rctx_t rctx, const char *str) {
   DEBUG9("%s RCTX %p={in%p={%d,%10s}, want={%d,%10s}, out={%d,%10s}}",
-        str, rctx,
-        rctx->input,              rctx->input->used,        rctx->input->data,
-        rctx->output_wanted->used,rctx->output_wanted->data,
-        rctx->output_got->used,   rctx->output_got->data);
+         str, rctx,
+         rctx->input,              rctx->input->used,        rctx->input->data,
+         rctx->output_wanted->used,rctx->output_wanted->data,
+         rctx->output_got->used,   rctx->output_got->data);
   DEBUG5("%s RCTX %p=[cmd%p=%10s, pid=%d]",
   DEBUG5("%s RCTX %p=[cmd%p=%10s, pid=%d]",
-        str,rctx,rctx->cmd,rctx->cmd,rctx->pid);
+         str,rctx,rctx->cmd,rctx->cmd,rctx->pid);
 
 }
 
 
 }
 
@@ -193,88 +193,88 @@ void rctx_dump(rctx_t rctx, const char *str) {
 void rctx_pushline(const char* filepos, char kind, char *line) {
 
   switch (kind) {
 void rctx_pushline(const char* filepos, char kind, char *line) {
 
   switch (kind) {
-  case '$':
-  case '&':
-    if (rctx->cmd) {
-      if (!rctx->is_empty) {
-       ERROR2("[%s] More than one command in this chunk of lines (previous: %s).\n"
-              " Dunno which input/output belongs to which command.",
-              filepos,rctx->cmd);
-       ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
-       rctx_armageddon(rctx,1);
-       return;
+    case '$':
+    case '&':
+      if (rctx->cmd) {
+        if (!rctx->is_empty) {
+          ERROR2("[%s] More than one command in this chunk of lines (previous: %s).\n"
+                 " Dunno which input/output belongs to which command.",
+                 filepos,rctx->cmd);
+          ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
+          rctx_armageddon(rctx,1);
+          return;
+        }
+        rctx_start();
+        VERB1("[%s] More than one command in this chunk of lines",filepos);
       }
       }
-      rctx_start();
-      VERB1("[%s] More than one command in this chunk of lines",filepos);
-    }
-    if (kind == '&')
-      rctx->is_background = 1;
-    else
-      rctx->is_background = 0;
-
-    rctx->cmd = xbt_strdup(line);
-    rctx->filepos = xbt_strdup(filepos);
-    INFO3("[%s] %s%s",filepos,rctx->cmd,
-         ((rctx->is_background)?" (background command)":""));
-
-    break;
-
-  case '<':
-    rctx->is_empty = 0;
-    xbt_strbuff_append(rctx->input,line);
-    xbt_strbuff_append(rctx->input,"\n");
-    break;
-
-  case '>':
-    rctx->is_empty = 0;
-    xbt_strbuff_append(rctx->output_wanted,line);
-    xbt_strbuff_append(rctx->output_wanted,"\n");
-    break;
-
-  case '!':
-    if (rctx->cmd)
-      rctx_start();
-
-    if (!strncmp(line,"timeout no",strlen("timeout no"))) {
-      VERB1("[%s] (disable timeout)", filepos);
-      timeout_value = -1;
-    } else if (!strncmp(line,"timeout ",strlen("timeout "))) {
-      timeout_value=atoi(line+strlen("timeout"));
-      VERB2("[%s] (new timeout value: %d)",
-            filepos,timeout_value);
-
-    } else if (!strncmp(line,"expect signal ",strlen("expect signal "))) {
-      rctx->expected_signal = strdup(line + strlen("expect signal "));
-      xbt_str_trim(rctx->expected_signal," \n");
-          VERB2("[%s] (next command must raise signal %s)",
-                filepos, rctx->expected_signal);
-
-    } else if (!strncmp(line,"expect return ",strlen("expect return "))) {
-      rctx->expected_return = atoi(line+strlen("expect return "));
-      VERB2("[%s] (next command must return code %d)",
-           filepos, rctx->expected_return);
-
-    } else if (!strncmp(line,"output ignore",strlen("output ignore"))) {
-      rctx->output = e_output_ignore;
-      VERB1("[%s] (ignore output of next command)", filepos);
-
-    } else if (!strncmp(line,"output display",strlen("output display"))) {
-      rctx->output = e_output_display;
-      VERB1("[%s] (ignore output of next command)", filepos);
-
-    } else if (!strncmp(line,"setenv ",strlen("setenv "))) {
-      rctx->env = realloc(rctx->env,++(rctx->env_size)*sizeof(char*));
-      rctx->env[rctx->env_size-2] = xbt_strdup(line+strlen("setenv "));
-      rctx->env[rctx->env_size-1] = NULL;
-      VERB1("[%s] (ignore output of next command)", filepos);
-
-    } else {
-      ERROR2("%s: Malformed metacommand: %s",filepos,line);
-      ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
-      rctx_armageddon(rctx,1);
-      return;
-    }
-    break;
+      if (kind == '&')
+        rctx->is_background = 1;
+      else
+        rctx->is_background = 0;
+
+      rctx->cmd = xbt_strdup(line);
+      rctx->filepos = xbt_strdup(filepos);
+      INFO3("[%s] %s%s",filepos,rctx->cmd,
+            ((rctx->is_background)?" (background command)":""));
+
+      break;
+
+    case '<':
+      rctx->is_empty = 0;
+      xbt_strbuff_append(rctx->input,line);
+      xbt_strbuff_append(rctx->input,"\n");
+      break;
+
+    case '>':
+      rctx->is_empty = 0;
+      xbt_strbuff_append(rctx->output_wanted,line);
+      xbt_strbuff_append(rctx->output_wanted,"\n");
+      break;
+
+    case '!':
+      if (rctx->cmd)
+        rctx_start();
+
+      if (!strncmp(line,"timeout no",strlen("timeout no"))) {
+        VERB1("[%s] (disable timeout)", filepos);
+        timeout_value = -1;
+      } else if (!strncmp(line,"timeout ",strlen("timeout "))) {
+        timeout_value=atoi(line+strlen("timeout"));
+        VERB2("[%s] (new timeout value: %d)",
+              filepos,timeout_value);
+
+      } else if (!strncmp(line,"expect signal ",strlen("expect signal "))) {
+        rctx->expected_signal = strdup(line + strlen("expect signal "));
+        xbt_str_trim(rctx->expected_signal," \n");
+        VERB2("[%s] (next command must raise signal %s)",
+              filepos, rctx->expected_signal);
+
+      } else if (!strncmp(line,"expect return ",strlen("expect return "))) {
+        rctx->expected_return = atoi(line+strlen("expect return "));
+        VERB2("[%s] (next command must return code %d)",
+              filepos, rctx->expected_return);
+
+      } else if (!strncmp(line,"output ignore",strlen("output ignore"))) {
+        rctx->output = e_output_ignore;
+        VERB1("[%s] (ignore output of next command)", filepos);
+
+      } else if (!strncmp(line,"output display",strlen("output display"))) {
+        rctx->output = e_output_display;
+        VERB1("[%s] (ignore output of next command)", filepos);
+
+      } else if (!strncmp(line,"setenv ",strlen("setenv "))) {
+        rctx->env = realloc(rctx->env,++(rctx->env_size)*sizeof(char*));
+        rctx->env[rctx->env_size-2] = xbt_strdup(line+strlen("setenv "));
+        rctx->env[rctx->env_size-1] = NULL;
+        VERB1("[%s] (ignore output of next command)", filepos);
+
+      } else {
+        ERROR2("%s: Malformed metacommand: %s",filepos,line);
+        ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
+        rctx_armageddon(rctx,1);
+        return;
+      }
+      break;
   }
 }
 
   }
 }
 
@@ -296,12 +296,12 @@ static void* thread_writer(void *r) {
       posw+=got;
     if (got<0) {
       if (errno == EPIPE) {
       posw+=got;
     if (got<0) {
       if (errno == EPIPE) {
-       rctx->brokenpipe = 1;
+        rctx->brokenpipe = 1;
       } else if (errno!=EINTR && errno!=EAGAIN && errno!=EPIPE) {
       } else if (errno!=EINTR && errno!=EAGAIN && errno!=EPIPE) {
-       perror("Error while writing input to child");
-       ERROR1("Test suite `%s': NOK (system error)",testsuite_name);
-       rctx_armageddon(rctx,4);
-       return NULL;
+        perror("Error while writing input to child");
+        ERROR1("Test suite `%s': NOK (system error)",testsuite_name);
+        rctx_armageddon(rctx,4);
+        return NULL;
       }
     }
     DEBUG1("written %d chars so far",posw);
       }
     }
     DEBUG1("written %d chars so far",posw);
@@ -381,9 +381,9 @@ void rctx_start(void) {
     rctx->child_from = child_out[0];
 
     if (timeout_value > 0)
     rctx->child_from = child_out[0];
 
     if (timeout_value > 0)
-       rctx->end_time = time(NULL) + timeout_value;
+      rctx->end_time = time(NULL) + timeout_value;
     else
     else
-       rctx->end_time = -1;
+      rctx->end_time = -1;
 
     rctx->reader_done = 0;
     rctx->reader = xbt_os_thread_create("reader",thread_reader,(void*)rctx);
 
     rctx->reader_done = 0;
     rctx->reader = xbt_os_thread_create("reader",thread_reader,(void*)rctx);
@@ -400,60 +400,60 @@ void rctx_start(void) {
     dup2(child_out[1],2);
     close(child_out[1]);
 
     dup2(child_out[1],2);
     close(child_out[1]);
 
-       xbt_dynar_t cmd = xbt_str_split_quoted(rctx->cmd);
-       char *file;
-       unsigned int it;
-       char *str;
-       char *long_cmd=xbt_strdup("");
-       xbt_dynar_get_cpy(cmd,0,&file);
-       char **args = xbt_new(char*,xbt_dynar_length(cmd)+1);
-       xbt_dynar_foreach(cmd,it,str) {
-               args[it] = xbt_strdup(str);
-               long_cmd = bprintf("%s %s",long_cmd,str);
-       }
-       args[it] = NULL;
-
-         /* To search for the right executable path when not trivial */
-         struct stat stat_buf;
-         char *binary_name = NULL;
-
-         /* build the command line */
-         if (stat(file, &stat_buf)) {
-           /* Damn. binary not in current dir. We'll have to dig the PATH to find it */
-           int i;
-
-           for (i = 0; environ[i]; i++) {
-             if (!strncmp("PATH=", environ[i], 5)) {
-               xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
-
-               xbt_dynar_foreach(path, it, str) {
-                 if (binary_name)
-                   free(binary_name);
-                 binary_name = bprintf("%s/%s", str, file);
-                 if (!stat(binary_name, &stat_buf)) {
-                   /* Found. */
-                   DEBUG1("Looked in the PATH for the binary. Found %s",
-                          binary_name);
-                   xbt_dynar_free(&path);
-                   break;
-                 }
-               }
-               xbt_dynar_free(&path);
-               if (stat(binary_name, &stat_buf)) {
-                 /* not found */
-                 ERROR1("Command %s not found",file);
-                 return;
-               }
-               break;
-             }
-           }
-         } else {
-           binary_name = xbt_strdup(file);
-         }
-
-
-       DEBUG2("execve %s %s env",binary_name,long_cmd);
-       execve(binary_name, args, rctx->env);
+    xbt_dynar_t cmd = xbt_str_split_quoted(rctx->cmd);
+    char *file;
+    unsigned int it;
+    char *str;
+    char *long_cmd=xbt_strdup("");
+    xbt_dynar_get_cpy(cmd,0,&file);
+    char **args = xbt_new(char*,xbt_dynar_length(cmd)+1);
+    xbt_dynar_foreach(cmd,it,str) {
+      args[it] = xbt_strdup(str);
+      long_cmd = bprintf("%s %s",long_cmd,str);
+    }
+    args[it] = NULL;
+
+    /* To search for the right executable path when not trivial */
+    struct stat stat_buf;
+    char *binary_name = NULL;
+
+    /* build the command line */
+    if (stat(file, &stat_buf)) {
+      /* Damn. binary not in current dir. We'll have to dig the PATH to find it */
+      int i;
+
+      for (i = 0; environ[i]; i++) {
+        if (!strncmp("PATH=", environ[i], 5)) {
+          xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
+
+          xbt_dynar_foreach(path, it, str) {
+            if (binary_name)
+              free(binary_name);
+            binary_name = bprintf("%s/%s", str, file);
+            if (!stat(binary_name, &stat_buf)) {
+              /* Found. */
+              DEBUG1("Looked in the PATH for the binary. Found %s",
+                     binary_name);
+              xbt_dynar_free(&path);
+              break;
+            }
+          }
+          xbt_dynar_free(&path);
+          if (stat(binary_name, &stat_buf)) {
+            /* not found */
+            ERROR1("Command %s not found",file);
+            return;
+          }
+          break;
+        }
+      }
+    } else {
+      binary_name = xbt_strdup(file);
+    }
+
+
+    DEBUG2("execve %s %s env",binary_name,long_cmd);
+    execve(binary_name, args, rctx->env);
   }
 
   rctx->is_stoppable = 1;
   }
 
   rctx->is_stoppable = 1;
@@ -472,7 +472,7 @@ void rctx_start(void) {
     runner = xbt_os_thread_create(old->cmd,rctx_wait,(void*)old);
     old->runner = runner;
     VERB3("Launched thread %p to wait for %s %d",
     runner = xbt_os_thread_create(old->cmd,rctx_wait,(void*)old);
     old->runner = runner;
     VERB3("Launched thread %p to wait for %s %d",
-         runner,old->cmd, old->pid);
+          runner,old->cmd, old->pid);
     xbt_dynar_push(bg_jobs,&old);
   }
 }
     xbt_dynar_push(bg_jobs,&old);
   }
 }
@@ -491,7 +491,7 @@ void *rctx_wait(void* r) {
 
   if (!rctx->is_stoppable)
     THROW1(unknown_error,0,"Cmd '%s' not started yet. Cannot wait it",
 
   if (!rctx->is_stoppable)
     THROW1(unknown_error,0,"Cmd '%s' not started yet. Cannot wait it",
-          rctx->cmd);
+           rctx->cmd);
 
   /* Wait for the child to die or the timeout to happen (or an armageddon to happen) */
   while (!rctx->interrupted && !rctx->reader_done && (rctx->end_time <0 ||rctx->end_time >= now)) {
 
   /* Wait for the child to die or the timeout to happen (or an armageddon to happen) */
   while (!rctx->interrupted && !rctx->reader_done && (rctx->end_time <0 ||rctx->end_time >= now)) {
@@ -533,12 +533,12 @@ void *rctx_wait(void* r) {
   if (rctx->timeout) {
     if (rctx->output_got->data[0])
       INFO2("<%s> Output on timeout:\n%s",
   if (rctx->timeout) {
     if (rctx->output_got->data[0])
       INFO2("<%s> Output on timeout:\n%s",
-           rctx->filepos,rctx->output_got->data);
+            rctx->filepos,rctx->output_got->data);
     else
       INFO1("<%s> No output before timeout",
     else
       INFO1("<%s> No output before timeout",
-           rctx->filepos);
+            rctx->filepos);
     ERROR3("Test suite `%s': NOK (<%s> timeout after %d sec)",
     ERROR3("Test suite `%s': NOK (<%s> timeout after %d sec)",
-          testsuite_name,rctx->filepos,timeout_value);
+           testsuite_name,rctx->filepos,timeout_value);
     DEBUG2("<%s> Interrupted = %d", rctx->filepos, rctx->interrupted);
     if (!rctx->interrupted) {
       rctx_armageddon(rctx, 3);
     DEBUG2("<%s> Interrupted = %d", rctx->filepos, rctx->interrupted);
     if (!rctx->interrupted) {
       rctx_armageddon(rctx, 3);
@@ -552,36 +552,36 @@ void *rctx_wait(void* r) {
   if (!rctx->interrupted) {
     if (WIFSIGNALED(rctx->status) && !rctx->expected_signal) {
       ERROR3("Test suite `%s': NOK (<%s> got signal %s)",
   if (!rctx->interrupted) {
     if (WIFSIGNALED(rctx->status) && !rctx->expected_signal) {
       ERROR3("Test suite `%s': NOK (<%s> got signal %s)",
-            testsuite_name, rctx->filepos,
-            signal_name(WTERMSIG(rctx->status),NULL));
+             testsuite_name, rctx->filepos,
+             signal_name(WTERMSIG(rctx->status),NULL));
       errcode = WTERMSIG(rctx->status)+4;
     }
 
     if (WIFSIGNALED(rctx->status) && rctx->expected_signal &&
       errcode = WTERMSIG(rctx->status)+4;
     }
 
     if (WIFSIGNALED(rctx->status) && rctx->expected_signal &&
-       strcmp(signal_name(WTERMSIG(rctx->status),rctx->expected_signal),
-              rctx->expected_signal)) {
+        strcmp(signal_name(WTERMSIG(rctx->status),rctx->expected_signal),
+               rctx->expected_signal)) {
       ERROR4("Test suite `%s': NOK (%s got signal %s instead of %s)",
       ERROR4("Test suite `%s': NOK (%s got signal %s instead of %s)",
-            testsuite_name, rctx->filepos,
-            signal_name(WTERMSIG(rctx->status),rctx->expected_signal),
-            rctx->expected_signal);
+             testsuite_name, rctx->filepos,
+             signal_name(WTERMSIG(rctx->status),rctx->expected_signal),
+             rctx->expected_signal);
       errcode = WTERMSIG(rctx->status)+4;
     }
 
     if (!WIFSIGNALED(rctx->status) && rctx->expected_signal) {
       ERROR3("Test suite `%s': NOK (child %s expected signal %s)",
       errcode = WTERMSIG(rctx->status)+4;
     }
 
     if (!WIFSIGNALED(rctx->status) && rctx->expected_signal) {
       ERROR3("Test suite `%s': NOK (child %s expected signal %s)",
-            testsuite_name, rctx->filepos,
-            rctx->expected_signal);
+             testsuite_name, rctx->filepos,
+             rctx->expected_signal);
       errcode = 5;
     }
 
     if (WIFEXITED(rctx->status) && WEXITSTATUS(rctx->status) != rctx->expected_return ) {
       if (rctx->expected_return)
       errcode = 5;
     }
 
     if (WIFEXITED(rctx->status) && WEXITSTATUS(rctx->status) != rctx->expected_return ) {
       if (rctx->expected_return)
-       ERROR4("Test suite `%s': NOK (<%s> returned code %d instead of %d)",
-              testsuite_name, rctx->filepos,
-              WEXITSTATUS(rctx->status), rctx->expected_return);
+        ERROR4("Test suite `%s': NOK (<%s> returned code %d instead of %d)",
+               testsuite_name, rctx->filepos,
+               WEXITSTATUS(rctx->status), rctx->expected_return);
       else
       else
-       ERROR3("Test suite `%s': NOK (<%s> returned code %d)",
-              testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status));
+        ERROR3("Test suite `%s': NOK (<%s> returned code %d)",
+               testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status));
       errcode = 40+WEXITSTATUS(rctx->status);
 
     }
       errcode = 40+WEXITSTATUS(rctx->status);
 
     }
@@ -595,14 +595,14 @@ void *rctx_wait(void* r) {
 
   if (   rctx->output == e_output_check
       && (    rctx->output_got->used != rctx->output_wanted->used
 
   if (   rctx->output == e_output_check
       && (    rctx->output_got->used != rctx->output_wanted->used
-          || strcmp(rctx->output_got->data, rctx->output_wanted->data))) {
+          || strcmp(rctx->output_got->data, rctx->output_wanted->data))) {
     if (XBT_LOG_ISENABLED(tesh,xbt_log_priority_info)) {
     if (XBT_LOG_ISENABLED(tesh,xbt_log_priority_info)) {
-       char *diff= xbt_str_diff(rctx->output_wanted->data,rctx->output_got->data);
-       ERROR2("Output of <%s> mismatch:\n%s",rctx->filepos,diff);
-       free(diff);
+      char *diff= xbt_str_diff(rctx->output_wanted->data,rctx->output_got->data);
+      ERROR2("Output of <%s> mismatch:\n%s",rctx->filepos,diff);
+      free(diff);
     }
     ERROR2("Test suite `%s': NOK (<%s> output mismatch)",
     }
     ERROR2("Test suite `%s': NOK (<%s> output mismatch)",
-          testsuite_name,rctx->filepos);
+           testsuite_name,rctx->filepos);
 
     errcode=2;
   } else if (rctx->output == e_output_ignore) {
 
     errcode=2;
   } else if (rctx->output == e_output_ignore) {
index 9b33472..ae8ff5d 100644 (file)
@@ -14,7 +14,7 @@
 #include "tesh.h"
 
 typedef enum {e_output_check, e_output_display, e_output_ignore} e_output_handling_t;
 #include "tesh.h"
 
 typedef enum {e_output_check, e_output_display, e_output_ignore} e_output_handling_t;
-   
+
 
 typedef struct {
   /* kind of job */
 
 typedef struct {
   /* kind of job */
@@ -26,20 +26,20 @@ typedef struct {
   int is_background:1;
   int is_empty:1;
   int is_stoppable:1;
   int is_background:1;
   int is_empty:1;
   int is_stoppable:1;
-  
+
   int brokenpipe:1;
   int timeout:1;
 
   int reader_done:1; /* reader set this to true when he's done because
                        the child is dead. The main thread use it to detect
                        that the child is not dead before the end of timeout */
   int brokenpipe:1;
   int timeout:1;
 
   int reader_done:1; /* reader set this to true when he's done because
                        the child is dead. The main thread use it to detect
                        that the child is not dead before the end of timeout */
-   
+
   int interrupted:1; /* Whether we got stopped by an armageddon */
   int interrupted:1; /* Whether we got stopped by an armageddon */
-  xbt_os_mutex_t interruption; /* To allow main thread to kill a runner 
+  xbt_os_mutex_t interruption; /* To allow main thread to kill a runner
                               one only at certain points */
 
   e_output_handling_t output;
                               one only at certain points */
 
   e_output_handling_t output;
-   
+
   int status;
 
   /* expected results */
   int status;
 
   /* expected results */
@@ -64,7 +64,7 @@ typedef struct {
 /* module mgmt */
 void rctx_init(void);
 void rctx_exit(void);
 /* module mgmt */
 void rctx_init(void);
 void rctx_exit(void);
-   
+
 /* wait for all currently running background jobs */
 void rctx_wait_bg(void);
 
 /* wait for all currently running background jobs */
 void rctx_wait_bg(void);
 
@@ -79,8 +79,8 @@ rctx_t rctx_new(void);
 void rctx_free(rctx_t rctx);
 void rctx_empty(rctx_t rc); /*reset to empty*/
 void rctx_dump(rctx_t rctx,const char *str);
 void rctx_free(rctx_t rctx);
 void rctx_empty(rctx_t rc); /*reset to empty*/
 void rctx_dump(rctx_t rctx,const char *str);
-   
-   
+
+
 /* Launch the current command */
 void rctx_start(void);
 /* Wait till the end of this command */
 /* Launch the current command */
 void rctx_start(void);
 /* Wait till the end of this command */
index a6d26b8..020caa2 100644 (file)
@@ -17,36 +17,36 @@ typedef struct s_signal_entry {
 } s_signal_entry_t,* signal_entry_t;
 
 static const s_signal_entry_t signals[] = {
 } s_signal_entry_t,* signal_entry_t;
 
 static const s_signal_entry_t signals[] = {
      {"SIGHUP"       ,SIGHUP},
      {"SIGINT"       ,SIGINT},
      {"SIGQUIT"      ,SIGQUIT},
      {"SIGILL"       ,SIGILL},
      {"SIGTRAP"      ,SIGTRAP},
      {"SIGABRT"      ,SIGABRT},
      {"SIGFPE"       ,SIGFPE},
      {"SIGKILL"      ,SIGKILL},
      {"SIGBUS"       ,SIGBUS},
      {"SIGSEGV"      ,SIGSEGV},
      {"SIGSYS"       ,SIGSYS},
      {"SIGPIPE"      ,SIGPIPE},
      {"SIGALRM"      ,SIGALRM},
      {"SIGTERM"      ,SIGTERM},
      {"SIGURG"       ,SIGURG},
      {"SIGSTOP"      ,SIGSTOP},
      {"SIGTSTP"      ,SIGTSTP},
      {"SIGCONT"      ,SIGCONT},
      {"SIGCHLD"      ,SIGCHLD},
      {"SIGTTIN"      ,SIGTTIN},
      {"SIGTTOU"      ,SIGTTOU},
      {"SIGIO"        ,SIGIO},
      {"SIGXCPU"      ,SIGXCPU},
      {"SIGXFSZ"      ,SIGXFSZ},
      {"SIGVTALRM"    ,SIGVTALRM},
      {"SIGPROF"      ,SIGPROF},
      {"SIGWINCH"     ,SIGWINCH},
      {"SIGUSR1"      ,SIGUSR1},
      {"SIGUSR2"      ,SIGUSR2},
      {"SIG UNKNOWN"  ,-1}
{"SIGHUP"     ,SIGHUP},
{"SIGINT"     ,SIGINT},
{"SIGQUIT"    ,SIGQUIT},
{"SIGILL"     ,SIGILL},
{"SIGTRAP"    ,SIGTRAP},
{"SIGABRT"    ,SIGABRT},
{"SIGFPE"     ,SIGFPE},
{"SIGKILL"    ,SIGKILL},
{"SIGBUS"     ,SIGBUS},
{"SIGSEGV"    ,SIGSEGV},
{"SIGSYS"     ,SIGSYS},
{"SIGPIPE"    ,SIGPIPE},
{"SIGALRM"    ,SIGALRM},
{"SIGTERM"    ,SIGTERM},
{"SIGURG"     ,SIGURG},
{"SIGSTOP"    ,SIGSTOP},
{"SIGTSTP"    ,SIGTSTP},
{"SIGCONT"    ,SIGCONT},
{"SIGCHLD"    ,SIGCHLD},
{"SIGTTIN"    ,SIGTTIN},
{"SIGTTOU"    ,SIGTTOU},
{"SIGIO"      ,SIGIO},
{"SIGXCPU"    ,SIGXCPU},
{"SIGXFSZ"    ,SIGXFSZ},
{"SIGVTALRM"  ,SIGVTALRM},
{"SIGPROF"    ,SIGPROF},
{"SIGWINCH"   ,SIGWINCH},
{"SIGUSR1"    ,SIGUSR1},
{"SIGUSR2"    ,SIGUSR2},
+ {"SIG UNKNOWN"  ,-1}
 };
 
 
 };
 
 
@@ -57,7 +57,7 @@ const char* signal_name(unsigned int got, char *expected) {
      (segfault leads to any of them depending on the system) */
   if((got == SIGBUS) && !strcmp("SIGSEGV",expected))
     got = SIGSEGV;
      (segfault leads to any of them depending on the system) */
   if((got == SIGBUS) && !strcmp("SIGSEGV",expected))
     got = SIGSEGV;
-  
+
   for (i=0; signals[i].number != -1; i++)
     if (signals[i].number == got)
       return (signals[i].name);
   for (i=0; signals[i].number != -1; i++)
     if (signals[i].number == got)
       return (signals[i].name);
index 959362b..0d6255a 100644 (file)
@@ -32,53 +32,53 @@ static void handle_line(const char * filepos, char *line) {
         rctx->input->used,        rctx->input->data,
         rctx->output_wanted->used,rctx->output_wanted->data,
         rctx->output_got->used,   rctx->output_got->data);
         rctx->input->used,        rctx->input->data,
         rctx->output_wanted->used,rctx->output_wanted->data,
         rctx->output_got->used,   rctx->output_got->data);
-  */
+   */
   DEBUG2("[%s] %s",filepos,line);
 
   switch (line[0]) {
   DEBUG2("[%s] %s",filepos,line);
 
   switch (line[0]) {
-  case '#': break;
-
-  case '$':
-    /* further trim useless chars which are significant for in/output */
-    xbt_str_rtrim(line+2," \t");
+    case '#': break;
+
+    case '$':
+      /* further trim useless chars which are significant for in/output */
+      xbt_str_rtrim(line+2," \t");
+
+      /* Deal with CD commands here, not in rctx */
+      if (!strncmp("cd ",line+2,3)) {
+        char *dir=line+4;
+
+        if (rctx->cmd)
+          rctx_start();
+
+        /* search begining */
+        while (*(dir++) == ' ');
+        dir--;
+        VERB1("Saw cd '%s'",dir);
+        if (chdir(dir)) {
+          ERROR2("Chdir to %s failed: %s",dir,strerror(errno));
+          ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
+          rctx_armageddon(rctx,4);
+        }
+        break;
+      } /* else, pushline */
+    case '&':
+    case '<':
+    case '>':
+    case '!':
+      rctx_pushline(filepos, line[0], line+2 /* pass '$ ' stuff*/);
+      break;
 
 
-    /* Deal with CD commands here, not in rctx */
-    if (!strncmp("cd ",line+2,3)) {
-      char *dir=line+4;
+    case 'p':
+      INFO2("[%s] %s",filepos,line+2);
+      break;
+    case 'P':
+      CRITICAL2("[%s] %s",filepos,line+2);
+      break;
 
 
-      if (rctx->cmd)
-       rctx_start();
-
-      /* search begining */
-      while (*(dir++) == ' ');
-      dir--;
-      VERB1("Saw cd '%s'",dir);
-      if (chdir(dir)) {
-       ERROR2("Chdir to %s failed: %s",dir,strerror(errno));
-       ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
-       rctx_armageddon(rctx,4);
-      }
+    default:
+      ERROR2("[%s] Syntax error: %s",filepos, line);
+      ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
+      rctx_armageddon(rctx,1);
       break;
       break;
-    } /* else, pushline */
-  case '&':
-  case '<':
-  case '>':
-  case '!':
-    rctx_pushline(filepos, line[0], line+2 /* pass '$ ' stuff*/);
-    break;
-
-  case 'p':
-    INFO2("[%s] %s",filepos,line+2);
-    break;
-  case 'P':
-    CRITICAL2("[%s] %s",filepos,line+2);
-    break;
-
-  default:
-    ERROR2("[%s] Syntax error: %s",filepos, line);
-    ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
-    rctx_armageddon(rctx,1);
-    break;
   }
 }
 
   }
 }
 
@@ -101,19 +101,19 @@ static void handle_suite(const char* filename, FILE* IN) {
     int linelen = 0;
     while (line[linelen] != '\0') {
       if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n')
     int linelen = 0;
     while (line[linelen] != '\0') {
       if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n')
-       blankline = 0;
+        blankline = 0;
       linelen++;
     }
 
     if (blankline) {
       if (!rctx->cmd && !rctx->is_empty) {
       linelen++;
     }
 
     if (blankline) {
       if (!rctx->cmd && !rctx->is_empty) {
-       ERROR1("[%d] Error: no command found in this chunk of lines.",
-              buffbegin);
-       ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
-       rctx_armageddon(rctx,1);
+        ERROR1("[%d] Error: no command found in this chunk of lines.",
+               buffbegin);
+        ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
+        rctx_armageddon(rctx,1);
       }
       if (rctx->cmd)
       }
       if (rctx->cmd)
-       rctx_start();
+        rctx_start();
 
       continue;
     }
 
       continue;
     }
@@ -122,15 +122,15 @@ static void handle_suite(const char* filename, FILE* IN) {
     int to_be_continued = 0;
     if (linelen>1 && line[linelen-2]=='\\') {
       if (linelen>2 && line[linelen-3] == '\\') {
     int to_be_continued = 0;
     if (linelen>1 && line[linelen-2]=='\\') {
       if (linelen>2 && line[linelen-3] == '\\') {
-       /* Damn. Escaped \ */
-       line[linelen-2] = '\n';
-       line[linelen-1] = '\0';
+        /* Damn. Escaped \ */
+        line[linelen-2] = '\n';
+        line[linelen-1] = '\0';
       } else {
       } else {
-       to_be_continued = 1;
-       line[linelen-2] = '\0';
-       linelen -= 2;
-       if (!buff->used)
-         buffbegin = line_num;
+        to_be_continued = 1;
+        line[linelen-2] = '\0';
+        linelen -= 2;
+        if (!buff->used)
+          buffbegin = line_num;
       }
     }
 
       }
     }
 
@@ -138,9 +138,9 @@ static void handle_suite(const char* filename, FILE* IN) {
       xbt_strbuff_append(buff,line);
 
       if (!to_be_continued) {
       xbt_strbuff_append(buff,line);
 
       if (!to_be_continued) {
-       snprintf(file_pos,256,"%s:%d",filename,buffbegin);
-       handle_line(file_pos, buff->data);
-       xbt_strbuff_empty(buff);
+        snprintf(file_pos,256,"%s:%d",filename,buffbegin);
+        handle_line(file_pos, buff->data);
+        xbt_strbuff_empty(buff);
       }
 
     } else {
       }
 
     } else {
@@ -191,19 +191,19 @@ int main(int argc,char *argv[]) {
     for (i=1; i<argc; i++) {
       char *suitename=xbt_strdup(argv[i]);
       if (!strcmp("./",suitename))
     for (i=1; i<argc; i++) {
       char *suitename=xbt_strdup(argv[i]);
       if (!strcmp("./",suitename))
-       memmove(suitename, suitename+2, strlen(suitename+2));
+        memmove(suitename, suitename+2, strlen(suitename+2));
 
       if (!strcmp(".tesh",suitename+strlen(suitename)-5))
 
       if (!strcmp(".tesh",suitename+strlen(suitename)-5))
-       suitename[strlen(suitename)-5] = '\0';
+        suitename[strlen(suitename)-5] = '\0';
 
       INFO1("Test suite `%s'",suitename);
       testsuite_name = suitename;
       IN=fopen(argv[i], "r");
       if (!IN) {
 
       INFO1("Test suite `%s'",suitename);
       testsuite_name = suitename;
       IN=fopen(argv[i], "r");
       if (!IN) {
-       perror(bprintf("Impossible to open the suite file `%s'",argv[i]));
-       ERROR1("Test suite `%s': NOK (system error)",testsuite_name);
-       rctx_armageddon(rctx,1);
-       }
+        perror(bprintf("Impossible to open the suite file `%s'",argv[i]));
+        ERROR1("Test suite `%s': NOK (system error)",testsuite_name);
+        rctx_armageddon(rctx,1);
+      }
       handle_suite(suitename,IN);
       rctx_wait_bg();
       fclose(IN);
       handle_suite(suitename,IN);
       rctx_wait_bg();
       fclose(IN);
index 9d22cf2..0afed51 100644 (file)
@@ -22,7 +22,7 @@
 const char* signal_name(unsigned int got, char *expected);
 
 #include "run_context.h"
 const char* signal_name(unsigned int got, char *expected);
 
 #include "run_context.h"
-  
+
 /*** Options ***/
 int timeout_value; /* child timeout value */
 
 /*** Options ***/
 int timeout_value; /* child timeout value */