Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal.h File Reference

Go to the source code of this file.

Data Structures

struct  test_case_info_tag
 

Macros

#define __INTERNAL_H_8DED3586_3931_4BD5_A578_3B8B6082391C_INCLUDED
 

Typedefs

typedef RESULT(* parse_config_attribute_function )(const TCHAR *parameter_name, const TCHAR *parameter_optipons, test_case_info *test_case_params)
 

Variables

int g_first
 

Basic definitions

These macros are used to define basic constants in the code.

#define LOGO_NAME   "lhogho"
 
#define TARGET_FILE_EXTENSION   "lgo"
 
#define SHELL_FILE_EXTENSION   "sh"
 
#define EXPECTED_RESULTS_EXT   "expected"
 
#define REAL_RESULTS_EXT   "real"
 
#define ERROR_RESULTS_EXT   "stderr"
 
#define LTEMP_EXT   "ltemp"
 
#define MAX_LINE_LENGTH   2048
 
#define MAX_NAME_LEN   1024
 
#define EXPECTED_MEMORY   TEXT("{MEM#0:0}")
 
#define MEMORY_CHECK_OPTION   "-Zm"
 
#define PARAM_SET_SYMBOL   TEXT('=')
 
#define SPACE_ESC_SYMBOL   TEXT('\"')
 
#define COMMENT_SYMBOL   TEXT(';')
 

Config file data types

These struct contains data from parameters written into test case file.

typedef struct test_case_info_tag test_case_info
 

String functions prototypes

See source code for details

int m_strcmp (const TCHAR *str1, const TCHAR *str2)
 compares two strings More...
 
TCHARm_strcpy (TCHAR *dest, const TCHAR *src)
 copy string More...
 
BOOL m_isspace (TCHAR chr)
 test if char is space More...
 
RESULT m_strdup (TCHAR **dest_ptr, const TCHAR *src)
 duplicate string. Allocate memory for destination More...
 
RESULT m_strndup (TCHAR **dest_ptr, const TCHAR *src, size_t num_chars)
 duplicate string, but no more than num_chars symbols More...
 
size_t m_strlen (const TCHAR *str)
 calculates string length More...
 
TCHARm_fgets (FILE *file, TCHAR *buffer, size_t buffer_size, size_t *out_size_ptr)
 Read a line from file. More...
 
void m_fputs (FILE *file, const TCHAR *buffer)
 prints a line to file More...
 
void m_fputs_ascii (FILE *file, const char *buffer)
 prints a line to file, convert it to UNICODE if needed More...
 
void m_fputc (FILE *file, TCHAR tchar)
 prints a symbol to file More...
 

Internal tester helper functions prototypes

See source code for details

RESULT parse_line (FILE *input_file, TCHAR **parameter_name, TCHAR **parameter_optipons)
 Parse a comment line in the test case file. More...
 
RESULT extract_args (FILE *input_file, test_case_info *test_info)
 Extracts all argument pairs from test case file. More...
 
RESULT extract_expected_results (FILE *input_file, const char *file_name)
 Extract value for expected results from test case file. More...
 
RESULT execute_test (const char *file_name, test_case_info test_info)
 Execute a test case. More...
 
RESULT compile_test (const char *file_name, test_case_info test_info)
 Compile test case file to executable. More...
 
RESULT check_results (const char *file_name, test_case_info test_info, UINT32 exec_result)
 Check results from test case execution. More...
 
RESULT import_results (const char *file_name, test_case_info test_info)
 Import results from test execution into test case file. More...
 
void clean_up (const char *file_name)
 Clean up any temporary data from test execution. More...
 
void print_file (const char *file_name, FILE *output)
 prints a file to the end of another one More...
 
RESULT file_compare (const char *test_file_name, test_case_info test_info)
 Compare result file with one expected. More...
 
RESULT exec_shell (const char *file_name)
 Execute a shell script with name same as test file name. More...
 

Macro Definition Documentation

#define __INTERNAL_H_8DED3586_3931_4BD5_A578_3B8B6082391C_INCLUDED

