Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
TestMaker.c
Go to the documentation of this file.
1 //===================================================
2 // Project:TestSystem Author: Peter Armianov
3 //===================================================
4 //
5 // TESTMAKER.C
6 //
7 // This file contains main implementation of the
8 // test system
9 //
10 // Revision history:
11 // 2007-05-14 - file created
12 // 2007-05-16 - First version implemented.
13 // 2007-06-17 - Bugs item #1738642 fixed.
14 // 2007-07-01 - additional working modes implemented
15 // 2007-07-12 - additional comments in Doxygen style
16 // 2007-09-08 - Implementing strict mode option
17 // 2013-06-27 - Adding INTEST flag /P. Boytchev/
18 //===================================================
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "error.h"
25 #include "TestMaker.h"
26 #include "internal.h"
27 #include "param_parsers.h"
28 
29 
32 
33 //===========================================================
38 //===========================================================
39 static void
41 {
42  printf("Program usage:\n");
43  printf("TestMaker [options]\n");
44  printf(" Valid options are:\n");
45 
46  printf(" -d (--dir) <folder name> - Specify the input folder. Default is current.\n");
47  printf(" -o (--out) <file name> - Specify the output file. Default is stdout.\n");
48  printf(" -e (--exec) - Set execution mode.\n");
49  printf(" -b (--build) - Set test build mode.\n");
50  printf(" -p (--param) <file name> - Specify parameters passed to compiler.\n");
51  printf(" -c (--compiler) <app name> - Specify the compiler which will be called.\n");
52  printf(" -v (--verbose) - Set verbose info mode.\n");
53  printf(" -t (--intest) - Set in-test info mode.\n");
54  printf(" -s (--strict) - Set strict text compare mode.\n");
55  printf(" -h (--help) - Print this info.\n");
56 
57  printf("\n");
58 }
59 
60 
61 //===========================================================
72 //===========================================================
73 
74 static RESULT
75 parse_arg(char ** argv, int argc, int * ind)
76 {
77  char * arg = argv[*ind];
78  int start = 1;
79 
80  if (arg[0] != '-')
81  {
82  printf("Unknown argument %s\n", arg);
83  print_help();
84  return ERR_INVALID_ARG;
85  }
86 
87  if (arg[1] == '-') ++start;
88 
89 
90  switch(arg[start])
91  {
92  case 'd':
93  if (arg[start + 1] && strcmp(arg + start, ARG_DIR))
94  {
95  printf("Unknown argument %s\n", arg);
96  print_help();
97  return ERR_INVALID_ARG;
98  }
99 
100  ++(*ind);
101  if (*ind == argc || argv[*ind][0] == '-')
102  {
103  printf("Unknown argument %s\n", arg);
104  print_help();
105  return ERR_INVALID_ARG;
106  }
107  m_strdup(&g_parameters.input_directory, argv[*ind]);
108  break;
109 
110  case 'p':
111  if (arg[start + 1] && strcmp(arg + start, ARG_PARAM))
112  {
113  printf("Unknown argument %s\n", arg);
114  print_help();
115  return ERR_INVALID_ARG;
116  }
117  ++(*ind);
118  if (*ind == argc)
119  {
120  printf("Unknown argument %s\n", arg);
121  print_help();
122  return ERR_INVALID_ARG;
123  }
124  m_strdup(&g_parameters.global_params, argv[*ind]);
125  break;
126 
127  case 'o':
128  if (arg[start + 1] && strcmp(arg + start, ARG_OUT))
129  {
130  printf("Unknown argument %s\n", arg);
131  print_help();
132  return ERR_INVALID_ARG;
133  }
134 
135  ++(*ind);
136  if (*ind == argc || argv[*ind][0] == '-')
137  {
138  printf("Unknown argument %s\n", arg);
139  print_help();
140  return ERR_INVALID_ARG;
141  }
142  g_parameters.output_file = fopen(argv[*ind], "wt");
144  {
145  LOG_ERROR("can't open output file");
146  return ERR_FILE;
147  }
148  break;
149 
150  case 'c':
151  if (arg[start + 1] && strcmp(arg + start, ARG_OUT))
152  {
153  printf("Unknown argument %s\n", arg);
154  print_help();
155  return ERR_INVALID_ARG;
156  }
157 
158  ++(*ind);
159  if (*ind == argc || argv[*ind][0] == '-')
160  {
161  printf("Unknown argument %s\n", arg);
162  print_help();
163  return ERR_INVALID_ARG;
164  }
165  m_strdup(&g_parameters.compiler_name, argv[*ind]);
166  break;
167 
168  case 'v':
169  if (arg[start + 1] && strcmp(arg + start, ARG_VERBOSE))
170  {
171  printf("Unknown argument %s\n", arg);
172  print_help();
173  return ERR_INVALID_ARG;
174  }
176  break;
177 
178  case 't':
179  if (arg[start + 1] && strcmp(arg + start, ARG_INTEST))
180  {
181  printf("Unknown argument %s\n", arg);
182  print_help();
183  return ERR_INVALID_ARG;
184  }
186  break;
187 
188  case 's':
189  if (arg[start + 1] && strcmp(arg + start, ARG_STRICT_MODE))
190  {
191  printf("Unknown argument %s\n", arg);
192  print_help();
193  return ERR_INVALID_ARG;
194  }
196  break;
197 
198 
199  case 'b':
200  if (arg[start + 1] && strcmp(arg + start, ARG_BUILD_MODE))
201  {
202  printf("Unknown argument %s\n", arg);
203  print_help();
204  return ERR_INVALID_ARG;
205  }
207  break;
208 
209  case 'e':
210  if (arg[start + 1] && strcmp(arg + start, ARG_EXEC_MODE))
211  {
212  printf("Unknown argument %s\n", arg);
213  print_help();
214  return ERR_INVALID_ARG;
215  }
217  break;
218 
219  case 'h':
220  print_help();
221  return SUCCESS_EMPTY;
222  default:
223  print_help();
224  return ERR_INVALID_ARG;
225  }
226 
227  return SUCCESS_FULL;
228 }
229 
230 
231 //===========================================================
240 //===========================================================
241 static RESULT
242 parse_args(int argc, char** argv)
243 {
244  int i;
245  RESULT res;
246  memset(&g_parameters, 0, sizeof(g_parameters));
247  g_parameters.output_file = fdopen(1, "a");
249 
250  for (i = 1; i < argc; ++ i)
251  {
252  res = parse_arg(argv, argc, &i);
253  if (res != SUCCESS_FULL)
254  {
255  if (IS_ERROR(res))
256  {
257  LOG_ERROR("parse_arg failed");
258  }
259  return res;
260  }
261  }
262 
263  return SUCCESS_FULL;
264 }
265 
266 
267 //===========================================================
277 //===========================================================
278 
279 static RESULT
280 init_tester(int argc, char** argv)
281 {
282  RESULT res;
283 
284  INIT_LOGER;
285 
286  res = init_param_parsers();
287  if (IS_ERROR(res))
288  {
289  LOG_ERROR("init_param_parsers failed");
290  return res;
291  }
292 
293  res = parse_args(argc, argv);
294  if (IS_ERROR(res))
295  {
296  LOG_ERROR("parse_args failed");
297  return res;
298  }
299 
302 
303  return SUCCESS_FULL;
304 }
305 
306 
307 /*
308 * Free used resources. Must be last function called
309 */
310 //===========================================================
316 //===========================================================
317 
318 static RESULT
320 {
322  {
323  fclose(g_parameters.output_file);
324  }
325 
329 
330  UNINIT_LOGER;
331  return SUCCESS_FULL;
332 }
333 
334 
335 //
337 //
338 int main(int argc, char** argv)
339 {
340  RESULT res;
341  res = init_tester(argc, argv);
342  if (res != SUCCESS_FULL)
343  {
344  LOG_ERROR("init_tester failed");
345  uninit_tester();
346  return GET_CODE(res);
347  }
348  res = process_directory();
349  if (IS_ERROR(res))
350  {
351  LOG_ERROR("process_directory failed");
352  }
353 
355  {
356  fprintf (g_parameters.output_file, "\n%5d files passed\n%5d files failed\n", g_parameters.num_passed, g_parameters.num_failed);
358  {
359  fprintf (g_parameters.output_file, "Test FAILED!\n\n");
360  }
361  else
362  {
363  fprintf (g_parameters.output_file, "Test SUCCESS!\n\n");
364  }
365  }
366 
368  {
369  fprintf (g_parameters.output_file, " - tests passed ......... %d\n - tests failed ......... %d\n", g_parameters.num_passed, g_parameters.num_failed);
370  }
371 
372  res = uninit_tester();
373  if (IS_ERROR(res))
374  {
375  LOG_ERROR("uninit_tester failed");
376  }
377  return GET_CODE(res);
378 }
379 

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