|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import sys |
| 3 | +import signal |
| 4 | +import traceback |
| 5 | +import html |
| 6 | +import math |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +import cyson as yson |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + |
| 14 | + if len(sys.argv) < 2: |
| 15 | + print('Usage: {} resultdir... >report.htm'.format(sys.argv[0]), file=sys.stderr) |
| 16 | + sys.exit(1) |
| 17 | + |
| 18 | + rdirs = sys.argv[1:] |
| 19 | + data = [] |
| 20 | + |
| 21 | + print(''' |
| 22 | +<html><head><style>.signal { color: blue; } .errcode { color: red; } .ok { color: green; } .mismatch { color: yellow; } .tabnum { text-align: right; } </style></head> |
| 23 | +''') |
| 24 | + print('<table border="1">') |
| 25 | + print('<tr><th>' + ''.join(map(lambda x: '<th colspan="5">' + html.escape(rdirs[x]), range(len(rdirs))))) |
| 26 | + print('<tr><th>Testcase' + '<th>Status<th>Real time, s<th>User time, s<th>RSS, MB<th>'*len(rdirs) + '</tr>') |
| 27 | + print('<tr><th>') |
| 28 | + |
| 29 | + for dirname in rdirs: |
| 30 | + for name in sorted(map(str, Path(dirname).glob('**/summary.tsv'))): |
| 31 | + with open(name) as f: |
| 32 | + coldata = [] |
| 33 | + cmdline = f.readline() |
| 34 | + print('<th colspan="4"><span title="{}">{}</span><th>'.format(html.escape(cmdline, quote=True), html.escape(name))) |
| 35 | + for line in f: |
| 36 | + line = line.split('\t') |
| 37 | + (q, utime, stime, maxrss, exitcode, elapsed) = line[:6] |
| 38 | + utime = float(utime) |
| 39 | + stime = float(stime) |
| 40 | + maxrss = int(maxrss) |
| 41 | + exitcode = int(exitcode) |
| 42 | + elapsed = int(elapsed)*1e-9 |
| 43 | + if len(data): |
| 44 | + # assert data[0][len(coldata)][0] == q |
| 45 | + if data[0][len(coldata)][0] != q: |
| 46 | + pass |
| 47 | + coldata += [[dirname, q, elapsed, utime, stime, maxrss, exitcode]] |
| 48 | + data += [coldata] |
| 49 | + for i in range(len(data[0])): |
| 50 | + q = data[0][i][1] |
| 51 | + print('<tr><td>{}'.format(html.escape(q)), end='') |
| 52 | + for c in range(len(data)): |
| 53 | + (dirname, q, elapsed, utime, stime, maxrss, exitcode) = data[c][i] |
| 54 | + outname = dirname + '/' + q + '-result.yson' |
| 55 | + if exitcode < 0: |
| 56 | + print('<td><span class="signal" title="{}">SIG</span>'.format(html.escape(signal.strsignal(-exitcode), quote=True))) |
| 57 | + elif exitcode > 0: |
| 58 | + print('<td><span class="errcode" title="{}">ERR</span>'.format(exitcode)) |
| 59 | + else: |
| 60 | + print('<td><span class="ok">OK</span>') |
| 61 | + print('<td class="tabnum">{:.1f}<td class="tabnum">{:.1f}<td class="tabnum">{:.1f}'.format(elapsed, utime, maxrss/1024)) |
| 62 | + if exitcode == 0: |
| 63 | + try: |
| 64 | + valType = None |
| 65 | + valData = None |
| 66 | + with open(outname, 'rb') as f: |
| 67 | + for result in yson.list_fragments(yson.InputStream.from_file(f)): |
| 68 | + valType = result[0][b'Write'][0][b'Type'] |
| 69 | + valData = result[0][b'Write'][0][b'Data'] |
| 70 | + pass |
| 71 | + if c == 0: |
| 72 | + data[c][i] += [valType, valData] |
| 73 | + print('<td>') |
| 74 | + else: |
| 75 | + assert valType[0] == b'ListType' |
| 76 | + assert valType[1][0] == b'StructType' |
| 77 | + stypes = valType[1][1] |
| 78 | + ncols = len(stypes) |
| 79 | + refType = data[0][i][-2] |
| 80 | + refData = data[0][i][-1] |
| 81 | + refstypes = refType[1][1] |
| 82 | + assert ncols == len(refType[1][1]), 'Column number mismatch {} != {}'.format(ncols, len(refstypes)) |
| 83 | + nrows = len(valData) |
| 84 | + assert nrows == len(refData), 'Row number mismatch {} != {}'.format(nrows, len(refData)) |
| 85 | + for col in range(ncols): |
| 86 | + stype = stypes[col][1] |
| 87 | + isOptional = False |
| 88 | + if stype[0] == b'OptionalType': |
| 89 | + stype = stype[1] |
| 90 | + isOptional = True |
| 91 | + assert stype[0] == b'DataType' |
| 92 | + isDouble = stype[1] == b'Double' |
| 93 | + for row in range(nrows): |
| 94 | + val = valData[row][col] |
| 95 | + ref = refData[row][col] |
| 96 | + if isOptional: |
| 97 | + if ref is None: |
| 98 | + assert val is None, 'NULL != NOT NULL at {}, {}'.format(row, col) |
| 99 | + continue |
| 100 | + assert val is not None, 'NOT NULL != NULL at {}, {}'.format(row, col) |
| 101 | + ref = ref[0] |
| 102 | + val = val[0] |
| 103 | + if isDouble: |
| 104 | + val = float(val) |
| 105 | + ref = float(ref) |
| 106 | + if math.isnan(val): |
| 107 | + assert math.isnan(ref), '{} != {} at {}, {}'.format(val, ref, row, col) |
| 108 | + continue |
| 109 | + assert not math.isnan(ref), '{} != {} at {}, {}'.format(val, ref, row, col) |
| 110 | + assert abs(val - ref) <= 1e-5*max(abs(val), abs(ref), 1), 'abs({} - {}) >= eps at {}, {}'.format(val, ref, row, col) |
| 111 | + else: |
| 112 | + assert val == ref, '{} != {} type {} at {}, {}'.format(val, ref, stypes[col][1][1], row, col) |
| 113 | + print('<td class="ok">MATCH</td>') |
| 114 | + except Exception: |
| 115 | + print('<td class="errcode">Comparison failed: ', traceback.format_exc()) |
| 116 | + else: |
| 117 | + print('<td class="errcode">N/A') |
| 118 | + |
| 119 | + print('</tr>') |
| 120 | + |
| 121 | + print('</table>') |
| 122 | + print('</html>') |
| 123 | + |
| 124 | + |
| 125 | +if __name__ == '__main__': |
| 126 | + main() |
0 commit comments