Definition at line 23 of file internal.h.

#define LOGO_NAME   "lhogho"

Definition at line 31 of file internal.h.

#define TARGET_FILE_EXTENSION   "lgo"

Definition at line 32 of file internal.h.

#define SHELL_FILE_EXTENSION   "sh"

Definition at line 33 of file internal.h.

#define EXPECTED_RESULTS_EXT   "expected"

Definition at line 34 of file internal.h.

#define REAL_RESULTS_EXT   "real"

Definition at line 35 of file internal.h.

#define ERROR_RESULTS_EXT   "stderr"

Definition at line 36 of file internal.h.

#define LTEMP_EXT   "ltemp"

Definition at line 37 of file internal.h.

#define MAX_LINE_LENGTH   2048

Definition at line 38 of file internal.h.

#define MAX_NAME_LEN   1024

Definition at line 39 of file internal.h.

#define EXPECTED_MEMORY   TEXT("{MEM#0:0}")

Definition at line 41 of file internal.h.

#define MEMORY_CHECK_OPTION   "-Zm"

Definition at line 42 of file internal.h.

#define PARAM_SET_SYMBOL   TEXT('=')

Definition at line 44 of file internal.h.

#define SPACE_ESC_SYMBOL   TEXT('\"')

Definition at line 45 of file internal.h.

#define COMMENT_SYMBOL   TEXT(';')

Definition at line 46 of file internal.h.

Typedef Documentation

typedef RESULT(* parse_config_attribute_function)(const TCHAR *parameter_name, const TCHAR *parameter_optipons, test_case_info *test_case_params)

Definition at line 65 of file internal.h.

Function Documentation

int m_strcmp ( const TCHAR str1,
const TCHAR str2 
)
Parameters
str1first string
str2second string
Returns
comparison result similar to standart strcmp result

Comare two strings. Return negative value if first is less than second positive value if first is great than second and zero if strings are equal

Definition at line 54 of file string_functions.c.

55 {
56  while (*str1 && *str1 == *str2)
57  {
58  ++str1;
59  ++str2;
60  }
61  return *str1 - *str2;
62 }
TCHAR * m_strcpy ( TCHAR dest,
const TCHAR src 
)
Parameters
destdestination string
srcsource string
Returns
pointer to destination

Copy string value to given pointer. User must supply enought memory

Definition at line 75 of file string_functions.c.

76 {
77  TCHAR * mem = dest;
78  while (*src)
79  {
80  *dest++ = *src++;
81  }
82  *dest = 0;
83  return mem;
84 }
BOOL m_isspace ( TCHAR  chr)
Parameters
chrchar to test
Returns
result of the test

Test if symbol is space symbol (Space, new line or tab)

Definition at line 95 of file string_functions.c.

96 {
97  return (chr == TEXT(' ') || chr == TEXT('\t') ||
98  chr == TEXT('\r') || chr == TEXT('\n'));
99 }
RESULT m_strdup ( TCHAR **  dest_ptr,
const TCHAR src 
)
Parameters
dest_ptrpointer to destination string
srcsource string
Returns
RESULT value. Error on memory problems

Duplicate string. Allocate memory for destination. If memory problems occured return error.

Definition at line 137 of file string_functions.c.

138 {
139  size_t len = m_strlen(src);
140  return m_strndup(dest_ptr, src, len);
141 }
RESULT m_strndup ( TCHAR **  dest_ptr,
const TCHAR src,
size_t  num_chars 
)
Parameters
dest_ptrpointer to destination string
srcsource string
num_charsnumber of characters to copy.
Returns
RESULT value. Error on memory problems

Copy string value to given pointer, byt no more than num_chars symbols. Allocates memory for destination. Not copy the 0 byte if source is longer than wanted length

Definition at line 114 of file string_functions.c.

