1#!/usr/bin/env python 2 3import testlog_parser, sys, os, xml, re, glob 4from table_formatter import * 5from optparse import OptionParser 6 7if __name__ == "__main__": 8 parser = OptionParser() 9 parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto") 10 parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms") 11 parser.add_option("-c", "--columns", dest="columns", help="comma-separated list of columns to show", metavar="COLS", default="") 12 parser.add_option("-f", "--filter", dest="filter", help="regex to filter tests", metavar="REGEX", default=None) 13 parser.add_option("", "--show-all", action="store_true", dest="showall", default=False, help="also include empty and \"notrun\" lines") 14 (options, args) = parser.parse_args() 15 16 if len(args) < 1: 17 print >> sys.stderr, "Usage:\n", os.path.basename(sys.argv[0]), "<log_name1>.xml" 18 exit(0) 19 20 options.generateHtml = detectHtmlOutputType(options.format) 21 22 # expand wildcards and filter duplicates 23 files = [] 24 files1 = [] 25 for arg in args: 26 if ("*" in arg) or ("?" in arg): 27 files1.extend([os.path.abspath(f) for f in glob.glob(arg)]) 28 else: 29 files.append(os.path.abspath(arg)) 30 seen = set() 31 files = [ x for x in files if x not in seen and not seen.add(x)] 32 files.extend((set(files1) - set(files))) 33 args = files 34 35 # load test data 36 tests = [] 37 files = [] 38 for arg in set(args): 39 try: 40 cases = testlog_parser.parseLogFile(arg) 41 if cases: 42 files.append(os.path.basename(arg)) 43 tests.extend(cases) 44 except: 45 pass 46 47 if options.filter: 48 expr = re.compile(options.filter) 49 tests = [t for t in tests if expr.search(str(t))] 50 51 tbl = table(", ".join(files)) 52 if options.columns: 53 metrics = [s.strip() for s in options.columns.split(",")] 54 metrics = [m for m in metrics if m and not m.endswith("%") and m in metrix_table] 55 else: 56 metrics = None 57 if not metrics: 58 metrics = ["name", "samples", "outliers", "min", "median", "gmean", "mean", "stddev"] 59 if "name" not in metrics: 60 metrics.insert(0, "name") 61 62 for m in metrics: 63 if m == "name": 64 tbl.newColumn(m, metrix_table[m][0]) 65 else: 66 tbl.newColumn(m, metrix_table[m][0], align = "center") 67 68 needNewRow = True 69 for case in sorted(tests): 70 if needNewRow: 71 tbl.newRow() 72 if not options.showall: 73 needNewRow = False 74 status = case.get("status") 75 if status != "run": 76 if status != "notrun": 77 needNewRow = True 78 for m in metrics: 79 if m == "name": 80 tbl.newCell(m, str(case)) 81 else: 82 tbl.newCell(m, status, color = "red") 83 else: 84 needNewRow = True 85 for m in metrics: 86 val = metrix_table[m][1](case, None, options.units) 87 if isinstance(val, float): 88 tbl.newCell(m, "%.2f %s" % (val, options.units), val) 89 else: 90 tbl.newCell(m, val, val) 91 if not needNewRow: 92 tbl.trimLastRow() 93 94 # output table 95 if options.generateHtml: 96 if options.format == "moinwiki": 97 tbl.htmlPrintTable(sys.stdout, True) 98 else: 99 htmlPrintHeader(sys.stdout, "Report %s tests from %s" % (len(tests), ", ".join(files))) 100 tbl.htmlPrintTable(sys.stdout) 101 htmlPrintFooter(sys.stdout) 102 else: 103 tbl.consolePrintTable(sys.stdout) 104