2 * Convert debug output from running the regression tests
3 * on ReactOS to an xml document.
4 * Casper S. Hornstrup <chorns@users.sourceforge.net>
19 #include <sys/types.h>
28 #define DIR_SEPARATOR_CHAR '/'
29 #define DIR_SEPARATOR_STRING "/"
31 #define DIR_SEPARATOR_CHAR '\\'
32 #define DIR_SEPARATOR_STRING "\\"
35 typedef struct _TEST_RESULT_INFO
37 struct _TEST_RESULT_INFO
*next
;
40 int succeeded
; /* 0 = failed, 1 = succeeded */
41 } TEST_RESULT_INFO
, *PTEST_RESULT_INFO
;
45 static FILE *file_handle
= NULL
;
46 static char *file_buffer
= NULL
;
47 static unsigned int file_size
= 0;
48 static int file_pointer
= 0;
49 static PTEST_RESULT_INFO test_result_info_list
= NULL
;
53 convert_path(char* origpath
)
58 newpath
= strdup(origpath
);
61 while (newpath
[i
] != 0)
64 if (newpath
[i
] == '\\')
70 if (newpath
[i
] == '/')
82 write_line(char *line
)
86 memset(buf
, 0, sizeof(buf
));
88 /* Terminate the line */
89 buf
[strlen(buf
)] = '\r';
90 buf
[strlen(buf
)] = '\n';
92 (void)fwrite(&buf
[0], 1, strlen(buf
), out
);
97 read_file(char *filename
)
99 file_handle
= fopen(filename
, "rb");
100 if (file_handle
== NULL
)
102 printf("Can't open %s\n", filename
);
106 // Get the size of the file
107 fseek(file_handle
, 0, SEEK_END
);
108 file_size
= ftell(file_handle
);
110 // Load it all into memory
111 file_buffer
= malloc(file_size
);
112 if (file_buffer
== NULL
)
115 printf("Out of memory\n");
118 fseek(file_handle
, 0, SEEK_SET
);
121 if (fread (file_buffer
, 1, file_size
, file_handle
) < 1)
124 printf("Read error in file %s\n", filename
);
143 is_whitespace(char ch
)
173 while ((file_pointer
< file_size
) && (!is_eol_char(file_buffer
[file_pointer
])))
177 if ((file_pointer
< file_size
) && (is_eol_char(file_buffer
[file_pointer
])))
180 if ((file_pointer
< file_size
) && (file_buffer
[file_pointer
] == '\n'))
190 while ((file_pointer
< file_size
) && !is_eol_char(file_buffer
[file_pointer
])
191 && is_whitespace(file_buffer
[file_pointer
]))
200 static char test_marker
[] = "ROSREGTEST:";
203 while ((file_pointer
< file_size
) && (!found_test
))
210 if (i
>= strlen(test_marker
))
214 if (is_eol_char(file_buffer
[file_pointer
]))
219 if (file_buffer
[file_pointer
] != test_marker
[i
])
236 read_until(char ch
, char* buf
)
238 int start
= file_pointer
;
239 while ((file_pointer
< file_size
))
241 if (file_buffer
[file_pointer
] == ch
)
243 strncpy(buf
, &file_buffer
[start
], file_pointer
- start
);
244 buf
[file_pointer
- start
] = 0;
253 read_until_end(char* buf
)
255 int start
= file_pointer
;
256 while ((file_pointer
< file_size
))
258 if (is_eol_char(file_buffer
[file_pointer
]))
260 strncpy(buf
, &file_buffer
[start
], file_pointer
- start
);
261 buf
[file_pointer
- start
] = 0;
271 parse_file(char *filename
)
273 PTEST_RESULT_INFO test_result_info
;
279 if (!skip_to_next_test())
286 * [ROSREGTEST:][space][|][<testname>][|][space][Status:][space][<result of running test>]
289 test_result_info
= malloc(sizeof(TEST_RESULT_INFO
));
290 if (test_result_info
== NULL
)
292 printf("Out of memory\n");
296 /* Skip whitespaces */
303 read_until(')', test_result_info
->testname
);
317 /* <result of running test> */
318 read_until_end(test_result_info
->result
);
320 if (strncmp(test_result_info
->result
, "Success", 7) == 0)
322 test_result_info
->succeeded
= 1;
326 test_result_info
->succeeded
= 0;
329 test_result_info
->next
= test_result_info_list
;
330 test_result_info_list
= test_result_info
;
339 PTEST_RESULT_INFO test_result_info
;
348 test_result_info
= test_result_info_list
;
349 while (test_result_info
!= NULL
)
351 if (test_result_info
->succeeded
)
359 test_result_info
= test_result_info
->next
;
362 if (succeeded_total
+ failed_total
> 0)
364 success_rate
= ((succeeded_total
) * 100) / (succeeded_total
+ failed_total
);
371 write_line("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
374 sprintf(buf
, "<testresults success_rate=\"%d\" succeeded_total=\"%d\" failed_total=\"%d\">",
375 success_rate
, succeeded_total
, failed_total
);
378 if (test_result_info_list
!= NULL
)
380 test_result_info
= test_result_info_list
;
381 while (test_result_info
!= NULL
)
383 sprintf(buf
, "<testresult testname=\"%s\" succeeded=\"%s\" result=\"%s\">",
384 test_result_info
->testname
,
385 test_result_info
->succeeded
== 1 ? "true" : "false",
386 test_result_info
->result
);
388 write_line("</testresult>");
389 test_result_info
= test_result_info
->next
;
393 write_line("</testresults>");
397 "REGTESTS2XML input-filename output-filename\n"
399 " input-filename File containing output from running regression tests\n"
400 " output-filename File to create\n";
402 int main(int argc
, char **argv
)
413 input_file
= convert_path(argv
[1]);
414 if (input_file
[0] == 0)
417 printf("Missing input-filename\n");
421 output_file
= convert_path(argv
[2]);
422 if (output_file
[0] == 0)
426 printf("Missing output-filename\n");
430 out
= fopen(output_file
, "wb");
435 printf("Cannot open output file");
439 parse_file(input_file
);