115 {
116  *dest_ptr = (TCHAR *)malloc((num_chars + 1) * sizeof(TCHAR));
117  if (!*dest_ptr)
118  {
119  return ERR_MEMORY;
120  }
121  memcpy(*dest_ptr, src, num_chars * sizeof(TCHAR));
122  (*dest_ptr)[num_chars] = 0;
123  return SUCCESS_FULL;
124 }
size_t m_strlen ( const TCHAR str)
Parameters
strthe string
Returns
length of the string in symbols

Calculates string length in symbols. Works with char and w_char

Definition at line 34 of file string_functions.c.

35 {
36  const TCHAR * start = str;
37  while (*str) ++str;
38  return str - start;
39 }
TCHAR * m_fgets ( FILE *  file,
TCHAR buffer,
size_t  buffer_size,
size_t *  out_size_ptr 
)
Parameters
filefile to read from
bufferbuffer to read in
buffer_sizesize of space in the buffer
out_size_ptrsize of line readed
Returns
pointer to readed string or NULL if error

Read characters from given open file until new line symbol is reached or input buffer is full. Returns the count of really readed symbols in parameter and pointer to the buffer. If error occured during read process returns NULL

Definition at line 159 of file string_functions.c.

160 {
161  TCHAR c = 0;
162  size_t pos = 0;
163  if (!file || !buffer || !buffer_size || !out_size_ptr)
164  {
165  LOG_ERROR("Invalid args supplied to m_fgets");
166  if (out_size_ptr)
167  {
168  *out_size_ptr = 0;
169  }
170  return NULL;
171  }
172 
173  while (pos < buffer_size - 1)
174  {
175  if (!fread(&c, sizeof(TCHAR), 1, file))
176  {
177  break;
178  }
179  buffer[pos++] = c;
180 
181  if (c == TEXT('\r') || c == TEXT('\n'))
182  {
183  TCHAR c1;
184  size_t readed;
185  if ((readed = fread(&c1, sizeof(TCHAR), 1, file)) &&
186  (c1 == TEXT('\r') || c1 == TEXT('\n')) && c1 != c)
187  {
188  buffer[pos++] = c1;
189  }
190  else
191  {
192  if (readed)
193  {
194  fseek(file, -1l, SEEK_CUR);
195  }
196  }
197  break;
198  }
199  }
200 
201  buffer[pos] = 0;
202  *out_size_ptr = pos;
203  return pos ? buffer : NULL;
204 }
void m_fputs ( FILE *  file,
const TCHAR buffer 
)
Parameters
filefile to write in
bufferstring to write

Writes a line to the file. Buffer must be a valid nul-terminated string

Definition at line 216 of file string_functions.c.

217 {
218  size_t len = m_strlen(buffer);
219  fwrite(buffer, sizeof(TCHAR), len, file);
220 }
void m_fputs_ascii ( FILE *  file,
const char *  buffer 
)
Parameters
filefile to write in
bufferstring to write

Writes a line to the file. If program works in unicode mode the string is converted from ASCII to unicode.

Definition at line 232 of file string_functions.c.

233 {
234  char * buf = (char *)buffer;
235  size_t len = strlen(buffer) * sizeof(TCHAR);
236 
237 #if defined(UNICODE)
238  buf = (char*)malloc(len);
239  while (*buffer) *buf++ = *buffer++, *buf++ = 0;
240 #endif
241  fwrite(buf, sizeof(TCHAR), len, file);
242 
243 #if defined(UNICODE)
244  free(buf);
245 #endif
246 }
void m_fputc ( FILE *  file,
TCHAR  tchar 
)
Parameters
filefile to write in
tcharsymbol to write

Writes a symbol to file.

Definition at line 258 of file string_functions.c.

259 {
260 #if defined (UNICODE)
261  putwc(tchar, file);
262 #else
263  putc(tchar, file);
264 #endif
265 }
RESULT parse_line ( FILE *  input_file,
TCHAR **  parameter_name,
TCHAR **  parameter_optipons 
)
Parameters
input_filefile to read from
parameter_namename of the parameter readed
parameter_optiponspointer to data assigned to the parameter
Returns
RESULT value. See error.h for details

