Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
process_file.c File Reference

Go to the source code of this file.

Functions

static RESULT test_jit_compile (const char *file_name)
 Execute in memory test. More...
 
static RESULT test_compile_exec (const char *file_name)
 Execute compilation and then test produced file. More...
 
static RESULT build_test_case (const char *file_name)
 Build test case file. More...
 
static RESULT process_one_file (const char *file_name)
 Perform specified testing action on a file. More...
 
RESULT process_directory ()
 Process all files in input directory. More...
 

Function Documentation

RESULT test_jit_compile ( const char *  file_name)
static
Parameters
file_namename of the test file
Returns
RESULT code (see error.h)

Exewcute in memory test of the compiler.

Definition at line 51 of file process_file.c.

52 {
53  RESULT res = SUCCESS_FULL;
54  RESULT res1 = SUCCESS_FULL;
55  FILE * input_file = NULL;
56  test_case_info test_info;
57 
58  input_file = fopen(file_name, "rb");
59  if (!input_file)
60  {
61  LOG_ERROR("Couldn't open input file");
62  return ERR_FILE;
63  }
64  memset(&test_info, 0, sizeof(test_info));
65 
66  do
67  {
68  res = extract_args(input_file, &test_info);
69  if (IS_ERROR(res))
70  {
71  fprintf(g_parameters.output_file, "Error extracting args for %s\n", file_name);
72  LOG_ERROR("Error parsing arguments");
73  break;
74  }
75 
76  res |= extract_expected_results(input_file, file_name);
77  if (IS_ERROR(res))
78  {
79  LOG_ERROR("Error extracting expected results");
80  break;
81  }
82 
83  fclose(input_file);
84  input_file = NULL;
85 
86  res1 = execute_test(file_name, test_info);
87  if (IS_ERROR(res))
88  {
89  LOG_ERROR("Error executing test");
90  break;
91  }
92 
93  res |= check_results(file_name, test_info, res1);
94  if (IS_ERROR(res))
95  {
96  LOG_ERROR("Error checking results from test");
97  }
98 
99  clean_up(file_name);
100 
101  }while (0);
102 
103  SAFE_FREE(test_info.command_line_param);
104  SAFE_FREE(test_info.test_name);
105 
106  if (input_file)
107  {
108  fclose(input_file);
109  }
110 
111  if (res != SUCCESS_FULL)
112  {
114  }
115  else
116  {
118  }
119 
120  return res;
121 }
RESULT test_compile_exec ( const char *  file_name)
static
Parameters
file_namename of the test file
Returns
RESULT code (see error.h)

Call the compiler to produce executable file and then test it's execution.

Definition at line 134 of file process_file.c.

135 {
136  RESULT res = SUCCESS_FULL;
137  RESULT res1 = SUCCESS_FULL;
138 
139  FILE * input_file = NULL;
140  test_case_info test_info;
141 
142  input_file = fopen(file_name, "rb");
143  if (!input_file)
144  {
145  LOG_ERROR("Couldn't open input file");
146  return ERR_FILE;
147  }
148  memset(&test_info, 0, sizeof(test_info));
149 
150  do
151  {
152  res = extract_args(input_file, &test_info);
153  if (IS_ERROR(res))
154  {
155  LOG_ERROR("Error parsing arguments");
156  break;
157  }
158 
159  res |= extract_expected_results(input_file, file_name);
160  if (IS_ERROR(res))
161  {
162  LOG_ERROR("Error extracting expected results");
163  break;
164  }
165 
166  fclose(input_file);
167  input_file = NULL;
168 
169  res |= compile_test(file_name, test_info);
170  if (IS_ERROR(res))
171  {
172  LOG_ERROR("Error compiling test");
173  break;
174  }
175 
176  res1 = execute_test(file_name, test_info);
177  if (IS_ERROR(res))
178  {
179  LOG_ERROR("Error executing test");
180  break;
181  }
182 
183  res |= check_results(file_name, test_info, res1);
184  if (IS_ERROR(res))
185  {
186  LOG_ERROR("Error checking results from test");
187  }
188 
189  clean_up(file_name);
190  }while (0);
191 
192  SAFE_FREE(test_info.command_line_param);
193  SAFE_FREE(test_info.test_name);
194 
195  if (input_file)
196  {
197  fclose(input_file);
198  }
199 
200  if (res != SUCCESS_FULL)
201  {
203  }
204  else
205  {
207  }
208 
209  return res;
210 }
RESULT build_test_case ( const char *  file_name)
static
Parameters
file_namename of the test file
Returns
RESULT code (see error.h)

Calls the compiler to run inmemory compilation and execution of thest case. Write down the results into the test case file.

Definition at line 223 of file process_file.c.

