Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics to java documentation
[simgrid.git] / tools / tesh / tesh.c
index 98a6d14..fa34d0b 100644 (file)
@@ -21,10 +21,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(tesh,"TEst SHell utility");
 /*** Options ***/
 int timeout_value = 5; /* child timeout value */
 
-
+char *testsuite_name;
 static void handle_line(const char * filepos, char *line) {
-  int pos;
-
   /* Search end */
   xbt_str_rtrim(line+2,"\n");
 
@@ -56,11 +54,9 @@ static void handle_line(const char * filepos, char *line) {
       dir--;
       VERB1("Saw cd '%s'",dir);
       if (chdir(dir)) {
-       char buff[256];
-       strerror_r(errno, buff, 256);
-
-       ERROR2("Chdir to %s failed: %s",dir+pos+2,buff);
-       exit(4);
+       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 */
@@ -74,26 +70,30 @@ static void handle_line(const char * filepos, char *line) {
   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);
-    exit(1);
+    ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
+    rctx_armageddon(rctx,1);
     break;
   }
 }
 
 static void handle_suite(const char* filename, FILE* IN) {
-  int len;
+  size_t len;
   char * line = NULL;
   int line_num=0;
   char file_pos[256];
 
-  buff_t buff=buff_new();
+  xbt_strbuff_t buff=xbt_strbuff_new();
   int buffbegin = 0;   
 
   rctx = rctx_new();
 
-  while (getline(&line,(size_t*) &len, IN) != -1) {
+  while (getline(&line, &len, IN) != -1) {
     line_num++;
 
     /* Count the line length while checking wheather it's blank */
@@ -109,7 +109,8 @@ static void handle_suite(const char* filename, FILE* IN) {
       if (!rctx->cmd && !rctx->is_empty) {
        ERROR1("[%d] Error: no command found in this chunk of lines.",
               buffbegin);
-       exit(1);
+       ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name);
+       rctx_armageddon(rctx,1);
       }
       if (rctx->cmd)
        rctx_start();
@@ -134,12 +135,12 @@ static void handle_suite(const char* filename, FILE* IN) {
     }
 
     if (buff->used || to_be_continued) { 
-      buff_append(buff,line);
+      xbt_strbuff_append(buff,line);
 
       if (!to_be_continued) {
        snprintf(file_pos,256,"%s:%d",filename,buffbegin);
        handle_line(file_pos, buff->data);    
-       buff_empty(buff);
+       xbt_strbuff_empty(buff);
       }
        
     } else {
@@ -158,7 +159,7 @@ static void handle_suite(const char* filename, FILE* IN) {
   /* Clear buffers */
   if (line)
     free(line);
-  buff_free(buff);
+  xbt_strbuff_free(buff);
 
 }
 
@@ -180,6 +181,7 @@ int main(int argc,char *argv[]) {
   /* Find the description file */
   if (argc == 1) {
     INFO0("Test suite from stdin");
+    testsuite_name = xbt_strdup("(stdin)");
     handle_suite("stdin",stdin);
     INFO0("Test suite from stdin OK");
      
@@ -195,14 +197,16 @@ int main(int argc,char *argv[]) {
        suitename[strlen(suitename)-5] = '\0';
 
       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]));
-       exit(1);
+       ERROR1("Test suite `%s': NOK (system error)",testsuite_name);
+       rctx_armageddon(rctx,1);
        }
       handle_suite(suitename,IN);
       rctx_wait_bg();
-      fclose(IN); //->leads to segfault on amd64...
+      fclose(IN); 
       INFO1("Test suite `%s' OK",suitename);
       free(suitename);
     }