Read a comment line from test case file. If line describes valid parameter-value pair assignes name of parameter to parameter_name and option value to parameter_optipons Allocates memory for them. If line is empty return SUCCESS_EMPTY value If other error occurs return some error value.

Definition at line 51 of file tester_internal.c.

52 {
53  TCHAR buffer[MAX_LINE_LENGTH];
54  TCHAR * str, *start, *end;
55  size_t read_size;
56 
57  m_fgets(input_file, buffer, MAX_LINE_LENGTH, &read_size);
58  if (!read_size)
59  {
60  return SUCCESS_EMPTY;
61  }
62  str = buffer;
63  while (*str && m_isspace(*str))
64  {
65  ++str;
66  }
67  if (!*str)
68  {
69  return SUCCESS_EMPTY;
70  }
71 
72  // Skiping shell comments
73  if (str[0] == '#' && str[1] == '!' && g_first)
74  {
75  g_first = 0;
76  return parse_line(input_file, parameter_name, parameter_optipons);
77  }
78 
79  if (*str != COMMENT_SYMBOL)
80  {
81  LOG_ERROR("parse_line - no comment line");
82  return ERR_GENERIC;
83  }
84 
85  while (*str == COMMENT_SYMBOL || m_isspace(*str))
86  {
87  ++str;
88  }
89 
90  start = str;
91  while (*str && *str != PARAM_SET_SYMBOL)
92  {
93  ++str;
94  }
95  if (*str)
96  {
97  end = str;
98  --str;
99  while(str > start && m_isspace(*str))
100  --str;
101  if (str == start)
102  {
103  LOG_ERROR("parse_line - no param name");
104  return ERR_GENERIC;
105  }
106  if (*str != PARAM_SET_SYMBOL)
107  ++str;
108 
109  *parameter_name = (TCHAR*)malloc((str - start + 1) * sizeof(TCHAR));
110  str[0] = 0;
111  m_strcpy(*parameter_name, start);
112  }
113  else
114  {
115  LOG_ERROR("parse_line - no value specified");
116  return SUCCESS_EMPTY;
117  }
118 
119  str = end+1;
120  while (*str && m_isspace(*str))
121  {
122  ++str;
123  }
124  m_strdup(parameter_optipons, str);
125  return SUCCESS_FULL;
126 }
RESULT extract_args ( FILE *  input_file,
test_case_info test_info 
)
Parameters
input_filefile to read from
test_infostruct in which data from parameters will be writen
Returns
RESULT value. See error.h for details

Reads comment lines from the source file until empty is found For each extracts data and call all registered parsers. Each of them is responsible to process parameter or return ERR_INVALID_ARG if doesn't recognise the param name

Definition at line 142 of file tester_internal.c.

143 {
144  TCHAR * test_name = NULL;
145  TCHAR * test_options = NULL;
146  RESULT res;
147  int i;
148 
149  g_first = 1;
150 
151  while ((res = parse_line(input_file, &test_name, &test_options)) != SUCCESS_EMPTY)
152  {
153  if (IS_ERROR(res))
154  {
155  LOG_ERROR("Couldn't read parameter from input file");
156  break;
157  }
158  for (i = 0; i < PARSERS_COUNT; ++i)
159  {
160  if (g_parsers[i])
161  {
162  res = g_parsers[i](test_name, test_options, test_info);
163  if (IS_ERROR(res) && res != ERR_INVALID_ARG)
164  {
165  break;
166  }
167  }
168  }
169  free (test_name);
170  free (test_options);
171 
172  res = SUCCESS_FULL;
173  }
174 
175  return IS_ERROR(res) ? res : SUCCESS_FULL;
176 }
RESULT extract_expected_results ( FILE *  input_file,
const char *  file_name 
)
Parameters
input_fileTest case file
file_namename of the file
Returns
RESULT value. See error.h for details

Read lines with expected results from test case file until empty found. Write them after corresponding processment to the file with name similar to file_name but with specified suffix.

Definition at line 223 of file tester_internal.c.

