First try in keyboard driver
[incOS.git] / programs / tests / htmlconverter.c
blob724ce8f71a2773781f99bccb79d036d98412fe14
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
6 struct test
8 char *msg;
9 int failed;
12 struct submodule
14 char *name;
15 int testcount;
16 int failedcount;
17 struct test **tests;
20 struct module
22 char *name;
23 int submodcount;
24 struct submodule **submods;
27 int modulecount = 0;
28 struct module **modules = 0;
30 struct module *get_module(char *name)
32 int i;
33 for (i = 0; i < modulecount; i++)
35 if (!strcmp(modules[i]->name, name))
37 return modules[i];
40 return 0;
42 struct submodule *get_submodule(struct module *mod, char *name)
44 int i;
45 for (i = 0; i < mod->submodcount; i++)
47 if (!strcmp(mod->submods[i]->name, name))
49 return mod->submods[i];
52 return 0;
55 void add_test(char *module, char *submodule, char *status, char *file, char *line, char *msg)
57 // Get module
58 struct module *mod = get_module(module);
59 if (!mod)
61 // Add module
62 modules = realloc(modules, (modulecount + 1) * sizeof(struct module*));
63 modules[modulecount] = malloc(sizeof(struct module));
64 memset(modules[modulecount], 0, sizeof(struct module));
65 modules[modulecount]->name = strdup(module);
66 mod = modules[modulecount];
67 modulecount++;
69 // Get submodule
70 struct submodule *submod = get_submodule(mod, submodule);
71 if (!submod)
73 // Add module
74 mod->submods = realloc(mod->submods, (mod->submodcount + 1) * sizeof(struct submodule*));
75 mod->submods[mod->submodcount] = malloc(sizeof(struct submodule));
76 memset(mod->submods[mod->submodcount], 0, sizeof(struct submodule));
77 mod->submods[mod->submodcount]->name = strdup(submodule);
78 submod = mod->submods[mod->submodcount];
79 mod->submodcount++;
81 // Create test
82 struct test *test = malloc(sizeof(struct test));
83 test->msg = strdup(msg);
84 if (strcmp(status, "PASSED"))
86 test->failed = 1;
87 submod->failedcount++;
89 else
90 test->failed = 0;
91 // Add test
92 submod->tests = realloc(submod->tests, (submod->testcount + 1) * sizeof(struct test*));
93 submod->tests[submod->testcount] = test;
94 submod->testcount++;
97 void create_html_file(void)
99 printf("<html><head><title>Test results</title></head><body>\n");
100 printf("<h1>Test results</h1>\n");
101 int i;
102 for (i = 0; i < modulecount; i++)
104 struct module *module = modules[i];
105 printf("<h3>%s</h3>\n", module->name);
106 printf("<table border=\"1\">\n");
107 printf("<colgroup><col width=\"100\"><col width=\"100\"></colgroup>\n");
108 int j;
109 for (j = 0; j < module->submodcount; j++)
111 printf("<tr>\n");
112 float ratio = (float)module->submods[j]->failedcount / (float)module->submods[j]->testcount;
113 unsigned char red = ratio * 255;
114 unsigned char green = (1.0 - ratio) * 255;
115 printf("<td>%s</td><td bgcolor=\"#%02X%02X00\">%d/%d</td>", module->submods[j]->name,
116 red, green, module->submods[j]->testcount - module->submods[j]->failedcount,
117 module->submods[j]->testcount);
118 printf("</tr>\n");
120 printf("</table>\n");
122 printf("</body></html>\n");
125 int main(int argc, char **argv)
127 while (!feof(stdin))
129 char tmp[1024];
130 char *buffer = tmp;
131 fgets(buffer, 1024, stdin);
132 if (!strncmp("[tests] ", buffer, 6))
134 buffer = strchr(buffer, ']');
135 if (!buffer) continue;
136 buffer += 2;
137 char *module = buffer;
138 buffer = strchr(buffer, '/');
139 if (!buffer) continue;
140 *buffer = 0;
141 buffer++;
142 char *submodule = buffer;
143 buffer = strchr(buffer, ':');
144 if (!buffer) continue;
145 *buffer = 0;
146 buffer += 2;
147 char *status = buffer;
148 buffer = strchr(buffer, ':');
149 if (!buffer) continue;
150 *buffer = 0;
151 buffer += 2;
152 char *file = buffer;
153 buffer = strchr(buffer, ':');
154 if (!buffer) continue;
155 *buffer = 0;
156 buffer += 2;
157 char *line = buffer;
158 buffer = strchr(buffer, ':');
159 if (!buffer) continue;
160 *buffer = 0;
161 buffer += 2;
162 char *msg = buffer;
163 add_test(module, submodule, status, file, line, msg);
167 create_html_file();
169 return 0;