Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 1 | # Process the test results |
| 2 | # Test status (like passed, or failed with error code) |
| 3 | |
| 4 | import argparse |
| 5 | import re |
| 6 | import TestScripts.NewParser as parse |
| 7 | import TestScripts.CodeGen |
| 8 | from collections import deque |
| 9 | import os.path |
| 10 | import csv |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 11 | import TestScripts.ParseTrace |
Christophe Favergeon | 30c0379 | 2019-10-03 12:47:41 +0100 | [diff] [blame] | 12 | import colorama |
| 13 | from colorama import init,Fore, Back, Style |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 14 | import sys |
| 15 | |
| 16 | resultStatus=0 |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 17 | |
Christophe Favergeon | 30c0379 | 2019-10-03 12:47:41 +0100 | [diff] [blame] | 18 | init() |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 19 | |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 20 | |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 21 | def errorStr(id): |
| 22 | if id == 1: |
| 23 | return("UNKNOWN_ERROR") |
| 24 | if id == 2: |
| 25 | return("Equality error") |
| 26 | if id == 3: |
| 27 | return("Absolute difference error") |
| 28 | if id == 4: |
| 29 | return("Relative difference error") |
| 30 | if id == 5: |
| 31 | return("SNR error") |
| 32 | if id == 6: |
| 33 | return("Different length error") |
| 34 | if id == 7: |
| 35 | return("Assertion error") |
| 36 | if id == 8: |
| 37 | return("Memory allocation error") |
| 38 | if id == 9: |
| 39 | return("Empty pattern error") |
| 40 | if id == 10: |
| 41 | return("Buffer tail corrupted") |
Christophe Favergeon | f055bd3 | 2019-10-15 12:30:30 +0100 | [diff] [blame] | 42 | if id == 11: |
| 43 | return("Close float error") |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 44 | |
| 45 | return("Unknown error %d" % id) |
| 46 | |
| 47 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 48 | def findItem(root,path): |
| 49 | """ Find a node in a tree |
| 50 | |
| 51 | Args: |
| 52 | path (list) : A list of node ID |
| 53 | This list is describing a path in the tree. |
| 54 | By starting from the root and following this path, |
| 55 | we can find the node in the tree. |
| 56 | Raises: |
| 57 | Nothing |
| 58 | Returns: |
| 59 | TreeItem : A node |
| 60 | """ |
| 61 | # The list is converted into a queue. |
| 62 | q = deque(path) |
| 63 | q.popleft() |
| 64 | c = root |
| 65 | while q: |
| 66 | n = q.popleft() |
| 67 | # We get the children based on its ID and continue |
| 68 | c = c[n-1] |
| 69 | return(c) |
| 70 | |
| 71 | def joinit(iterable, delimiter): |
| 72 | # Intersperse a delimiter between element of a list |
| 73 | it = iter(iterable) |
| 74 | yield next(it) |
| 75 | for x in it: |
| 76 | yield delimiter |
| 77 | yield x |
| 78 | |
| 79 | # Return test result as a text tree |
| 80 | class TextFormatter: |
| 81 | def start(self): |
| 82 | None |
| 83 | |
| 84 | def printGroup(self,elem,theId): |
| 85 | if elem is None: |
| 86 | elem = root |
| 87 | message=elem.data["message"] |
| 88 | if not elem.data["deprecated"]: |
| 89 | kind = "Suite" |
| 90 | ident = " " * elem.ident |
| 91 | if elem.kind == TestScripts.Parser.TreeElem.GROUP: |
| 92 | kind = "Group" |
| 93 | #print(elem.path) |
Christophe Favergeon | 30c0379 | 2019-10-03 12:47:41 +0100 | [diff] [blame] | 94 | print(Style.BRIGHT + ("%s%s : %s (%d)" % (ident,kind,message,theId)) + Style.RESET_ALL) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 95 | |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 96 | def printTest(self,elem, theId, theError,errorDetail,theLine,passed,cycles,params): |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 97 | message=elem.data["message"] |
| 98 | if not elem.data["deprecated"]: |
| 99 | kind = "Test" |
| 100 | ident = " " * elem.ident |
Christophe Favergeon | 30c0379 | 2019-10-03 12:47:41 +0100 | [diff] [blame] | 101 | p=Fore.RED + "FAILED" + Style.RESET_ALL |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 102 | if passed == 1: |
Christophe Favergeon | 30c0379 | 2019-10-03 12:47:41 +0100 | [diff] [blame] | 103 | p= Fore.GREEN + "PASSED" + Style.RESET_ALL |
| 104 | print("%s%s %s(%d)%s : %s (cycles = %d)" % (ident,message,Style.BRIGHT,theId,Style.RESET_ALL,p,cycles)) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 105 | if params: |
| 106 | print("%s %s" % (ident,params)) |
| 107 | if passed != 1: |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 108 | print(Fore.RED + ("%s %s at line %d" % (ident, errorStr(theError), theLine)) + Style.RESET_ALL) |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 109 | if (len(errorDetail)>0): |
| 110 | print(Fore.RED + ident + " " + errorDetail + Style.RESET_ALL) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 111 | |
| 112 | def pop(self): |
| 113 | None |
| 114 | |
| 115 | def end(self): |
| 116 | None |
| 117 | |
Christophe Favergeon | e972cbd | 2019-11-19 15:54:13 +0100 | [diff] [blame] | 118 | # Return test result as a text tree |
| 119 | class HTMLFormatter: |
| 120 | def __init__(self): |
| 121 | self.nb=1 |
| 122 | self.suite=False |
| 123 | |
| 124 | def start(self): |
| 125 | print("<html><head><title>Test Results</title></head><body>") |
| 126 | |
| 127 | def printGroup(self,elem,theId): |
| 128 | if elem is None: |
| 129 | elem = root |
| 130 | message=elem.data["message"] |
| 131 | if not elem.data["deprecated"]: |
| 132 | kind = "Suite" |
| 133 | ident = " " * elem.ident |
| 134 | if elem.kind == TestScripts.Parser.TreeElem.GROUP: |
| 135 | kind = "Group" |
| 136 | if kind == "Group": |
| 137 | print("<h%d> %s (%d) </h%d>" % (self.nb,message,theId,self.nb)) |
| 138 | else: |
| 139 | print("<h%d> %s (%d) </h%d>" % (self.nb,message,theId,self.nb)) |
| 140 | self.suite=True |
| 141 | print("<table style=\"width:100%\">") |
| 142 | print("<tr>") |
| 143 | print("<td>Name</td>") |
| 144 | print("<td>ID</td>") |
| 145 | print("<td>Status</td>") |
Christophe Favergeon | 59aeeea | 2019-11-20 13:39:05 +0100 | [diff] [blame] | 146 | print("<td>Params</td>") |
Christophe Favergeon | e972cbd | 2019-11-19 15:54:13 +0100 | [diff] [blame] | 147 | print("<td>Cycles</td>") |
| 148 | print("</tr>") |
| 149 | self.nb = self.nb + 1 |
| 150 | |
| 151 | def printTest(self,elem, theId, theError,errorDetail,theLine,passed,cycles,params): |
| 152 | message=elem.data["message"] |
| 153 | if not elem.data["deprecated"]: |
| 154 | kind = "Test" |
| 155 | ident = " " * elem.ident |
| 156 | p="<font color=\"red\">FAILED</font>" |
| 157 | if passed == 1: |
| 158 | p= "<font color=\"green\">PASSED</font>" |
| 159 | print("<tr>") |
| 160 | print("<td><pre>%s</pre></td>" % message) |
| 161 | print("<td>%d</td>" % theId) |
| 162 | print("<td>%s</td>" % p) |
Christophe Favergeon | 59aeeea | 2019-11-20 13:39:05 +0100 | [diff] [blame] | 163 | if params: |
| 164 | print("<td>%s</td>\n" % (params)) |
| 165 | else: |
| 166 | print("<td></td>\n") |
Christophe Favergeon | e972cbd | 2019-11-19 15:54:13 +0100 | [diff] [blame] | 167 | print("<td>%d</td>" % cycles) |
| 168 | print("</tr>") |
Christophe Favergeon | 59aeeea | 2019-11-20 13:39:05 +0100 | [diff] [blame] | 169 | |
Christophe Favergeon | e972cbd | 2019-11-19 15:54:13 +0100 | [diff] [blame] | 170 | if passed != 1: |
| 171 | |
| 172 | print("<tr><td colspan=4><font color=\"red\">%s at line %d</font></td></tr>" % (errorStr(theError), theLine)) |
| 173 | if (len(errorDetail)>0): |
| 174 | print("<tr><td colspan=4><font color=\"red\">" + errorDetail + "</font></td></tr>") |
| 175 | |
| 176 | def pop(self): |
| 177 | if self.suite: |
| 178 | print("</table>") |
| 179 | self.nb = self.nb - 1 |
| 180 | self.suite=False |
| 181 | |
| 182 | def end(self): |
| 183 | print("</body></html>") |
| 184 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 185 | # Return test result as a CSV |
| 186 | class CSVFormatter: |
| 187 | |
| 188 | def __init__(self): |
| 189 | self.name=[] |
| 190 | self._start=True |
| 191 | |
| 192 | def start(self): |
| 193 | print("CATEGORY,NAME,ID,STATUS,CYCLES,PARAMS") |
| 194 | |
| 195 | def printGroup(self,elem,theId): |
| 196 | if elem is None: |
| 197 | elem = root |
| 198 | # Remove Root from category name in CSV file. |
| 199 | if not self._start: |
| 200 | self.name.append(elem.data["class"]) |
| 201 | else: |
| 202 | self._start=False |
| 203 | message=elem.data["message"] |
| 204 | if not elem.data["deprecated"]: |
| 205 | kind = "Suite" |
| 206 | ident = " " * elem.ident |
| 207 | if elem.kind == TestScripts.Parser.TreeElem.GROUP: |
| 208 | kind = "Group" |
| 209 | |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 210 | def printTest(self,elem, theId, theError, errorDetail,theLine,passed,cycles,params): |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 211 | message=elem.data["message"] |
| 212 | if not elem.data["deprecated"]: |
| 213 | kind = "Test" |
| 214 | name=elem.data["class"] |
| 215 | category= "".join(list(joinit(self.name,":"))) |
| 216 | print("%s,%s,%d,%d,%d,\"%s\"" % (category,name,theId,passed,cycles,params)) |
| 217 | |
| 218 | def pop(self): |
| 219 | if self.name: |
| 220 | self.name.pop() |
| 221 | |
| 222 | def end(self): |
| 223 | None |
| 224 | |
| 225 | class MathematicaFormatter: |
| 226 | |
| 227 | def __init__(self): |
| 228 | self._hasContent=[False] |
| 229 | self._toPop=[] |
| 230 | |
| 231 | def start(self): |
| 232 | None |
| 233 | |
| 234 | def printGroup(self,elem,theId): |
| 235 | if self._hasContent[len(self._hasContent)-1]: |
| 236 | print(",",end="") |
| 237 | |
| 238 | print("<|") |
| 239 | self._hasContent[len(self._hasContent)-1] = True |
| 240 | self._hasContent.append(False) |
| 241 | if elem is None: |
| 242 | elem = root |
| 243 | message=elem.data["message"] |
| 244 | if not elem.data["deprecated"]: |
| 245 | |
| 246 | kind = "Suite" |
| 247 | ident = " " * elem.ident |
| 248 | if elem.kind == TestScripts.Parser.TreeElem.GROUP: |
| 249 | kind = "Group" |
| 250 | print("\"%s\" ->" % (message)) |
| 251 | #if kind == "Suite": |
| 252 | print("{",end="") |
| 253 | self._toPop.append("}") |
| 254 | #else: |
| 255 | # self._toPop.append("") |
| 256 | |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 257 | def printTest(self,elem, theId, theError,errorDetail,theLine,passed,cycles,params): |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 258 | message=elem.data["message"] |
| 259 | if not elem.data["deprecated"]: |
| 260 | kind = "Test" |
| 261 | ident = " " * elem.ident |
| 262 | p="FAILED" |
| 263 | if passed == 1: |
| 264 | p="PASSED" |
| 265 | parameters="" |
| 266 | if params: |
| 267 | parameters = "%s" % params |
| 268 | if self._hasContent[len(self._hasContent)-1]: |
| 269 | print(",",end="") |
| 270 | print("<|\"NAME\" -> \"%s\",\"ID\" -> %d,\"STATUS\" -> \"%s\",\"CYCLES\" -> %d,\"PARAMS\" -> \"%s\"|>" % (message,theId,p,cycles,parameters)) |
| 271 | self._hasContent[len(self._hasContent)-1] = True |
| 272 | #if passed != 1: |
| 273 | # print("%s Error = %d at line %d" % (ident, theError, theLine)) |
| 274 | |
| 275 | def pop(self): |
| 276 | print(self._toPop.pop(),end="") |
| 277 | print("|>") |
| 278 | self._hasContent.pop() |
| 279 | |
| 280 | def end(self): |
| 281 | None |
| 282 | |
| 283 | NORMAL = 1 |
| 284 | INTEST = 2 |
| 285 | TESTPARAM = 3 |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 286 | ERRORDESC = 4 |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 287 | |
| 288 | def createMissingDir(destPath): |
| 289 | theDir=os.path.normpath(os.path.dirname(destPath)) |
| 290 | if not os.path.exists(theDir): |
| 291 | os.makedirs(theDir) |
| 292 | |
| 293 | def correctPath(path): |
| 294 | while (path[0]=="/") or (path[0] == "\\"): |
| 295 | path = path[1:] |
| 296 | return(path) |
| 297 | |
| 298 | def extractDataFiles(results,outputDir): |
| 299 | infile = False |
| 300 | f = None |
| 301 | for l in results: |
| 302 | if re.match(r'^.*D:[ ].*$',l): |
| 303 | if infile: |
| 304 | if re.match(r'^.*D:[ ]END$',l): |
| 305 | infile = False |
| 306 | if f: |
| 307 | f.close() |
| 308 | else: |
| 309 | if f: |
| 310 | m = re.match(r'^.*D:[ ](.*)$',l) |
| 311 | data = m.group(1) |
| 312 | f.write(data) |
| 313 | f.write("\n") |
| 314 | |
| 315 | else: |
| 316 | m = re.match(r'^.*D:[ ](.*)$',l) |
| 317 | path = str(m.group(1)) |
| 318 | infile = True |
| 319 | destPath = os.path.join(outputDir,correctPath(path)) |
| 320 | createMissingDir(destPath) |
| 321 | f = open(destPath,"w") |
| 322 | |
| 323 | |
| 324 | |
| 325 | def writeBenchmark(elem,benchFile,theId,theError,passed,cycles,params,config): |
| 326 | if benchFile: |
| 327 | name=elem.data["class"] |
| 328 | category= elem.categoryDesc() |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 329 | old="" |
| 330 | if "testData" in elem.data: |
| 331 | if "oldID" in elem.data["testData"]: |
| 332 | old=elem.data["testData"]["oldID"] |
| 333 | benchFile.write("\"%s\",\"%s\",%d,\"%s\",%s,%d,%s\n" % (category,name,theId,old,params,cycles,config)) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 334 | |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 335 | def getCyclesFromTrace(trace): |
| 336 | if not trace: |
| 337 | return(0) |
| 338 | else: |
| 339 | return(TestScripts.ParseTrace.getCycles(trace)) |
| 340 | |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 341 | def analyseResult(resultPath,root,results,embedded,benchmark,trace,formatter): |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 342 | global resultStatus |
Christophe Favergeon | be7efb4 | 2019-08-09 10:17:03 +0100 | [diff] [blame] | 343 | calibration = 0 |
| 344 | if trace: |
| 345 | # First cycle in the trace is the calibration data |
| 346 | # The noramlisation factor must be coherent with the C code one. |
| 347 | calibration = int(getCyclesFromTrace(trace) / 20) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 348 | formatter.start() |
| 349 | path = [] |
| 350 | state = NORMAL |
| 351 | prefix="" |
| 352 | elem=None |
| 353 | theId=None |
| 354 | theError=None |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 355 | errorDetail="" |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 356 | theLine=None |
| 357 | passed=0 |
| 358 | cycles=None |
| 359 | benchFile = None |
| 360 | config="" |
| 361 | if embedded: |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame] | 362 | prefix = ".*[S]+:[ ]" |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 363 | |
| 364 | # Parse the result file. |
| 365 | # NORMAL mode is when we are parsing suite or group. |
| 366 | # Otherwise we are parsing a test and we need to analyse the |
| 367 | # test result. |
| 368 | # TESTPARAM is used to read parameters of the test. |
| 369 | # Format of output is: |
| 370 | #node ident : s id or g id or t or u |
| 371 | #test status : id error linenb status Y or N (Y when passing) |
| 372 | #param for this test b x,x,x,x or b alone if not param |
| 373 | #node end : p |
| 374 | # In FPGA mode: |
| 375 | #Prefix S:[ ] before driver dump |
| 376 | # D:[ ] before data dump (output patterns) |
| 377 | |
| 378 | for l in results: |
| 379 | l = l.strip() |
| 380 | if not re.match(r'^.*D:[ ].*$',l): |
| 381 | if state == NORMAL: |
| 382 | if len(l) > 0: |
| 383 | # Line starting with g or s is a suite or group. |
| 384 | # In FPGA mode, those line are prefixed with 'S: ' |
| 385 | # and data file with 'D: ' |
| 386 | if re.match(r'^%s[gs][ ]+[0-9]+.*$' % prefix,l): |
| 387 | # Extract the test id |
| 388 | theId=re.sub(r'^%s[gs][ ]+([0-9]+).*$' % prefix,r'\1',l) |
| 389 | theId=int(theId) |
| 390 | path.append(theId) |
| 391 | # From a list of id, find the TreeElem in the Parsed tree |
| 392 | # to know what is the node. |
| 393 | elem = findItem(root,path) |
| 394 | # Display formatted output for this node |
| 395 | if elem.params: |
| 396 | #print(elem.params.full) |
| 397 | benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv") |
| 398 | createMissingDir(benchPath) |
| 399 | if benchFile: |
| 400 | printf("ERROR BENCH FILE %s ALREADY OPEN" % benchPath) |
| 401 | benchFile.close() |
| 402 | benchFile=None |
| 403 | benchFile=open(benchPath,"w") |
| 404 | header = "".join(list(joinit(elem.params.full,","))) |
| 405 | # A test and a benchmark are different |
| 406 | # so we don't dump a status and error |
| 407 | # A status and error in a benchmark would |
| 408 | # impact the cycles since the test |
| 409 | # would be taken into account in the measurement |
| 410 | # So benchmark are always passing and contain no test |
| 411 | #benchFile.write("ID,%s,PASSED,ERROR,CYCLES\n" % header) |
| 412 | csvheaders = "" |
| 413 | |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 414 | with open(os.path.join(resultPath,'currentConfig.csv'), 'r') as f: |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 415 | reader = csv.reader(f) |
| 416 | csvheaders = next(reader, None) |
| 417 | configList = list(reader) |
| 418 | #print(configList) |
| 419 | config = "".join(list(joinit(configList[0],","))) |
| 420 | configHeaders = "".join(list(joinit(csvheaders,","))) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 421 | benchFile.write("CATEGORY,NAME,ID,OLDID,%s,CYCLES,%s\n" % (header,configHeaders)) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 422 | |
| 423 | formatter.printGroup(elem,theId) |
| 424 | |
| 425 | # If we have detected a test, we switch to test mode |
| 426 | if re.match(r'^%s[t][ ]*$' % prefix,l): |
| 427 | state = INTEST |
| 428 | |
| 429 | |
| 430 | # Pop |
| 431 | # End of suite or group |
| 432 | if re.match(r'^%sp.*$' % prefix,l): |
| 433 | if benchFile: |
| 434 | benchFile.close() |
| 435 | benchFile=None |
| 436 | path.pop() |
| 437 | formatter.pop() |
| 438 | elif state == INTEST: |
| 439 | if len(l) > 0: |
| 440 | # In test mode, we are looking for test status. |
| 441 | # A line starting with S |
| 442 | # (There may be empty lines or line for data files) |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 443 | passRe = r'^%s([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)[ ]+([t0-9]+)[ ]+([YN]).*$' % prefix |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 444 | if re.match(passRe,l): |
| 445 | # If we have found a test status then we will start again |
| 446 | # in normal mode after this. |
| 447 | |
| 448 | m = re.match(passRe,l) |
| 449 | |
| 450 | # Extract test ID, test error code, line number and status |
| 451 | theId=m.group(1) |
| 452 | theId=int(theId) |
| 453 | |
| 454 | theError=m.group(2) |
| 455 | theError=int(theError) |
| 456 | |
| 457 | theLine=m.group(3) |
| 458 | theLine=int(theLine) |
| 459 | |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 460 | maybeCycles = m.group(4) |
| 461 | if maybeCycles == "t": |
Christophe Favergeon | be7efb4 | 2019-08-09 10:17:03 +0100 | [diff] [blame] | 462 | cycles = getCyclesFromTrace(trace) - calibration |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 463 | else: |
| 464 | cycles = int(maybeCycles) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 465 | |
| 466 | status=m.group(5) |
| 467 | passed=0 |
| 468 | |
| 469 | # Convert status to number as used by formatter. |
| 470 | if status=="Y": |
| 471 | passed = 1 |
| 472 | if status=="N": |
| 473 | passed = 0 |
| 474 | # Compute path to this node |
| 475 | newPath=path.copy() |
| 476 | newPath.append(theId) |
| 477 | # Find the node in the Tree |
| 478 | elem = findItem(root,newPath) |
| 479 | |
| 480 | |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 481 | state = ERRORDESC |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 482 | else: |
| 483 | if re.match(r'^%sp.*$' % prefix,l): |
| 484 | if benchFile: |
| 485 | benchFile.close() |
| 486 | benchFile=None |
| 487 | path.pop() |
| 488 | formatter.pop() |
| 489 | if re.match(r'^%s[t][ ]*$' % prefix,l): |
| 490 | state = INTEST |
| 491 | else: |
| 492 | state = NORMAL |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 493 | elif state == ERRORDESC: |
| 494 | if len(l) > 0: |
| 495 | if re.match(r'^.*E:.*$',l): |
| 496 | if re.match(r'^.*E:[ ].*$',l): |
| 497 | m = re.match(r'^.*E:[ ](.*)$',l) |
| 498 | errorDetail = m.group(1) |
| 499 | else: |
| 500 | errorDetail = "" |
| 501 | state = TESTPARAM |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 502 | else: |
| 503 | if len(l) > 0: |
| 504 | state = INTEST |
| 505 | params="" |
| 506 | if re.match(r'^.*b[ ]+([0-9,]+)$',l): |
| 507 | m=re.match(r'^.*b[ ]+([0-9,]+)$',l) |
| 508 | params=m.group(1).strip() |
| 509 | # Format the node |
| 510 | #print(elem.fullPath()) |
| 511 | #createMissingDir(destPath) |
| 512 | writeBenchmark(elem,benchFile,theId,theError,passed,cycles,params,config) |
| 513 | else: |
| 514 | params="" |
| 515 | writeBenchmark(elem,benchFile,theId,theError,passed,cycles,params,config) |
| 516 | # Format the node |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 517 | if not passed: |
| 518 | resultStatus=1 |
Christophe Favergeon | 4f46273 | 2019-11-13 14:11:14 +0100 | [diff] [blame] | 519 | formatter.printTest(elem,theId,theError,errorDetail,theLine,passed,cycles,params) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 520 | |
| 521 | |
| 522 | formatter.end() |
| 523 | |
| 524 | |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 525 | def analyze(root,results,args,trace): |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 526 | # currentConfig.csv should be in the same place |
| 527 | resultPath=os.path.dirname(args.r) |
| 528 | |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 529 | if args.c: |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 530 | analyseResult(resultPath,root,results,args.e,args.b,trace,CSVFormatter()) |
Christophe Favergeon | e972cbd | 2019-11-19 15:54:13 +0100 | [diff] [blame] | 531 | elif args.html: |
| 532 | analyseResult(resultPath,root,results,args.e,args.b,trace,HTMLFormatter()) |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 533 | elif args.m: |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 534 | analyseResult(resultPath,root,results,args.e,args.b,trace,MathematicaFormatter()) |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 535 | else: |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 536 | print("") |
| 537 | print(Fore.RED + "The cycles displayed by this script must not be trusted." + Style.RESET_ALL) |
| 538 | print(Fore.RED + "They are just an indication. The timing code has not yet been validated." + Style.RESET_ALL) |
| 539 | print("") |
| 540 | |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 541 | analyseResult(resultPath,root,results,args.e,args.b,trace,TextFormatter()) |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 542 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 543 | parser = argparse.ArgumentParser(description='Parse test description') |
| 544 | |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 545 | parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Test description file path") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 546 | # Where the result file can be found |
| 547 | parser.add_argument('-r', nargs='?',type = str, default=None, help="Result file path") |
| 548 | parser.add_argument('-c', action='store_true', help="CSV output") |
Christophe Favergeon | e972cbd | 2019-11-19 15:54:13 +0100 | [diff] [blame] | 549 | parser.add_argument('-html', action='store_true', help="HTML output") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 550 | parser.add_argument('-e', action='store_true', help="Embedded test") |
| 551 | # -o needed when -e is true to know where to extract the output files |
| 552 | parser.add_argument('-o', nargs='?',type = str, default="Output", help="Output dir path") |
| 553 | |
| 554 | parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path") |
| 555 | parser.add_argument('-m', action='store_true', help="Mathematica output") |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 556 | parser.add_argument('-t', nargs='?',type = str, default=None, help="External trace file") |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 557 | |
| 558 | args = parser.parse_args() |
| 559 | |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 560 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 561 | |
| 562 | |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 563 | if args.f is not None: |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 564 | #p = parse.Parser() |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 565 | # Parse the test description file |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 566 | #root = p.parse(args.f) |
| 567 | root=parse.loadRoot(args.f) |
Christophe Favergeon | f76a803 | 2019-08-09 09:15:50 +0100 | [diff] [blame] | 568 | if args.t: |
| 569 | with open(args.t,"r") as trace: |
| 570 | with open(args.r,"r") as results: |
| 571 | analyze(root,results,args,iter(trace)) |
| 572 | else: |
| 573 | with open(args.r,"r") as results: |
| 574 | analyze(root,results,args,None) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 575 | if args.e: |
| 576 | # In FPGA mode, extract output files from stdout (result file) |
| 577 | with open(args.r,"r") as results: |
| 578 | extractDataFiles(results,args.o) |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 579 | |
| 580 | sys.exit(resultStatus) |
Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame] | 581 | |
| 582 | else: |
| 583 | parser.print_help() |