224 {
225  TCHAR buffer [MAX_LINE_LENGTH];
226  TCHAR * str;
227  size_t real_read_size;
228  RESULT res = SUCCESS_FULL;
229  char new_file_name [MAX_LINE_LENGTH];
230  FILE * test_file = NULL;
231 
232  strcpy(new_file_name, file_name);
233  strcat(new_file_name, "."EXPECTED_RESULTS_EXT);
234 
235  if (!(test_file = fopen(new_file_name, "wb")))
236  {
237  return ERR_FILE;
238  }
239 
240  do
241  {
242  str = m_fgets(input_file, buffer, MAX_LINE_LENGTH, &real_read_size);
243 
244  while (str && *str && m_isspace(*str))
245  {
246  ++str;
247  }
248  res = write_one_line_result(str, test_file);
249  }while (res == SUCCESS_FULL);
250 
251  fclose(test_file);
252  return IS_ERROR(res) ? res : SUCCESS_FULL;
253 }
RESULT execute_test ( const char *  file_name,
test_case_info  test_info 
)
Parameters
file_nameTest case file name
test_infoOptions for execution
Returns
execution code as RESULT value

Prepare shell comand line calling tested application and execute it. Depending on testing mode could perform different actions. Collect stdout output and return execution success code as SUCCESS result

Definition at line 267 of file tester_internal.c.

268 {
269  char cmd_buffer[MAX_LINE_LENGTH] = "";
270  int ret;
271 
272 #if defined(__WIN32__) && defined (__GNUC__)
273  // If executed in Cygwin there is problem with system primitive
274  // 'cause system is calling 'cmd' , not 'bash'
275  strcpy(cmd_buffer, "bash -c \"");
276 #endif
277 
280  {
281  /* will compile a source */
283  {
284  strcat(cmd_buffer, g_parameters.compiler_name);
285  }
286  else
287  {
288  strcat(cmd_buffer, LOGO_NAME);
289  }
290  strcat(cmd_buffer, " ");
291  }
292  else
293  {
294  /* will execute precompiled program */
295  char * end = (char *)strrchr(file_name, '.');
296  if (end) *end = '\0';
297  strcpy(cmd_buffer, file_name);
298  if (end) *end = '.';
299  }
300 
301 
303  {
304  strcat(cmd_buffer, MEMORY_CHECK_OPTION);
305  strcat(cmd_buffer, " ");
306  }
307 
309  {
310  strcat(cmd_buffer, g_parameters.global_params);
311  strcat(cmd_buffer, " ");
312  }
313 
314  if (test_info.command_line_param)
315  {
316  strcat(cmd_buffer, test_info.command_line_param);
317  strcat(cmd_buffer, " ");
318  }
319 
322  {
323  strcat(cmd_buffer, file_name);
324  }
325 
326  strcat(cmd_buffer, " 1> ");
327  strcat(cmd_buffer, file_name);
328  strcat(cmd_buffer, "."REAL_RESULTS_EXT);
329  strcat(cmd_buffer, " 2> ");
330  strcat(cmd_buffer, file_name);
331  strcat(cmd_buffer, "."ERROR_RESULTS_EXT);
332 
333 #if defined(__WIN32__) && defined (__GNUC__)
334  strcat(cmd_buffer, "\"");
335 #endif
336 
337  ret = system(cmd_buffer);
338  if (ret == -1)
339  {
340  LOG_ERROR("execution failed");
341  return ERR_GENERIC;
342  }
343  return MAKE_SUCCESS(ret);
344 }
RESULT compile_test ( const char *  file_name,
test_case_info  test_info 
)
Parameters
file_nameTest case file name
test_infoOptions for execution
Returns
RESULT value. See error.h for details

Calls external compiler to compile test file.

Definition at line 356 of file tester_internal.c.

