Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
process_file.c
Go to the documentation of this file.
1 //===================================================
2 // Project:TestSystem Author: Peter Armianov
3 //===================================================
4 //
5 // Process_File.C
6 //
7 // This file contains implementation of main tester
8 // module.
9 //
10 // Revision history:
11 // 2007-05-28 - file created
12 // 2007-07-01 - additional working modes implemented
13 // 2007-07-12 - additional comments in Doxygen style
14 // 2007-08-09 - Fixed bug #1762633
15 // 2007-09-03 - Fixing failed tests count
16 // 2007-09-08 - Fixed problem when working dir not set
17 // 2009-05-30 - Support for shell tests
18 //===================================================
19 
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 
25 #if defined(__GNUC__)
26 # include <unistd.h>
27 # include <sys/types.h>
28 # include <errno.h>
29 # include <dirent.h>
30 #elif defined(_MSC_VER)
31 # include <io.h>
32 # include <direct.h>
33 #else
34 # error "Unknown compiler"
35 #endif
36 
37 #include "error.h"
38 #include "TestMaker.h"
39 #include "internal.h"
40 
41 
42 //===========================================================
49 //===========================================================
50 static RESULT
51 test_jit_compile(const char * file_name)
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 }
122 
123 
124 //===========================================================
132 //===========================================================
133 static RESULT
134 test_compile_exec(const char * file_name)
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 }
211 
212 
213 //===========================================================
221 //===========================================================
222 static RESULT
223 build_test_case(const char * file_name)
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 }
260 
261 //===========================================================
269 //===========================================================
270 static RESULT
271 process_one_file(const char * file_name)
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 }
345 
346 
347 //===========================================================
354 //===========================================================
355 extern RESULT
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 }
430 

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