224 {
225  RESULT res = SUCCESS_FULL;
226  test_case_info test_info;
227 
228  memset(&test_info, 0, sizeof(test_info));
229 
230  do
231  {
232  res = execute_test(file_name, test_info);
233  if (IS_ERROR(res))
234  {
235  LOG_ERROR("Error executing test");
236  break;
237  }
238 
239  res |= import_results(file_name, test_info);
240  if (IS_ERROR(res))
241  {
242  LOG_ERROR("Error importing results from test");
243  }
244  }
245  while (0);
246 
247  if (res != SUCCESS_FULL)
248  {
250  }
251  else
252  {
254  }
255 
256  clean_up(file_name);
257 
258  return res;
259 }
RESULT process_one_file ( const char *  file_name)
static
Parameters
file_namename of the test file
Returns
RESULT code (see error.h)

Depending on command line arguments specifying tester mode call function to perform diferent test procedures on the file

Definition at line 271 of file process_file.c.

272 {
273  RESULT res;
274  char file_buffer[1024] = "";
275 
277  {
278  strcpy(file_buffer, g_parameters.input_directory);
279  }
280  else
281  {
282  strcpy(file_buffer, ".");
283  }
284 
285 #if defined (_MSC_VER)
286  if (file_buffer[strlen(file_buffer) -1] != '\\')
287  {
288  strcat(file_buffer, "\\");
289  }
290 #elif defined (__GNUC__)
291  if (file_buffer[strlen(file_buffer) -1] != '/')
292  {
293  strcat(file_buffer, "/");
294  }
295 #endif
296 
297  strcat(file_buffer, file_name);
298 
300  {
301  res = build_test_case(file_buffer);
302  if (IS_ERROR(res))
303  {
304  LOG_ERROR("Error creating test case.");
305  return res;
306  }
307  }
308 
310  {
311  res = exec_shell(file_buffer);
312  if (IS_ERROR(res))
313  {
314  fprintf(g_parameters.output_file, "Error shell execution test : %s\n", file_name);
315  LOG_ERROR("Error executing SHELL test");
316  return res;
317  }
318  else if (res == SUCCESS_FULL)
319  {
320  return res;
321  }
322 
323  res = test_jit_compile(file_buffer);
324  if (IS_ERROR(res))
325  {
326  fprintf(g_parameters.output_file, "Error jit execution test : %s\n", file_name);
327  LOG_ERROR("Error executing JIT test");
328  return res;
329  }
330  }
331 
333  {
334  res = test_compile_exec(file_buffer);
335  if (IS_ERROR(res))
336  {
337  LOG_ERROR("Error compiling and executing test");
338  return res;
339  }
340  }
341 
342  fflush(g_parameters.output_file);
343  return SUCCESS_FULL;
344 }
RESULT process_directory ( )
Returns
RESULT code (see error.h)

Scan specified directory and for all test case files call process_one_file function.

Definition at line 356 of file process_file.c.

357 {
358  RESULT res = SUCCESS_FULL;
359 #if defined (_MSC_VER)
360  struct _finddata_t info;
361  char mask[1024];
362  intptr_t handle;
363 #elif defined (__GNUC__)
364  DIR * dirPtr = 0;
365  struct dirent * dirStruct = 0;
366 #endif
367 
368 
369 
370 #if defined (_MSC_VER)
371 
373  {
374  strcpy(mask, g_parameters.input_directory);
375  if (mask[strlen(mask)-1] != '\\')
376  {
377  strcat(mask, "\\");
378  }
379  }
380  else
381  {
382  mask[0] = 0;
383  }
384  strcat(mask, "*.");
385  strcat(mask, TARGET_FILE_EXTENSION);
386 
387  handle = _findfirst(mask, &info);
388  if (handle == -1)
389  {
390  return SUCCESS_EMPTY;
391  }
392 
393  do
394  {
395  res = process_one_file(info.name);
396  } while(_findnext(handle, &info) != -1);
397 
398  _findclose(handle);
399 
400 #elif defined (__GNUC__)
401 
403  {
404  dirPtr = opendir(g_parameters.input_directory);
405  }
406  else
407  {
408  dirPtr = opendir(".");
409  }
410 
411  if (dirPtr == 0)
412  {
413  return ERR_FILE;
414  }
415 
416  while ((dirStruct = readdir(dirPtr)) != 0)
417  {
418  size_t len = strlen(dirStruct->d_name);
419  if (!strcmp(dirStruct->d_name + len - strlen(TARGET_FILE_EXTENSION), TARGET_FILE_EXTENSION)
420  && dirStruct->d_name[len - strlen(TARGET_FILE_EXTENSION) - 1] == '.')
421  {
422  res = process_one_file(dirStruct->d_name);
423  }
424  }
425  closedir(dirPtr);
426 
427 #endif
428  return res;
429 }

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