357 {
358  char cmd_buffer[MAX_LINE_LENGTH];
359  int ret;
360 
362  {
363  strcpy(cmd_buffer, g_parameters.compiler_name);
364  }
365  else
366  {
367  strcpy(cmd_buffer, LOGO_NAME);
368  }
369  strcat(cmd_buffer, " -x ");
370 
372  {
373  strcat(cmd_buffer, g_parameters.global_params);
374  strcat(cmd_buffer, " ");
375  }
376 
377  if (test_info.command_line_param)
378  {
379  strcat(cmd_buffer, test_info.command_line_param);
380  strcat(cmd_buffer, " ");
381  }
382 
383  strcat(cmd_buffer, file_name);
384 
385  if ((ret = system(cmd_buffer)) == -1)
386  {
387  LOG_ERROR("execution failed");
388  return ERR_GENERIC;
389  }
390  return MAKE_SUCCESS(ret);
391 }
RESULT check_results ( const char *  file_name,
test_case_info  test_info,
UINT32  exec_result 
)
Parameters
file_namename of tested file
test_infooptions for execution
exec_resultreturn value from execution
Returns
RESULT value. See error.h for details

Checks results from test execution and compare them with expected.

Definition at line 426 of file tester_internal.c.

427 {
428  BOOL is_success = TRUE;
429  UINT64 size;
430  RESULT res;
431  char par_name[MAX_NAME_LEN];
432  size_t file_name_len;
433 
434  file_name_len = m_strlen(file_name);
435  strcpy(par_name, file_name);
436 
437  if (0 && exec_result) // No exit code tests now!
438  {
440  {
441  fprintf(g_parameters.output_file, "Error executing test :");
442  m_fputs(g_parameters.output_file, test_info.test_name ? test_info.test_name : file_name);
443  fprintf(g_parameters.output_file, "Exit code : %u\n", exec_result);
444  }
445  return MAKE_SUCCESS(exec_result);
446  }
447 
448  strcpy(par_name + file_name_len, "."ERROR_RESULTS_EXT);
449  res = get_file_size(par_name, &size);
450  if (IS_ERROR(res))
451  {
452  LOG_ERROR("get_file_size failed");
453  return res;
454  }
455  if (size)
456  {
458  {
459  fprintf(g_parameters.output_file, "Executing test ");
460  m_fputs(g_parameters.output_file, test_info.test_name ? test_info.test_name : file_name);
461  fprintf(g_parameters.output_file, " caused output to stderr\n");
463  }
464  return MAKE_SUCCESS((UINT32)size);
465  }
466 
467  if (res = file_compare(file_name, test_info))
468  {
469  return res;
470  }
471 
473  {
474  fprintf(g_parameters.output_file, "Executing test ");
475  m_fputs(g_parameters.output_file, test_info.test_name ? test_info.test_name : file_name);
476  fprintf(g_parameters.output_file, " success!\n");
477  }
478 
480  {
481  fprintf(g_parameters.output_file, " %d (",g_parameters.num_passed );
482  const char* c = test_info.test_name ? test_info.test_name : file_name;
483  c = strrchr (c, '/')+1;
485  fprintf(g_parameters.output_file, ") \r");
486  }
487 
488  return SUCCESS_FULL;
489 }
RESULT import_results ( const char *  file_name,
test_case_info  test_info 
)
Parameters
file_namename of tested file
test_infooptions for execution
Returns
RESULT value. See error.h for details

Import results from test execution into test case file.

Definition at line 501 of file tester_internal.c.

