2 * src/fstream.c - type representing the tesh file stream.
\r
4 * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved.
\r
6 * This program is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the license (GNU LGPL) which comes with this package.
\r
10 * This file contains all the definitions of the functions related with
\r
11 * the tesh file stream type.
\r
15 #include <fstream.h>
\r
17 #include <context.h>
\r
18 #include <command.h>
\r
20 #include <str_replace.h>
\r
21 #include <variable.h>
\r
23 #include <readline.h>
\r
26 #include <getpath.h>
\r
29 #include <xsignal.h>
\r
34 is_w32_cmd(const char* cmd, char** path)
\r
37 struct stat stat_buff = {0};
\r
38 char buff[PATH_MAX + 1] = {0};
\r
48 if(stat(cmd, &stat_buff) || !S_ISREG(stat_buff.st_mode))
\r
52 for (i = 0; path[i] != NULL; i++)
\r
55 sprintf(buff,"%s\\%s",path[i], cmd);
\r
57 if(!stat(buff, &stat_buff) && S_ISREG(stat_buff.st_mode))
\r
71 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
\r
74 long fstream_getline(fstream_t fstream, char **buf, size_t *n) {
\r
76 return readline(fstream->stream, buf, n);
\r
81 failure(unit_t unit)
\r
83 if(!keep_going_unit_flag)
\r
85 unit_t root = unit->root ? unit->root : unit;
\r
87 if(!root->interrupted)
\r
89 /* the unit interrupted (exit for the loop) */
\r
90 root->interrupted = 1;
\r
92 /* release the unit */
\r
93 xbt_os_sem_release(root->sem);
\r
96 /* if the --keep-going option is not specified */
\r
97 if(!keep_going_flag)
\r
101 /* request an global interruption by the runner */
\r
104 /* release the runner */
\r
105 xbt_os_sem_release(units_sem);
\r
112 fstream_new(const char* directory, const char* name)
\r
122 if(!directory && !strcmp("stdin", name))
\r
124 fstream = xbt_new0(s_fstream_t, 1);
\r
125 fstream->name = strdup("stdin");
\r
128 else if(!directory)
\r
134 fstream = xbt_new0(s_fstream_t, 1);
\r
136 if(!(fstream->name = strdup(name)))
\r
142 if(!(fstream->directory = strdup(directory)))
\r
144 free(fstream->name);
\r
149 fstream->stream = NULL;
\r
150 fstream->unit = NULL;
\r
151 fstream->parsed = 0;
\r
158 fstream_open(fstream_t fstream)
\r
160 char path[PATH_MAX + 1] = {0};
\r
162 /* check the parameter */
\r
169 if(!fstream || fstream->stream)
\r
175 if(!strcmp(fstream->name, "stdin"))
\r
177 fstream->stream = stdin;
\r
182 sprintf(path,"%s/%s",fstream->directory, fstream->name);
\r
184 sprintf(path,"%s\\%s",fstream->directory, fstream->name);
\r
187 if(!(fstream->stream = fopen(path, "r")))
\r
196 fstream_close(fstream_t fstream)
\r
198 /* check the parameter */
\r
199 if(!(fstream) || !strcmp(fstream->name, "stdin") )
\r
205 if(!fstream->stream)
\r
208 if(EOF == fclose(fstream->stream))
\r
211 fstream->stream = NULL;
\r
217 fstream_free(fstream_t* ptr)
\r
220 /* check the parameter */
\r
231 fclose((*ptr)->stream);
\r
234 free((*ptr)->name);
\r
236 if((*ptr)->directory)
\r
237 free((*ptr)->directory);
\r
248 fstream_parse(fstream_t fstream, xbt_os_mutex_t mutex)
\r
251 char * line = NULL;
\r
253 char file_pos[256];
\r
254 xbt_strbuff_t buff;
\r
255 int buffbegin = 0;
\r
259 /* Count the line length while checking wheather it's blank */
\r
262 /* Deal with \ at the end of the line, and call handle_line on result */
\r
263 int to_be_continued;
\r
265 /* check the parameter */
\r
266 if(!(fstream) || !mutex)
\r
272 buff = xbt_strbuff_new();
\r
274 if(!(context = context_new()))
\r
277 unit = fstream->unit;
\r
279 /*while(!(unit->root->interrupted) && getline(&line, &len, fstream->stream) != -1)*/
\r
280 while(!(unit->root->interrupted) && fstream_getline(fstream, &line, &len) != -1)
\r
285 to_be_continued = 0;
\r
289 while(line[linelen] != '\0')
\r
291 if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n' && line[linelen]!='\r')
\r
299 if(!context->command_line && (context->input->used || context->output->used))
\r
301 snprintf(file_pos,256,"%s:%d",fstream->name, line_num);
\r
302 ERROR1("[%s] Error : no command found in the last chunk of lines", file_pos);
\r
304 unit_set_error(fstream->unit, ESYNTAX, 1, file_pos);
\r
309 else if(unit->is_running_suite)
\r
310 {/* it's the end of a suite */
\r
312 unit_t* current_suite = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1);
\r
314 if(!xbt_dynar_length((*current_suite)->includes))
\r
316 ERROR2("[%s] Malformated suite `(%s)' : include missing", file_pos, (*current_suite)->description);
\r
318 unit_set_error(*current_suite, ESYNTAX, 1, file_pos);
\r
324 unit->is_running_suite = 0;
\r
327 if(context->command_line)
\r
329 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
336 if(linelen>1 && line[linelen-2]=='\\')
\r
338 if(linelen>2 && line[linelen-3] == '\\')
\r
340 /* Damn. Escaped \ */
\r
341 line[linelen-2] = '\n';
\r
342 line[linelen-1] = '\0';
\r
346 to_be_continued = 1;
\r
347 line[linelen-2] = '\0';
\r
351 buffbegin = line_num;
\r
355 if(buff->used || to_be_continued)
\r
357 xbt_strbuff_append(buff,line);
\r
359 if (!to_be_continued)
\r
361 snprintf(file_pos,256,"%s:%d",fstream->name, buffbegin);
\r
362 fstream_lex_line(fstream, context, mutex, file_pos, buff->data);
\r
363 xbt_strbuff_empty(buff);
\r
368 snprintf(file_pos,256,"%s:%d",fstream->name, line_num);
\r
369 fstream_lex_line(fstream, context, mutex, file_pos, line);
\r
373 /* Check that last command of the file ran well */
\r
374 if(context->command_line)
\r
376 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
380 /* clear buffers */
\r
384 xbt_strbuff_free(buff);
\r
386 if(context_free(&context) < 0)
\r
389 return (exit_code || errno) ? -1 : 0;
\r
394 fstream_lex_line(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char * filepos, char *line)
\r
397 variable_t variable;
\r
399 char exp[VAR_NAME_MAX + 1] = {0};
\r
400 unit_t unit = fstream->unit;
\r
401 xbt_dynar_t variables = unit->runner->variables;
\r
405 char buff[VAR_NAME_MAX + 1] = {0};
\r
407 char delimiters[4] = {' ', '\t', '\n', '\0'};
\r
414 if(unit->is_running_suite && strncmp(line, "! include", strlen("! include")))
\r
415 {/* it's the end of a suite */
\r
417 unit_t* current_suite = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1);
\r
419 if(!xbt_dynar_length((*current_suite)->includes))
\r
420 ERROR2("[%s] Malformated suite `(%s)': include missing", filepos, (*current_suite)->description);
\r
422 ERROR2("[%s] Malformated suite `(%s)': blank line missing", filepos, (*current_suite)->description);
\r
424 unit_set_error(*current_suite, ESYNTAX, 1, filepos);
\r
426 failure(fstream->unit);
\r
429 context->line = strdup(filepos);
\r
432 xbt_str_rtrim(line + 2,"\n");
\r
434 line2 = strdup(line);
\r
436 len = strlen(line2 + 2) + 1;
\r
438 /* replace each variable by its value */
\r
439 xbt_os_mutex_acquire(unit->mutex);
\r
442 /* replace all existing
\r
451 xbt_dynar_foreach(variables, i, variable)
\r
453 if(!(p = strstr(line2 + 2, "${")))
\r
456 memset(buff, 0, len);
\r
458 sprintf(buff,"${%s",variable->name);
\r
461 if((p = strstr(line2 + 2, buff)))
\r
463 memset(buff, 0, len);
\r
467 while(*(p++) != '\0')
\r
475 if(buff[j - 1] != '}')
\r
477 xbt_os_mutex_release(unit->mutex);
\r
480 ERROR2("[%s] Syntax error : `%s'.",filepos, p - j);
\r
482 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
483 failure(fstream->unit);
\r
487 if((p = strstr(buff , ":=")))
\r
491 /* if the value of the variable is empty, update its value by the value*/
\r
494 end = strchr(p, '}');
\r
496 if(!end || (end == p))
\r
498 xbt_os_mutex_release(unit->mutex);
\r
501 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(buff, "${"));
\r
503 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
504 failure(fstream->unit);
\r
508 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
510 strncpy(val, p,(end - p));
\r
513 /* replace the expression by the expression of the value of the variable*/
\r
514 sprintf(exp, "${%s:=%s}", variable->name, val);
\r
517 str_replace_all(&line2, exp, variable->val, NULL);
\r
520 str_replace_all(&line2, exp, val, NULL);
\r
522 variable->val = strdup(val);
\r
525 memset(exp, 0, VAR_NAME_MAX + 1);
\r
534 else if((p = strstr(buff, ":-")))
\r
538 /* if the value of the variable is empty, replace the expression by the value */
\r
540 end = strchr(p, '}');
\r
542 if(!end || (end == p))
\r
544 xbt_os_mutex_release(unit->mutex);
\r
546 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
548 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
549 failure(fstream->unit);
\r
553 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
555 strncpy(val, p,(end - p));
\r
557 sprintf(exp, "${%s:-%s}", variable->name, val);
\r
559 str_replace_all(&line2, exp, variable->val ? variable->val : val, NULL);
\r
562 memset(exp, 0, VAR_NAME_MAX + 1);
\r
571 else if((p = strstr(buff, ":+")))
\r
575 /* if the value of the variable is not empty, replace the expression by the value */
\r
578 end = strchr(p, '}');
\r
580 if(!end || (end == p))
\r
582 xbt_os_mutex_release(unit->mutex);
\r
585 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
587 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
588 failure(fstream->unit);
\r
592 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
594 strncpy(val, p,(end - p));
\r
596 sprintf(exp, "${%s:+%s}", variable->name, val);
\r
600 str_replace_all(&line2, exp, val, NULL);
\r
604 str_replace_all(&line2, exp, NULL , NULL);
\r
605 variable->val = strdup(val);
\r
608 memset(exp, 0, VAR_NAME_MAX + 1);
\r
616 else if((p = strstr(buff, ":?")))
\r
620 /* if the value of the variable is not empty, replace the expression by the value */
\r
622 end = strchr(p, '}');
\r
624 if(!end || (end == p))
\r
626 xbt_os_mutex_release(unit->mutex);
\r
628 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
630 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
631 failure(fstream->unit);
\r
635 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
637 strncpy(val, p,(end - p));
\r
639 sprintf(exp, "${%s:?%s}", variable->name, val);
\r
642 str_replace_all(&line2, exp, variable->val, NULL);
\r
646 xbt_os_mutex_release(unit->mutex);
\r
648 ERROR2("[%s] %s.",filepos, val);
\r
650 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
651 failure(fstream->unit);
\r
655 memset(exp, 0, VAR_NAME_MAX + 1);
\r
666 /* replace all existing $var */
\r
667 xbt_dynar_foreach(variables, i, variable)
\r
669 if(!strchr(line2 + 2, '$'))
\r
672 if(strstr(line2 + 2, variable->name))
\r
675 sprintf(exp, "${#%s}", variable->name);
\r
677 if(strstr(line2 + 2, exp))
\r
682 char slen[4] = {0};
\r
683 sprintf(slen,"%d", (int)strlen(variable->val));
\r
684 str_replace_all(&line2, exp, slen, NULL);
\r
687 str_replace_all(&line2, exp, "0", NULL);
\r
690 memset(exp, 0, VAR_NAME_MAX + 1);
\r
692 sprintf(exp, "${%s}", variable->name);
\r
694 if(strstr(line2 + 2, exp))
\r
697 str_replace_all(&line2, exp, variable->val, NULL);
\r
699 str_replace_all(&line2, exp, NULL, NULL);
\r
702 memset(exp, 0, VAR_NAME_MAX + 1);
\r
704 sprintf(exp, "$%s", variable->name);
\r
706 if((p = strstr(line2 + 2, exp)))
\r
708 if((p + strlen(variable->name) + 1)[0] != '\0')
\r
709 delimiters[0] = (p + strlen(variable->name) + 1)[0];
\r
712 str_replace_all(&line2, exp, variable->val, delimiters);
\r
714 str_replace_all(&line2, exp, NULL, delimiters);
\r
717 memset(exp, 0, VAR_NAME_MAX + 1);
\r
722 while((p = strstr(line2 + 2, "${")))
\r
724 /*if(*(p+1) != '{')
\r
729 while(*(p++) != '\0')
\r
731 if(*p != ' ' && *p !='\t')
\r
738 str_replace_all(&line2, exp, NULL, " \t\n\r");
\r
739 memset(exp, 0, VAR_NAME_MAX + 1);
\r
744 char* begin = NULL;
\r
749 while(*(p++) != '\0')
\r
751 if((!begin && *p != ' ' && *p !='\t') || begin)
\r
753 /* `:' must be before this caracter, bad substitution : exit loop
\r
755 the current character is already present, bad substitution : exit loop
\r
759 *(p - 1) != ':' && (
\r
760 (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?')
\r
766 (*p == ':') || (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?')
\r
776 /* save the begining of the value */
\r
777 if((*(p+1) == '=') || (*(p+1) == '-') || (*(p+1) == '+') || (*(p+1) == '?'))
\r
786 /* the current char is `:' but the next is invalid, bad substitution : exit loop */
\r
789 /* end of the substitution : exit loop */
\r
797 if(exp[j - 1] == '}')
\r
804 if(4 == strlen(exp))
\r
806 xbt_os_mutex_release(unit->mutex);
\r
808 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
810 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
811 failure(fstream->unit);
\r
815 str_replace_all(&line2, exp, "0", NULL);
\r
817 else if(strstr(exp,":="))
\r
819 /* ${var:=value} */
\r
821 end = strchr(p, '}');
\r
823 if(!end || (end == begin))
\r
825 xbt_os_mutex_release(unit->mutex);
\r
828 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
830 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
831 failure(fstream->unit);
\r
835 variable = xbt_new0(s_variable_t, 1);
\r
837 variable->val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
839 strncpy(variable->val, begin ,(end - begin));
\r
842 end = strchr(exp, ':');
\r
844 if(!end || (end == begin))
\r
846 xbt_os_mutex_release(unit->mutex);
\r
849 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
851 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
852 failure(fstream->unit);
\r
856 variable->name = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
858 strncpy(variable->name, exp + 2 ,(end - begin));
\r
860 str_replace_all(&line2, exp, variable->val, NULL);
\r
862 xbt_dynar_push(variables, &variable);
\r
865 else if(strstr(exp,":-"))
\r
867 /* ${var:-value} */
\r
870 end = strchr(p, '}');
\r
872 if(!end || (end == begin))
\r
874 xbt_os_mutex_release(unit->mutex);
\r
877 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
879 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
880 failure(fstream->unit);
\r
884 val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
886 strncpy(val, begin ,(end - begin));
\r
888 str_replace_all(&line2, exp, val, NULL);
\r
894 else if(strstr(exp,":+"))
\r
896 /* ${var:+value} */
\r
898 end = strchr(p, '}');
\r
900 if(!end || (end == begin))
\r
902 xbt_os_mutex_release(unit->mutex);
\r
904 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
906 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
907 failure(fstream->unit);
\r
911 str_replace_all(&line2, exp, NULL, NULL);
\r
913 else if(strstr(exp,":?"))
\r
915 /* ${var:?value} */
\r
917 end = strchr(p, '}');
\r
919 if(!end || (end == begin))
\r
921 xbt_os_mutex_release(unit->mutex);
\r
923 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
925 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
926 failure(fstream->unit);
\r
930 val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
932 strncpy(val, begin ,(end - begin));
\r
934 xbt_os_mutex_release(unit->mutex);
\r
936 ERROR2("[%s] : `%s'.",filepos, val);
\r
941 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
942 failure(fstream->unit);
\r
951 if(3 == strlen(exp))
\r
953 xbt_os_mutex_release(unit->mutex);
\r
955 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
957 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
958 failure(fstream->unit);
\r
962 str_replace_all(&line2, exp, NULL, NULL);
\r
966 memset(exp, 0, VAR_NAME_MAX + 1);
\r
970 xbt_os_mutex_release(unit->mutex);
\r
972 if(strstr(line2 + 2, "${"))
\r
973 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
975 ERROR2("[%s] Syntax error : `%s'.",filepos, strstr(line2, "${"));
\r
977 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
978 failure(fstream->unit);
\r
990 if((p = strchr(p, '$')))
\r
997 while(*(p++) != '\0')
\r
999 if(*p != ' ' && *p !='\t')
\r
1006 str_replace_all(&line2, exp, NULL, " \t\n\r");
\r
1007 memset(exp, 0, VAR_NAME_MAX + 1);
\r
1011 /* maybe < $ cmd */
\r
1019 xbt_os_mutex_release(unit->mutex);
\r
1030 if(line[1] != ' ')
\r
1033 if(line2[0] == '$')
\r
1034 ERROR1("[%s] Missing space after `$' `(usage : $ <command>)'", filepos);
\r
1036 ERROR1("[%s] Missing space after & `(usage : & <command>)'", filepos);
\r
1038 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1044 context->async = (line2[0] == '&');
\r
1047 /* further trim useless chars which are significant for in/output */
\r
1048 xbt_str_rtrim(line2 + 2," \t");
\r
1050 /* deal with CD commands here, not in context */
\r
1051 if(!strncmp("cd ",line2 + 2, 3))
\r
1053 char* dir = strdup(line2 + 4);
\r
1055 if(context->command_line)
\r
1057 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
1061 /* search begining */
\r
1062 while(*(dir++) == ' ');
\r
1069 INFO2("[%s] cd %s", filepos, dir);
\r
1071 if(!just_print_flag)
\r
1075 ERROR3("[%s] Chdir to %s failed: %s",filepos, dir,error_to_string(errno, 0));
\r
1076 unit_set_error(fstream->unit, errno, 0, filepos);
\r
1087 fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2);
\r
1095 if(line[0] == '!' && line[1] != ' ')
\r
1097 ERROR1("[%s] Missing space after `!' `(usage : ! <command> [[=]value])'", filepos);
\r
1099 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1105 fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2);
\r
1114 char* prompt = line2 + 2;
\r
1116 for(j = 0; j < strlen(prompt); j++)
\r
1118 if (prompt[j] != ' ' && prompt[j] != '\t')
\r
1127 ERROR1("[%s] Bad usage of the metacommand p `(usage : p <prompt>)'", filepos);
\r
1129 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1136 INFO2("[%s] %s",filepos,prompt);
\r
1148 char* prompt = line2 + 2;
\r
1150 for(j = 0; j < strlen(prompt); j++)
\r
1151 if (prompt[j] != ' ' && prompt[j] != '\t')
\r
1156 ERROR1("[%s] Bad usage of the metacommand P `(usage : P <prompt>)'", filepos);
\r
1158 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1164 if(!dry_run_flag)
\r
1165 CRITICAL2("[%s] %s",filepos, prompt);
\r
1171 if(unit->description)
\r
1172 WARN2("[%s] Description already specified `%s'",filepos, line2 + 2);
\r
1178 char* desc = line2 + 2;
\r
1180 for(j = 0; j < strlen(desc); j++)
\r
1181 if (desc[j] != ' ' && desc[j] != '\t')
\r
1186 ERROR1("[%s] Bad usage of the metacommand D `(usage : D <Description>)'", filepos);
\r
1188 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1194 unit->description = strdup(desc);
\r
1199 ERROR2("[%s] Syntax error `%s'", filepos, line2);
\r
1200 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1209 fstream_process_token(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* filepos, char token, char *line)
\r
1211 unit_t unit = fstream->unit;
\r
1218 if(context->command_line)
\r
1221 if(context->output->used || context->input->used)
\r
1223 ERROR2("[%s] More than one command in this chunk of lines (previous: %s).\nDunno which input/output belongs to which command.",filepos, context->command_line);
\r
1225 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1230 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
1233 VERB1("[%s] More than one command in this chunk of lines",filepos);
\r
1240 for(j = 0; j < strlen(line); j++)
\r
1241 if (line[j] != ' ' && line[j] != '\t')
\r
1247 ERROR1("[%s] Undefinite command for `$' `(usage: $ <command>)'", filepos);
\r
1249 ERROR1("[%s] Undefinite command for `&' `(usage: & <command>)'", filepos);
\r
1251 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1258 context->command_line = strdup(line);
\r
1260 xbt_str_ltrim(context->command_line," ");
\r
1262 context->line = /*strdup(filepos)*/ filepos;
\r
1263 context->pos = strdup(filepos);
\r
1268 /* translate the command line */
\r
1272 char command_line[PATH_MAX + 1] = {0};
\r
1274 char* args = NULL;
\r
1278 if(strstr(context->command_line,".exe"))
\r
1279 strcpy(command_line,context->command_line);
\r
1286 len = strlen(context->command_line);
\r
1290 if(context->command_line[i] != ' ' && context->command_line[i] != '\t' && context->command_line[i] != '>')
\r
1291 command_line[j++] = context->command_line[i];
\r
1298 strcat(command_line,".exe");
\r
1300 args = strdup(context->command_line + i);
\r
1303 if(getpath(command_line, &path) && !is_w32_cmd(command_line, fstream->unit->runner->path))
\r
1305 ERROR3("[%s] `%s' : NOK (%s)", filepos, context->command_line, error_to_string(ECMDNOTFOUND, 1));
\r
1306 unit_set_error(fstream->unit, ECMDNOTFOUND, 1, filepos);
\r
1311 delimiter = strrchr(command_line,'/');
\r
1314 delimiter = strrchr(command_line,'\\');
\r
1316 /*free(context->command_line);*/
\r
1323 context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + strlen(args) + 2, sizeof(char));
\r
1324 sprintf(context->t_command_line,"%s\\%s%s",path,delimiter ? delimiter + 1 : command_line, args);
\r
1331 context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + 2, sizeof(char));
\r
1332 sprintf(context->t_command_line,"%s\\%s",path,delimiter ? delimiter + 1 : command_line);
\r
1341 context->t_command_line = (char*)calloc(strlen(command_line) + strlen(args) + 1, sizeof(char));
\r
1342 sprintf(context->t_command_line,"%s%s",command_line, args);
\r
1349 context->t_command_line = (char*)calloc(strlen(command_line) + 1, sizeof(char));
\r
1350 strcpy(context->t_command_line,command_line);
\r
1362 xbt_strbuff_append(context->input,line);
\r
1363 xbt_strbuff_append(context->input,"\n");
\r
1367 xbt_strbuff_append(context->output,line);
\r
1368 xbt_strbuff_append(context->output,"\n");
\r
1373 if(context->command_line)
\r
1375 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
1379 if(!strncmp(line,"timeout no",strlen("timeout no")))
\r
1381 VERB1("[%s] (disable timeout)", filepos);
\r
1382 context->timeout = INDEFINITE;
\r
1384 else if(!strncmp(line,"timeout ",strlen("timeout ")))
\r
1389 char* p = line + strlen("timeout ");
\r
1392 for(j = 0; j < strlen(p); j++)
\r
1393 if (p[j] != ' ' && p[j] != '\t')
\r
1398 ERROR1("[%s] Undefinite timeout value `(usage :timeout <seconds>)'", filepos);
\r
1400 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1406 while(p[i] != '\0')
\r
1408 if(!isdigit(p[i]))
\r
1410 ERROR2("[%s] Invalid timeout value `(%s)' : `(usage :timeout <seconds>)'", filepos, line + strlen("timeout "));
\r
1412 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1421 context->timeout = atoi(line + strlen("timeout"));
\r
1422 VERB2("[%s] (new timeout value: %d)",filepos,context->timeout);
\r
1425 else if (!strncmp(line,"expect signal ",strlen("expect signal ")))
\r
1431 char* p = line + strlen("expect signal ");
\r
1434 for(j = 0; j < strlen(p); j++)
\r
1435 if (p[j] != ' ' && p[j] != '\t')
\r
1440 ERROR1("[%s] Undefinite signal name `(usage :expect signal <signal name>)'", filepos);
\r
1442 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1448 context->signal = strdup(line + strlen("expect signal "));
\r
1450 xbt_str_trim(context->signal," \n");
\r
1453 if(!strstr("SIGSEGVSIGTRAPSIGBUSSIGFPESIGILL", context->signal))
\r
1455 ERROR2("[%s] Signal `%s' not supported by this platform", filepos, context->signal);
\r
1457 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1464 if(!sig_exists(context->signal))
\r
1466 ERROR2("[%s] Signal `%s' not supported by Tesh", filepos, context->signal);
\r
1468 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1478 VERB2("[%s] (next command must raise signal %s)", filepos, context->signal);
\r
1481 else if (!strncmp(line,"expect return ",strlen("expect return ")))
\r
1487 char* p = line + strlen("expect return ");
\r
1490 for(j = 0; j < strlen(p); j++)
\r
1491 if (p[j] != ' ' && p[j] != '\t')
\r
1496 ERROR1("[%s] Undefinite return value `(usage :expect return <return value>)'", filepos);
\r
1498 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1504 while(p[i] != '\0')
\r
1506 if(!isdigit(p[i]))
\r
1508 ERROR2("[%s] Invalid exit code value `(%s)' : must be an integer >= 0 and <=255", filepos, line + strlen("expect return "));
\r
1510 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1519 context->exit_code = atoi(line+strlen("expect return "));
\r
1520 VERB2("[%s] (next command must return code %d)",filepos, context->exit_code);
\r
1523 else if (!strncmp(line,"output ignore",strlen("output ignore")))
\r
1525 context->output_handling = oh_ignore;
\r
1526 VERB1("[%s] (ignore output of next command)", filepos);
\r
1529 else if (!strncmp(line,"output display",strlen("output display")))
\r
1531 context->output_handling = oh_display;
\r
1532 VERB1("[%s] (ignore output of next command)", filepos);
\r
1535 else if(!strncmp(line,"include ", strlen("include ")))
\r
1540 p1 = line + strlen("include");
\r
1542 while(*p1 == ' ' || *p1 == '\t')
\r
1548 ERROR1("[%s] no file specified : `(usage : include <file> [<description>])'", filepos);
\r
1550 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1557 char file_name[PATH_MAX + 1] = {0};
\r
1561 while(*p2 != '\0' && *p2 != ' ' && *p2 != '\t')
\r
1564 strncpy(file_name, p1, p2 - p1);
\r
1568 while(*p2 == ' ' || *p2 == '\t')
\r
1571 fstream_handle_include(fstream, context, mutex, file_name, p2[0] != '\0' ? p2 : NULL);
\r
1575 else if(!strncmp(line,"suite ", strlen("suite ")))
\r
1579 char* p = line + strlen("suite ");
\r
1582 for(j = 0; j < strlen(p); j++)
\r
1583 if (p[j] != ' ' && p[j] != '\t')
\r
1588 ERROR1("[%s] Undefinite suit description : `(usage : suite <description>)", filepos);
\r
1590 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1596 if(unit->is_running_suite)
\r
1598 ERROR1("[%s] Suite already in progress", filepos);
\r
1600 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1606 fstream_handle_suite(fstream, line + strlen("suite "), filepos);
\r
1608 else if(!strncmp(line,"unsetenv ", strlen("unsetenv ")))
\r
1610 unsigned int i, j;
\r
1614 variable_t variable;
\r
1617 char* name = line + strlen("unsetenv ");
\r
1621 for(j = 0; j < strlen(name); j++)
\r
1622 if (name[j] != ' ' && name[j] != '\t')
\r
1627 ERROR1("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", filepos);
\r
1629 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1635 xbt_os_mutex_acquire(unit->mutex);
\r
1638 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1640 if(!strcmp(variable->name, name))
\r
1642 env = variable->env;
\r
1643 err = variable->err;
\r
1656 SetEnvironmentVariable(name, NULL);
\r
1658 xbt_dynar_cursor_rm(unit->runner->variables, &i);
\r
1662 ERROR2("[%s] `(%s)' environment variable not found : impossible to unset it",filepos, name);
\r
1663 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1664 xbt_os_mutex_release(unit->mutex);
\r
1675 ERROR2("[%s] `(%s)' is not an environment variable : use `unset' instead `unsetenv'",filepos, name);
\r
1676 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1678 xbt_os_mutex_release(unit->mutex);
\r
1683 ERROR2("[%s] `(%s)' is not an environment variable (it's a system variable) : impossible to unset it",filepos, name);
\r
1684 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1685 xbt_os_mutex_release(unit->mutex);
\r
1692 ERROR2("[%s] `(%s)' environment variable not found : impossible to unset it",filepos, name);
\r
1693 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1694 xbt_os_mutex_release(unit->mutex);
\r
1700 xbt_os_mutex_release(unit->mutex);
\r
1704 else if(!strncmp(line,"setenv ", strlen("setenv ")))
\r
1707 char name[PATH_MAX + 1] = {0};
\r
1713 p = line + strlen("setenv ");
\r
1715 val = strchr(p, '=');
\r
1719 variable_t variable;
\r
1725 /* syntax error */
\r
1726 if(val[0] == '\0' || val[0] ==' ' || val[0] =='\t')
\r
1728 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
1730 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1738 strncpy(name, p, (val - p -1));
\r
1742 for(j = 0; j < strlen(name); j++)
\r
1743 if (name[j] != ' ' && name[j] != '\t')
\r
1749 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
1751 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1757 /* test if the variable is already registred */
\r
1758 xbt_os_mutex_acquire(unit->mutex);
\r
1760 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1762 if(!strcmp(variable->name, name))
\r
1764 env = variable->env;
\r
1765 err = variable->err;
\r
1771 /* if the variable is already registred, update its value;
\r
1772 * otherwise register it.
\r
1778 if(!strcmp(val, variable->val))
\r
1779 WARN3("[%s] This environment variable `(%s)' is already set with the value `(%s)'", filepos, name, val);
\r
1781 free(variable->val);
\r
1782 variable->val = strdup(val);
\r
1785 SetEnvironmentVariable(variable->name, variable->val);
\r
1787 setenv(variable->name, variable->val, 1);
\r
1793 ERROR2("[%s] Conflict : a system variable `(%s)' already exists", filepos, name);
\r
1795 ERROR2("[%s] Conflict : (none environment) variable `(%s)' already exists", filepos, name);
\r
1797 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1798 xbt_os_mutex_release(unit->mutex);
\r
1807 ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name);
\r
1809 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1810 xbt_os_mutex_release(unit->mutex);
\r
1816 variable = variable_new(name, val);
\r
1817 variable->env = 1;
\r
1819 xbt_dynar_push(unit->runner->variables, &variable);
\r
1822 SetEnvironmentVariable(variable->name, variable->val);
\r
1824 setenv(variable->name, variable->val, 0);
\r
1829 xbt_os_mutex_release(unit->mutex);
\r
1834 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
1836 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1841 else if(!strncmp(line,"unset ", strlen("unset ")))
\r
1843 unsigned int i, j;
\r
1847 variable_t variable;
\r
1850 char* name = line + strlen("unset ");
\r
1854 for(j = 0; j < strlen(name); j++)
\r
1855 if (name[j] != ' ' && name[j] != '\t')
\r
1861 ERROR1("[%s] Bad usage of the metacommand unset `(usage : unset variable)'", filepos);
\r
1863 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1870 xbt_os_mutex_acquire(unit->mutex);
\r
1872 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1874 if(!strcmp(variable->name, name))
\r
1876 env = variable->env;
\r
1877 err = variable->err;
\r
1887 /*xbt_dynar_remove_at(unit->runner->variables, i, NULL);*/
\r
1888 /*xbt_dynar_cursor_rm(unit->runner->variables, &i);*/
\r
1891 free(variable->val);
\r
1892 variable->val = NULL;
\r
1896 WARN2("[%s] Variable `(%s)' already unseted",filepos, variable->name);
\r
1901 ERROR2("[%s] `(%s)' variable not found",filepos, name);
\r
1902 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1903 xbt_os_mutex_release(unit->mutex);
\r
1910 ERROR2("[%s] `(%s)' is an environment variable use `unsetenv' instead `unset'",filepos, name);
\r
1911 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1912 xbt_os_mutex_release(unit->mutex);
\r
1918 ERROR2("[%s] `(%s)' is system variable : you can unset it",filepos, name);
\r
1919 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1920 xbt_os_mutex_release(unit->mutex);
\r
1925 xbt_os_mutex_release(unit->mutex);
\r
1928 else if(!strncmp(line,"set ", strlen("set ")))
\r
1931 char name[PATH_MAX + 1] = {0};
\r
1935 val = strchr(line + strlen("set "), '=');
\r
1939 variable_t variable;
\r
1948 /* syntax error */
\r
1949 if(val[0] == '\0')
\r
1951 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
1953 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1958 else if(val[0] ==' ' || val[0] =='\t')
\r
1960 strncpy(name, line + strlen("set "), (val - (line + strlen("set "))));
\r
1962 ERROR2("[%s] No space avaible after`(%s)'", filepos, name);
\r
1964 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1971 /* assume it's a varibale */
\r
1973 strncpy(name, line + strlen("set "), (val - (line + strlen("set ")) -1));
\r
1977 for(j = 0; j < strlen(name); j++)
\r
1978 if (name[j] != ' ' && name[j] != '\t')
\r
1984 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
1986 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1992 xbt_os_mutex_acquire(unit->mutex);
\r
1994 /* test if the variable is already registred */
\r
1995 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1997 if(!strcmp(variable->name, name))
\r
2000 err = variable->err;
\r
2001 env = variable->env;
\r
2006 /* if the variable is already registred, update its value (if same value warns);
\r
2007 * otherwise register it.
\r
2013 ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name);
\r
2015 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2016 xbt_os_mutex_release(unit->mutex);
\r
2023 ERROR2("[%s] `(%s)' is an environment variable use `setenv' instead `set'", filepos, name);
\r
2025 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2026 xbt_os_mutex_release(unit->mutex);
\r
2033 if(!strcmp(val, variable->val))
\r
2034 WARN3("[%s] Variable `(%s)' already contains value `<%s>'",filepos, variable->name, val);
\r
2036 free(variable->val);
\r
2037 variable->val = strdup(val);
\r
2042 variable_t new_var = variable_new(name, val);
\r
2043 xbt_dynar_push(unit->runner->variables, &new_var);
\r
2047 xbt_os_mutex_release(unit->mutex);
\r
2051 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
2053 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2059 {/* assume it's a variable */
\r
2061 char name[PATH_MAX + 1] = {0};
\r
2062 unsigned int i, j;
\r
2065 val = strchr(line, '=');
\r
2069 variable_t variable;
\r
2076 /* syntax error */
\r
2077 if(val[0] == '\0')
\r
2079 strncpy(name, line, (val - line -1));
\r
2083 for(j = 0; j < strlen(name); j++)
\r
2084 if (name[j] != ' ' && name[j] != '\t')
\r
2088 ERROR1("[%s] Bad usage of Tesh variable mechanism `(usage : variable=value)'", filepos);
\r
2089 else if(!strcmp("setenv", name))
\r
2090 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
2091 else if(!strcmp("set", name))
\r
2092 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
2094 ERROR2("[%s] Undefined variable `(%s)'", filepos, name);
\r
2096 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2101 else if(val[0] ==' ' || val[0] =='\t')
\r
2103 strncpy(name, line, (val - line));
\r
2105 ERROR2("[%s] No space avaible after`(%s)'", filepos, name);
\r
2107 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2113 /* assume it's a varibale */
\r
2115 strncpy(name, line, (val - line -1));
\r
2119 for(j = 0; j < strlen(name); j++)
\r
2120 if (name[j] != ' ' && name[j] != '\t')
\r
2126 ERROR1("[%s] Bad usage of Tesh variable capability `(usage : variable=value)'", filepos);
\r
2128 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2134 if(!strcmp("set", name))
\r
2136 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
2138 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2142 else if(!strcmp("setenv", name))
\r
2144 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
2146 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2151 xbt_os_mutex_acquire(unit->mutex);
\r
2153 /* test if the variable is already registred */
\r
2154 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
2156 if(!strcmp(variable->name, name))
\r
2159 err = variable->err;
\r
2160 env = variable->env;
\r
2165 /* if the variable is already registred, update its value (if same value warns);
\r
2166 * otherwise register it.
\r
2172 ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name);
\r
2174 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2175 xbt_os_mutex_release(unit->mutex);
\r
2181 ERROR2("[%s] `(%s)' is an environment variable use `setenv' metacommand", filepos, name);
\r
2183 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2184 xbt_os_mutex_release(unit->mutex);
\r
2191 if(!strcmp(val, variable->val))
\r
2192 WARN3("[%s] Variable `(%s)' already contains value `<%s>'",filepos, variable->name, val);
\r
2194 free(variable->val);
\r
2195 variable->val = strdup(val);
\r
2200 variable_t new_var = variable_new(name, val);
\r
2201 xbt_dynar_push(unit->runner->variables, &new_var);
\r
2205 xbt_os_mutex_release(unit->mutex);
\r
2210 if(!strncmp("setenv", line, strlen("setenv")))
\r
2211 ERROR1("[%s] Bad usage of the metacommand setenv : `(usage : setenv variable=value)'", filepos);
\r
2212 else if(!strncmp("set", line, strlen("set")))
\r
2213 ERROR1("[%s] Bad usage of the metacommand set : `(usage : set variable=value)'", filepos);
\r
2214 else if(!strncmp("unsetenv", line, strlen("unsetenv")))
\r
2215 ERROR1("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", filepos);
\r
2216 else if(!strncmp("unset", line, strlen("unset")))
\r
2217 ERROR1("[%s] Bad usage of the metacommand unset : `(usage : unset variable)'", filepos);
\r
2218 else if(!strncmp("timeout", line, strlen("timeout")))
\r
2219 ERROR1("[%s] Bad usage of the metacommand timeout : `(usage : timeout <integral positive integer>)'", filepos);
\r
2220 else if(!strncmp("expect signal", line, strlen("expect signal")))
\r
2221 ERROR1("[%s] Bad usage of the metacommand expect signal : `(usage : expect signal <sig_name>)'", filepos);
\r
2222 else if(!strncmp("expect return", line, strlen("expect return")))
\r
2223 ERROR1("[%s] Bad usage of the metacommand expect return : `(usage : expect return <return value (>=0 <=255)>)'", filepos);
\r
2224 else if(!strncmp("include", line, strlen("include")))
\r
2225 ERROR1("[%s] Bad usage of the metacommand include :`(usage : include <file> [<description>])'", filepos);
\r
2226 else if(!strncmp("suite", line, strlen("suite")))
\r
2227 ERROR1("[%s] Bad usage of the metacommand suite : `(usage : suite <description>)'", filepos);
\r
2229 ERROR2("[%s] Unknown metacommand: `%s'",filepos,line);
\r
2231 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2243 fstream_handle_include(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* file_name, const char* description)
\r
2246 char* prev_directory = NULL;
\r
2247 fstream_t _fstream = NULL;
\r
2248 struct stat buffer = {0};
\r
2249 unit_t unit = fstream->unit;
\r
2251 if(!stat(file_name, &buffer) && S_ISREG(buffer.st_mode))
\r
2253 /* the file is in the current directory */
\r
2254 _fstream = fstream_new(getcwd(NULL, 0), file_name);
\r
2255 fstream_open(_fstream);
\r
2257 /* the file to include is not in the current directory, check if it is in a include directory */
\r
2261 prev_directory = getcwd(NULL, 0);
\r
2263 xbt_dynar_foreach(include_dirs, i, dir)
\r
2267 if(!stat(file_name, &buffer) && S_ISREG(buffer.st_mode))
\r
2269 _fstream = fstream_new(dir->name, file_name);
\r
2270 fstream_open(_fstream);
\r
2275 chdir(prev_directory);
\r
2276 free(prev_directory);
\r
2279 /* the file to include is not found handle the failure */
\r
2282 if(file_name[0] == '$')
\r
2284 ERROR3("[%s] Include file `(%s)' not found or variable `(%s)' doesn't exist",context->line, file_name, file_name + 1);
\r
2289 /* may be a variable */
\r
2290 variable_t variable;
\r
2294 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
2296 if(!strcmp(variable->name, file_name))
\r
2304 ERROR3("[%s] Include file `(%s)' not found (if you want to use the variable <%s> add the prefix `$')",context->line, file_name, file_name);
\r
2306 ERROR2("[%s] Include file `(%s)' not found",context->line, file_name);
\r
2309 unit_set_error(fstream->unit, EINCLUDENOTFOUND, 1, context->line);
\r
2311 failure(fstream->unit);
\r
2317 if(!unit->is_running_suite)
\r
2318 {/* it's the unit of a suite */
\r
2319 unit_t include = unit_new(unit->runner, unit->root, unit, _fstream);
\r
2321 include->mutex = unit->root->mutex;
\r
2324 include->description = strdup(description);
\r
2326 xbt_dynar_push(unit->includes, &include);
\r
2331 INFO2("Include from %s (%s)", _fstream->name, description);
\r
2333 INFO1("Include from %s", _fstream->name);
\r
2337 INFO1("Checking include %s...",_fstream->name);
\r
2339 fstream_parse(_fstream, mutex);
\r
2342 {/* it's a include */
\r
2347 owner = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1);
\r
2349 include = unit_new(unit->runner, unit->root, *owner, _fstream);
\r
2351 include->mutex = unit->root->mutex;
\r
2354 include->description = strdup(description);
\r
2356 xbt_dynar_push((*owner)->includes, &include);
\r
2361 INFO2("Include from %s (%s)", _fstream->name, description);
\r
2363 INFO1("Include from %s", _fstream->name);
\r
2366 INFO1("Checking include %s...",_fstream->name);
\r
2368 fstream_parse(_fstream, mutex);
\r
2374 fstream_handle_suite(fstream_t fstream, const char* description, const char* filepos)
\r
2376 unit_t unit = fstream->unit;
\r
2377 unit_t suite = unit_new(unit->runner, unit->root, unit, NULL);
\r
2380 suite->description = strdup(description);
\r
2382 suite->filepos = strdup(filepos);
\r
2384 xbt_dynar_push(unit->suites, &suite);
\r
2385 unit->is_running_suite = 1;
\r
2388 INFO1("Test suite %s", description);
\r
2390 INFO1("Checking suite %s...",description);
\r
2395 fstream_launch_command(fstream_t fstream, context_t context, xbt_os_mutex_t mutex)
\r
2397 unit_t unit = fstream->unit;
\r
2401 command_t command;
\r
2403 if(!(command = command_new(unit, context, mutex)))
\r
2405 if(EINVAL == errno)
\r
2407 ERROR3("[%s] Cannot instantiate the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2409 unit_set_error(unit, errno, 0, context->pos);
\r
2413 else if(ENOMEM == errno)
\r
2415 ERROR3("[%s] Cannot instantiate the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2417 unit_set_error(unit, errno, 0, context->pos);
\r
2424 if(command_run(command) < 0)
\r
2426 ERROR3("[%s] Cannot run the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2427 unit_set_error(unit, errno, 0, context->pos);
\r
2433 if(context_reset(context) < 0)
\r
2435 ERROR3("[%s] Cannot reset the context of the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2437 unit_set_error(fstream->unit, errno, 0, context->pos);
\r