Mercurial > projects > ldc
annotate tests/makewebstatistics.d @ 261:5723b7385c25 trunk
[svn r279] fixed bug in makewebstatistics, regenerated output
author | ChristianK |
---|---|
date | Fri, 13 Jun 2008 08:21:11 +0200 |
parents | 4234b014a4f2 |
children | 5d2f4814bb2e |
rev | line source |
---|---|
255 | 1 // Based on DSTRESS code by Thomas Kühne |
2 | |
3 module findregressions; | |
4 | |
5 private import std.string; | |
6 private import std.conv; | |
7 private import std.stdio; | |
8 private import std.stream; | |
9 private import std.file; | |
10 private import std.c.stdlib; | |
11 private import std.date; | |
12 private import std.path; | |
13 | |
14 | |
15 enum Result{ | |
16 UNTESTED = 0, | |
17 PASS = 1 << 2, | |
18 XFAIL = 2 << 2, | |
19 XPASS = 3 << 2, | |
20 FAIL = 4 << 2, | |
21 ERROR = 5 << 2, | |
22 BASE_MASK = 7 << 2, | |
23 | |
24 EXT_MASK = 3, | |
25 BAD_MSG = 1, | |
26 BAD_GDB = 2, | |
27 | |
28 MAX = BAD_GDB + BASE_MASK | |
29 } | |
30 | |
31 char[] toString(Result r){ | |
32 switch(r & Result.BASE_MASK){ | |
33 case Result.PASS: return "PASS"; | |
34 case Result.XPASS: return "XPASS"; | |
35 case Result.FAIL: return "FAIL"; | |
36 case Result.XFAIL: return "XFAIL"; | |
37 case Result.ERROR: return "ERROR"; | |
38 case Result.UNTESTED: return "UNTESTED"; | |
39 default: | |
40 break; | |
41 } | |
42 throw new Exception(format("unhandled Result value %s", cast(int)r)); | |
43 } | |
44 | |
45 char[] dateString(){ | |
46 static char[] date; | |
47 if(date is null){ | |
48 auto time = getUTCtime(); | |
49 auto year = YearFromTime(time); | |
50 auto month = MonthFromTime(time); | |
51 auto day = DateFromTime(time); | |
52 date = format("%d-%02d-%02d", year, month+1, day); | |
53 } | |
54 return date; | |
55 } | |
56 | |
57 char[][] unique(char[][] a){ | |
58 char[][] b = a.sort; | |
59 char[][] back; | |
60 | |
61 back ~= b[0]; | |
62 | |
63 size_t ii=0; | |
64 for(size_t i=0; i<b.length; i++){ | |
65 if(back[ii]!=b[i]){ | |
66 back~=b[i]; | |
67 ii++; | |
68 } | |
69 } | |
70 | |
71 return back; | |
72 } | |
73 | |
74 private{ | |
75 version(Windows){ | |
76 import std.c.windows.windows; | |
77 extern(Windows) BOOL GetFileTime(HANDLE hFile, LPFILETIME lpCreationTime, LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime); | |
78 }else version(linux){ | |
79 import std.c.linux.linux; | |
80 version = Unix; | |
81 }else version(Unix){ | |
82 import std.c.unix.unix; | |
83 }else{ | |
84 static assert(0); | |
85 } | |
86 | |
87 alias ulong FStime; | |
88 | |
89 FStime getFStime(char[] fileName){ | |
90 version(Windows){ | |
91 HANDLE h; | |
92 | |
93 if (useWfuncs){ | |
94 wchar* namez = std.utf.toUTF16z(fileName); | |
95 h = CreateFileW(namez,GENERIC_WRITE,0,null,OPEN_ALWAYS, | |
96 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); | |
97 }else{ | |
98 char* namez = toMBSz(fileName); | |
99 h = CreateFileA(namez,GENERIC_WRITE,0,null,OPEN_ALWAYS, | |
100 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); | |
101 } | |
102 | |
103 if (h == INVALID_HANDLE_VALUE) | |
104 goto err; | |
105 | |
106 FILETIME creationTime; | |
107 FILETIME accessTime; | |
108 FILETIME writeTime; | |
109 | |
110 BOOL b = GetFileTime(h, &creationTime, &accessTime, &writeTime); | |
111 if(b==1){ | |
112 long modA = writeTime.dwLowDateTime; | |
113 long modB = writeTime.dwHighDateTime; | |
114 return modA | (modB << (writeTime.dwHighDateTime.sizeof*8)); | |
115 } | |
116 | |
117 err: | |
118 CloseHandle(h); | |
119 throw new Exception("failed to query file modification : "~fileName); | |
120 }else version(Unix){ | |
121 char* namez = toStringz(fileName); | |
122 struct_stat statbuf; | |
123 | |
124 if(stat(namez, &statbuf)){ | |
125 throw new FileException(fileName, getErrno()); | |
126 } | |
127 | |
128 return statbuf.st_mtime; | |
129 }else{ | |
130 static assert(0); | |
131 } | |
132 } | |
133 } | |
134 | |
135 char[] cleanFileName(char[] file){ | |
136 char[] back; | |
137 bool hadSep; | |
138 | |
139 foreach(char c; file){ | |
140 if(c == '/' || c == '\\'){ | |
141 if(!hadSep){ | |
142 back ~= '/'; | |
143 hadSep = true; | |
144 } | |
145 }else{ | |
146 back ~= c; | |
147 hadSep = false; | |
148 } | |
149 } | |
150 | |
151 size_t start = 0; | |
152 while(back[start] <= ' ' && start < back.length){ | |
153 start++; | |
154 } | |
155 | |
156 size_t end = back.length-1; | |
157 while(back[end] <= ' ' && end >= start){ | |
158 end--; | |
159 } | |
160 | |
161 back = back[start .. end+1]; | |
162 | |
163 return back; | |
164 } | |
165 | |
166 class Test{ | |
167 char[] name; | |
168 char[] file; | |
169 Result r; | |
170 | |
171 this(char[] file){ | |
172 this.file = file; | |
173 | |
174 int start = rfind(file, "/"); | |
175 if(start<0){ | |
176 start = 0; | |
177 }else{ | |
178 start += 1; | |
179 } | |
180 | |
181 int end = rfind(file, "."); | |
182 if(end < start){ | |
183 end = file.length; | |
184 } | |
185 | |
186 name = file[start .. end]; | |
187 } | |
188 } | |
189 | |
190 | |
191 class Log{ | |
192 Test[char[]] tests; | |
193 | |
194 char[] id; | |
195 | |
196 int[Result] counts; | |
197 | |
198 this(char[] id, char[] file){ | |
199 this.id = id; | |
200 counts = [ | |
201 Result.PASS: 0, | |
202 Result.FAIL: 0, | |
203 Result.XPASS: 0, | |
204 Result.XFAIL: 0, | |
205 Result.ERROR: 0 ]; | |
206 | |
207 writefln("parsing: %s", file); | |
208 FStime logTime = getFStime(file); | |
209 Stream source = new BufferedFile(file, FileMode.In); | |
210 while(!source.eof()){ | |
211 add(source.readLine()); | |
212 } | |
213 dropBogusResults(logTime, "dstress"); | |
214 } | |
215 | |
216 | |
217 void dropBogusResults(FStime recordTime, char[] testRoot){ | |
218 uint totalCount = tests.length; | |
219 | |
220 char[][] sourcesTests = tests.keys; | |
221 foreach(char[] source; sourcesTests){ | |
222 if(find(source, "complex/") < 0){ | |
223 try{ | |
224 FStime caseTime = getFStime(testRoot~std.path.sep~source); | |
225 if(caseTime > recordTime){ | |
226 debug(drop) fwritefln(stderr, "dropped: %s", source); | |
227 counts[tests[source].r & Result.BASE_MASK]--; | |
228 tests.remove(source); | |
229 } | |
230 }catch(Exception e){ | |
231 debug(drop) fwritefln(stderr, "dropped: %s", source); | |
232 counts[tests[source].r & Result.BASE_MASK]--; | |
233 tests.remove(source); | |
234 } | |
235 } | |
236 // asm-filter | |
237 int i = find(source, "asm_p"); | |
238 if(i >= 0){ | |
239 counts[tests[source].r & Result.BASE_MASK]--; | |
240 tests.remove(source); | |
241 } | |
242 } | |
243 tests.rehash; | |
244 | |
245 writefln("dropped %s outdated tests (%s remaining)", totalCount - tests.length, tests.length); | |
246 } | |
247 | |
248 | |
249 bool add(char[] line){ | |
250 const char[] SUB = "Torture-Sub-"; | |
251 const char[] TORTURE = "Torture:"; | |
252 | |
253 line = strip(line); | |
254 int id = -1; | |
255 Result r = Result.UNTESTED; | |
256 | |
257 if(line.length > SUB.length && line[0 .. SUB.length] == SUB){ | |
258 line = line[SUB.length .. $]; | |
259 id = 0; | |
260 while(line[id] >= '0' && line[id] <= '9'){ | |
261 id++; | |
262 } | |
263 int start = id; | |
264 id = std.conv.toUint(line[0 .. id]); | |
265 | |
266 while(line[start] != '-'){ | |
267 start++; | |
268 } | |
269 line = line[start+1 .. $]; | |
270 } | |
271 | |
272 char[][] token = split(line); | |
273 if(token.length < 2){ | |
274 return false; | |
275 } | |
276 char[] file = strip(token[1]); | |
277 | |
278 switch(token[0]){ | |
279 case "PASS:": | |
280 r = Result.PASS; break; | |
281 case "FAIL:": | |
282 r = Result.FAIL; break; | |
283 case "XPASS:": | |
284 r = Result.XPASS; break; | |
285 case "XFAIL:": | |
286 r = Result.XFAIL; break; | |
287 case "ERROR:": | |
288 r = Result.ERROR; break; | |
289 default:{ | |
290 if(token[0] == TORTURE){ | |
291 throw new Exception("not yet handled: "~line); | |
292 }else if(id > -1){ | |
293 throw new Exception(format("bug in SUB line: (%s) %s", id, line)); | |
294 } | |
295 } | |
296 } | |
297 | |
298 if(r != Result.UNTESTED){ | |
299 if(std.string.find(line, "bad error message") > -1){ | |
300 r |= Result.BAD_MSG; | |
301 } | |
302 if(std.string.find(line, "bad debugger message") > -1){ | |
303 r |= Result.BAD_MSG; | |
304 } | |
305 | |
306 file = cleanFileName(file); | |
307 | |
308 if(id >= 0){ | |
309 // update sub | |
310 id--; | |
311 | |
312 Test* test = file in tests; | |
313 | |
314 if(test is null){ | |
315 Test t = new Test(file); | |
316 tests[file] = t; | |
317 t.r = r; | |
318 counts[r & Result.BASE_MASK]++; | |
319 }else{ | |
320 if(test.r != Result.UNTESTED){ | |
321 test.r = Result.UNTESTED; | |
322 } | |
323 test.r = r; | |
324 } | |
325 } | |
326 return true; | |
327 } | |
328 return false; | |
329 } | |
330 } | |
331 | |
332 | |
333 int main(char[][] args){ | |
334 | |
335 if(args.length < 2){ | |
257 | 336 fwritefln(stderr, "%s [--regenerate] <log> <log> ...", args[0]); |
255 | 337 fwritefln(stderr, "bash example: %s $(ls reference/llvmdc*)", args[0]); |
338 return 1; | |
339 } | |
340 | |
257 | 341 bool regenerate = false; |
342 char[][] files; | |
343 if(args[1] == "--regenerate") { | |
344 regenerate = true; | |
345 files = args[2..$]; | |
346 } else { | |
347 files = args[1..$]; | |
348 } | |
349 | |
255 | 350 // make sure base path exists |
351 char[] basedir = "web"; | |
352 if(std.file.exists(basedir) && !std.file.isdir(basedir)) | |
353 throw new Exception(basedir ~ " is not a directory!"); | |
354 else if(!std.file.exists(basedir)) | |
355 std.file.mkdir(basedir); | |
356 | |
357 | |
358 Log[char[]] logs; | |
359 | |
360 // parse log and emit per-log data if necessary | |
257 | 361 foreach(char[] file; files){ |
255 | 362 char[] id = std.path.getBaseName(file); |
363 char[] dirname = std.path.join(basedir, id); | |
364 | |
365 if(std.file.exists(dirname)) { | |
366 if(std.file.isdir(dirname)) { | |
257 | 367 if(!regenerate) { |
368 writefln("Directory ", dirname, " already exists, skipping..."); | |
369 continue; | |
370 } | |
255 | 371 } |
372 else | |
373 throw new Exception(dirname ~ " is not a directory!"); | |
374 } | |
375 else | |
376 std.file.mkdir(dirname); | |
377 | |
378 // parse etc. | |
379 Log log = new Log(id, file); | |
380 logs[id] = log; | |
381 | |
382 // write status | |
383 BufferedFile makeFile(char[] name) { | |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
384 return new BufferedFile(std.path.join(dirname, name), FileMode.OutNew); |
255 | 385 } |
386 BufferedFile[Result] resultsfile = [ | |
387 Result.PASS: makeFile("pass.html"), | |
388 Result.FAIL: makeFile("fail.html"), | |
389 Result.XPASS: makeFile("xpass.html"), | |
390 Result.XFAIL: makeFile("xfail.html"), | |
391 Result.ERROR: makeFile("error.html") ]; | |
392 | |
393 scope(exit) { | |
394 foreach(file; resultsfile) | |
395 file.close(); | |
396 } | |
397 | |
398 | |
399 foreach(tkey; log.tests.keys.sort) { | |
400 auto test = log.tests[tkey]; | |
401 auto result = test.r & Result.BASE_MASK; | |
257 | 402 resultsfile[result].writefln(test.name, " in ", test.file); |
255 | 403 } |
404 | |
405 | |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
406 BufferedFile stats = new BufferedFile(std.path.join(dirname, "stats.base"), FileMode.OutNew); |
255 | 407 scope(exit) stats.close(); |
408 stats.writefln(`<tr>`); | |
409 stats.writefln(`<td style="padding-right:1em; text-align:left;">`, id, `</td>`); | |
410 stats.writefln(`<td><a href="`, std.path.join(log.id, "pass.html"), `">`, log.counts[Result.PASS], `</a></td>`); | |
411 stats.writefln(`<td><a href="`, std.path.join(log.id, "xfail.html"), `">`, log.counts[Result.XFAIL], `</a></td>`); | |
412 stats.writefln(`<td><a href="`, std.path.join(log.id, "fail.html"), `">`, log.counts[Result.FAIL], `</a></td>`); | |
413 stats.writefln(`<td><a href="`, std.path.join(log.id, "xpass.html"), `">`, log.counts[Result.XPASS], `</a></td>`); | |
414 stats.writefln(`<td><a href="`, std.path.join(log.id, "error.html"), `">`, log.counts[Result.ERROR], `</a></td>`); | |
415 stats.writefln(`</tr>`); | |
416 } | |
417 | |
418 // differences between logs | |
257 | 419 foreach(int i, char[] file; files[1 .. $]){ |
420 char[] newid = std.path.getBaseName(files[1+i]); | |
421 char[] oldid = std.path.getBaseName(files[1+i-1]); | |
255 | 422 |
423 char[] dirname = std.path.join(basedir, oldid ~ "-to-" ~ newid); | |
424 | |
425 if(std.file.exists(dirname)) { | |
426 if(std.file.isdir(dirname)) { | |
257 | 427 if(!regenerate) { |
428 writefln("Directory ", dirname, " already exists, skipping..."); | |
429 continue; | |
430 } | |
255 | 431 } |
432 else | |
433 throw new Exception(dirname ~ " is not a directory!"); | |
434 } | |
435 else | |
436 std.file.mkdir(dirname); | |
437 | |
438 // parse etc. | |
439 Log newLog, oldLog; | |
440 Log getOrParse(char[] id, char[] file) { | |
441 if(id in logs) | |
442 return logs[id]; | |
443 else { | |
444 Log tmp = new Log(id, file); | |
445 logs[id] = tmp; | |
446 return tmp; | |
447 } | |
448 } | |
257 | 449 newLog = getOrParse(newid, files[1+i]); |
450 oldLog = getOrParse(oldid, files[1+i-1]); | |
255 | 451 |
452 int nRegressions, nImprovements, nChanges; | |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
453 auto regressionsFile = new BufferedFile(std.path.join(dirname, "regressions.html"), FileMode.OutNew); |
255 | 454 scope(exit) regressionsFile.close(); |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
455 auto improvementsFile = new BufferedFile(std.path.join(dirname, "improvements.html"), FileMode.OutNew); |
255 | 456 scope(exit) improvementsFile.close(); |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
457 auto changesFile = new BufferedFile(std.path.join(dirname, "changes.html"), FileMode.OutNew); |
255 | 458 scope(exit) changesFile.close(); |
459 BufferedFile targetFile; | |
460 | |
461 foreach(Test t; newLog.tests.values){ | |
462 Test* oldT = t.file in oldLog.tests; | |
463 | |
464 if(oldT !is null){ | |
465 if(oldT.r == t.r) | |
466 continue; | |
467 else if(oldT.r < t.r && oldT.r && oldT.r <= Result.XFAIL){ | |
468 targetFile = regressionsFile; | |
469 nRegressions++; | |
470 } | |
471 else if(t.r < oldT.r && t.r && t.r <= Result.XFAIL){ | |
472 targetFile = improvementsFile; | |
473 nImprovements++; | |
474 } | |
475 else { | |
476 targetFile = changesFile; | |
477 nChanges++; | |
478 } | |
257 | 479 targetFile.writefln(toString(oldT.r), " -> ", toString(t.r), " : ", t.name, " in ", t.file); |
255 | 480 } |
481 } | |
482 | |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
483 BufferedFile stats = new BufferedFile(std.path.join(dirname, "stats.base"), FileMode.OutNew); |
255 | 484 scope(exit) stats.close(); |
485 auto dir = oldid ~ "-to-" ~ newid; | |
486 stats.writefln(`<tr><td></td>`); | |
487 stats.writefln(`<td style="background-color:white;" colspan="5">`); | |
488 stats.writefln(`<a href="`, std.path.join(dir, "improvements.html"), `">Improvements: `, nImprovements, `</a>, `); | |
489 stats.writefln(`<a href="`, std.path.join(dir, "regressions.html"), `">Regressions: `, nRegressions, `</a>, `); | |
490 stats.writefln(`<a href="`, std.path.join(dir, "changes.html"), `">Changes: `, nChanges, `</a></td>`); | |
491 stats.writefln(`</tr>`); | |
492 } | |
493 | |
494 // collect all the stats.base files into a large table | |
261
5723b7385c25
[svn r279] fixed bug in makewebstatistics, regenerated output
ChristianK
parents:
257
diff
changeset
|
495 BufferedFile index = new BufferedFile(std.path.join(basedir, "index.html"), FileMode.OutNew); |
255 | 496 scope(exit) index.close(); |
497 index.writefln(` | |
256 | 498 <html><body> |
255 | 499 <table style="border-collapse:collapse; text-align:center;"> |
500 <colgroup> | |
501 <col style="border-right: medium solid black;"> | |
502 <col style="background-color: #AAFFAA;"> | |
503 <col style="background-color: #AAFFAA; border-right: thin solid black;"> | |
504 <col style="background-color: #FFAAAA;"> | |
505 <col style="background-color: #FFAAAA;"> | |
506 <col style="background-color: #FFAAAA;"> | |
507 </colgroup> | |
508 <tr style="border-bottom: medium solid black;"> | |
509 <th>name</th> | |
510 <th style="padding-left:1em;padding-right:1em;">PASS</th> | |
511 <th style="padding-left:1em;padding-right:1em;">XFAIL</th> | |
512 <th style="padding-left:1em;padding-right:1em;">FAIL</th> | |
513 <th style="padding-left:1em;padding-right:1em;">XPASS</th> | |
514 <th style="padding-left:1em;padding-right:1em;">ERROR</th> | |
515 </tr> | |
516 `); | |
517 | |
257 | 518 for(int i = files.length - 1; i >= 0; --i) { |
519 auto file = files[i]; | |
255 | 520 char[] id = std.path.getBaseName(file); |
521 char[] statsname = std.path.join(std.path.join(basedir, id), "stats.base"); | |
522 index.writef(cast(char[])std.file.read(statsname)); | |
523 | |
257 | 524 if(i == 0) |
255 | 525 continue; |
526 | |
257 | 527 char[] newid = std.path.getBaseName(files[i-1]); |
255 | 528 statsname = std.path.join(std.path.join(basedir, newid ~ "-to-" ~ id), "stats.base"); |
529 index.writef(cast(char[])std.file.read(statsname)); | |
530 } | |
531 | |
256 | 532 index.writefln(`</table></body></html>`); |
255 | 533 |
534 return 0; | |
535 } | |
536 |