502 {
503  TCHAR line[MAX_LINE_LENGTH];
504  size_t real_size;
505 
506  char exp_name[MAX_NAME_LEN];
507  char temp_name[MAX_NAME_LEN];
508 
509  FILE * expected_file;
510  FILE * source_file;
511  FILE * temp_file;
512 
513 
514  strcpy(exp_name, file_name);
515  strcat(exp_name, "."REAL_RESULTS_EXT);
516  expected_file = fopen(exp_name, "rb");
517  if (!expected_file)
518  {
519  LOG_ERROR("Can't open expected file");
520  return ERR_FILE;
521  }
522 
523  strcpy(temp_name, file_name);
524  strcat(temp_name, "."LTEMP_EXT);
525  temp_file = fopen(temp_name, "wb");
526  if (!temp_file)
527  {
528  LOG_ERROR("Can't open temp file");
529  return ERR_FILE;
530  }
531 
532  source_file = fopen(file_name, "rb");
533  if (!source_file)
534  {
535  LOG_ERROR("Can't open source file");
536  return ERR_FILE;
537  }
538 
539  fprintf(temp_file, "\n");
540 
541  while (m_fgets(expected_file, line, MAX_LINE_LENGTH, &real_size))
542  {
543  if (real_size && real_size < MAX_LINE_LENGTH)
544  {
545  m_fputc(temp_file, COMMENT_SYMBOL);
546  }
547  m_fputs(temp_file, line);
548  }
549 
550  fprintf(temp_file, "\n");
551  fclose(expected_file);
552  unlink(exp_name);
553 
554  while (m_fgets(source_file, line, MAX_LINE_LENGTH, &real_size))
555  {
556  m_fputs(temp_file, line);
557  }
558  fclose(temp_file);
559  fclose(source_file);
560  unlink(file_name);
561  return rename(temp_name, file_name) == 0 ? SUCCESS_FULL : ERR_FILE;
562 }
void clean_up ( const char *  file_name)
Parameters
file_namename of tested file

Remove any temporary files produced from test execution process

Definition at line 572 of file tester_internal.c.

573 {
574  char name[MAX_NAME_LEN];
575  size_t file_name_len;
576 
577  file_name_len = m_strlen(file_name);
578  strcpy(name, file_name);
579 
580  strcpy(name + file_name_len, "."EXPECTED_RESULTS_EXT);
581  unlink(name);
582 
583  strcpy(name + file_name_len, "."REAL_RESULTS_EXT);
584  unlink(name);
585 
586  strcpy(name + file_name_len, "."ERROR_RESULTS_EXT);
587  unlink(name);
588 }
void print_file ( const char *  file_name,
FILE *  output_file 
)
Parameters
file_namename of file to be printed
output_filefile where data will be appended

Appends contet of input file into end of destination file

Definition at line 599 of file tester_internal.c.

600 {
601  TCHAR buffer[MAX_LINE_LENGTH];
602  size_t size;
603 
604  FILE * f = fopen(file_name, "rb");
605  if (!f)
606  {
607  LOG_ERROR("Open file to print failed");
608  return;
609  }
610  while(m_fgets(f, buffer, MAX_LINE_LENGTH, &size))
611  {
612  m_fputs(output_file, buffer);
613  }
614  fclose(f);
615 }
RESULT file_compare ( const char *  test_file_name,
test_case_info  test_info 
)
Parameters
test_file_namename of tested file
test_infoparameters for test execution
Returns
RESULT value. See error.h for details

Compare file containing produced from tester data with file containing expected data Returns success value if lines are "equual" and error if tey are not

Definition at line 682 of file tester_internal.c.

