784ca864c11ba612d8ea63d2e685699cb09d4a22
[mono.git] / eglib / test / driver.c
1 #include <stdio.h>
2 #include <glib.h>
3
4 #include "test.h"
5 #include "tests.h"
6
7 static void print_help(char *s)
8 {
9         gint i;
10         
11         printf("Usage: %s [options] [iterations [test1 test2 ... testN]]\n\n", s);
12         printf(" options are:\n");
13         printf("   --help      show this help\n\n");
14         printf(" iterations:   number of times to run tests\n");
15         printf(" test1..testN  name of test to run (all run by default)\n\n");
16         printf(" available tests:\n");
17
18         for(i = 0; test_groups[i].name != NULL; i++) {
19                 printf("   %s\n", test_groups[i].name);
20         }
21
22         printf("\n");
23 }
24
25 gint main(gint argc, gchar **argv)
26 {
27         gint i, j, k, iterations = 1, tests_to_run_count = 0;
28         gchar **tests_to_run = NULL;
29         
30         if(argc > 1) {
31                 for(i = 1; i < argc; i++) {
32                         if(strcmp(argv[i], "--help") == 0) {
33                                 print_help(argv[0]);
34                                 return 1;
35                         }
36                 }
37         
38                 iterations = atoi(argv[1]);
39                 tests_to_run_count = argc - 2;
40
41                 if(tests_to_run_count > 0) {
42                         tests_to_run = (gchar **)g_new0(gchar *, tests_to_run_count + 1);
43
44                         for(i = 0; i < tests_to_run_count; i++) {
45                                 tests_to_run[i] = argv[i + 2];
46                         }
47
48                         tests_to_run[tests_to_run_count] = NULL;
49                 }
50         }
51
52         for(i = 0; i < iterations; i++) {
53                 for(j = 0; test_groups[j].name != NULL; j++) {
54                         gboolean run = TRUE;
55                         
56                         if(tests_to_run != NULL) {
57                                 run = FALSE;
58                                 for(k = 0; tests_to_run[k] != NULL; k++) {
59                                         if(strcmp(tests_to_run[k], test_groups[j].name) == 0) {
60                                                 run = TRUE;
61                                                 break;
62                                         }
63                                 }
64                         }
65                         
66                         if(run) {
67                                 run_group(&(test_groups[j]));
68                         }
69                 }
70         }
71
72         if(tests_to_run != NULL) {
73                 g_free(tests_to_run);
74         }
75
76         return 0;
77 }
78