683 {
684  TCHAR expected[MAX_LINE_LENGTH];
685  TCHAR expected_mem[] = EXPECTED_MEMORY;
686  TCHAR real[MAX_LINE_LENGTH];
687  size_t real_size, exp_size;
688  char name[MAX_NAME_LEN];
689  RESULT res = SUCCESS_FULL;
690  int mem_checked = 0;
691 
692  FILE * expected_file;
693  FILE * real_file;
694 
695  strcpy(name, test_file_name);
696  strcat(name, "."EXPECTED_RESULTS_EXT);
697  expected_file = fopen(name, "rb");
698  if (!expected_file)
699  {
700  LOG_ERROR("Can't open expected file");
701  return ERR_FILE;
702  }
703 
704  strcpy(name, test_file_name);
705  strcat(name, "."REAL_RESULTS_EXT);
706  real_file = fopen(name, "rb");
707  if (!real_file)
708  {
709  LOG_ERROR("Can't open real file");
710  return ERR_FILE;
711  }
712 
713  while (m_fgets(real_file, real, MAX_LINE_LENGTH, &real_size))
714  {
715  if (!m_fgets(expected_file, expected, MAX_LINE_LENGTH, &exp_size))
716  {
717  if (!mem_checked)
718  {
719  mem_checked = 1;
720  if (SUCCESS_FULL == compare_strings_output(real, expected_mem))
721  {
722  continue;
723  }
724  }
725 
727  {
728  fprintf(g_parameters.output_file, "Test %s failed. Extra line in output: \n%s\n",
729  test_info.test_name ? test_info.test_name : test_file_name, real);
730  }
731  else
732  {
733  fprintf(g_parameters.output_file, "Test failed\n");
734  }
735  res = ERR_GENERIC;
736  break;
737  }
738  if (IS_ERROR(compare_strings_output(real, expected)))
739  {
741  {
742  fprintf(g_parameters.output_file, "Test %s failed. Unexpected line in output: \n\"%s\"\n"
743  "\tExpected\n\"%s\"\n",
744  test_info.test_name ? test_info.test_name : test_file_name, real, expected);
745  }
746  else
747  {
748  fprintf(g_parameters.output_file, "Test failed\n");
749  }
750  res = ERR_GENERIC;
751  break;
752  }
753  }
754 
755  if (m_fgets(expected_file, expected, MAX_LINE_LENGTH, &exp_size))
756  {
757  int i = 0;
758  if (expected[i])
759  {
761  {
762  fprintf(g_parameters.output_file, "Test %s failed. Extra line in output: \n%s\n",
763  test_info.test_name ? test_info.test_name : test_file_name, real);
764  }
765  else
766  {
767  fprintf(g_parameters.output_file, "Test failed\n");
768  }
769  res = ERR_GENERIC;
770  }
771  }
772 
773  if (!mem_checked)
774  {
776  {
777  fprintf(g_parameters.output_file, "Test %s failed. No memory check performed!\n",
778  test_info.test_name ? test_info.test_name : test_file_name);
779  }
780  else
781  {
782  fprintf(g_parameters.output_file, "Test failed\n");
783  }
784  res = ERR_GENERIC;
785  }
786 
787  fclose(real_file);
788  fclose(expected_file);
789 
790  return res;
791 }
RESULT exec_shell ( const char *  file_name)
Parameters
file_namename of tested file
Returns
RESULT value. Execuion status

Try to execute shell script with name same as input file if any. If no script exist return SUCCESS_FILE else return SUCESS_FULL on successfull execution of ERR_GENERIC on error.

Definition at line 803 of file tester_internal.c.

804 {
805  RESULT res = SUCCESS_FILE;
806  FILE * test_file;
807  char sh_name[512];
808  char command[512] = "bash -c ";
809  size_t len;
810  int ret_code;
811  char * dot_pos = strrchr(file_name, '.');
812 
813  // Prepare shell file name
814  if (dot_pos && dot_pos != file_name)
815  {
816  len = dot_pos - file_name;
817  }
818  else
819  {
820  len = strlen(file_name);
821  }
822 
823  strncpy(sh_name, file_name, len);
824  sh_name[len++] = '.';
825  strcpy(sh_name+len, SHELL_FILE_EXTENSION);
826 
827  // Try to open file
828  test_file = fopen(sh_name, "r");
829  if (!test_file)
830  {
831  return SUCCESS_FILE;
832  }
833  fclose(test_file);
834  ret_code = system(strcat(command, sh_name));
836  {
837  fprintf(stderr, "execution:%s-> %d\n", sh_name, ret_code);
838  }
839  if (g_parameters.intest_flag && ret_code)
840  {
841  fprintf(stderr, "execution:%s-> %d\n", sh_name, ret_code);
842  }
843  if (ret_code == -1) // execution failed!
844  {
845  LOG_ERROR("execution failed");
846  return SUCCESS_FILE;
847  }
848  if (ret_code == 0)
849  {
851  return SUCCESS_FULL;
852  }
853 
855  return ERR_GENERIC;
856 }

Variable Documentation

int g_first

Definition at line 34 of file tester_internal.c.


[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013