3 from __future__ import print_function
4 import testlog_parser, sys, os, xml, re, glob
5 from table_formatter import *
6 from optparse import OptionParser
8 if __name__ == "__main__":
9 parser = OptionParser()
10 parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto")
11 parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), us, ns or ticks)", metavar="UNITS", default="ms")
12 parser.add_option("-c", "--columns", dest="columns", help="comma-separated list of columns to show", metavar="COLS", default="")
13 parser.add_option("-f", "--filter", dest="filter", help="regex to filter tests", metavar="REGEX", default=None)
14 parser.add_option("", "--show-all", action="store_true", dest="showall", default=False, help="also include empty and \"notrun\" lines")
15 (options, args) = parser.parse_args()
18 print("Usage:\n", os.path.basename(sys.argv[0]), "<log_name1>.xml", file=sys.stderr)
21 options.generateHtml = detectHtmlOutputType(options.format)
23 # expand wildcards and filter duplicates
27 if ("*" in arg) or ("?" in arg):
28 files1.extend([os.path.abspath(f) for f in glob.glob(arg)])
30 files.append(os.path.abspath(arg))
32 files = [ x for x in files if x not in seen and not seen.add(x)]
33 files.extend((set(files1) - set(files)))
41 cases = testlog_parser.parseLogFile(arg)
43 files.append(os.path.basename(arg))
49 expr = re.compile(options.filter)
50 tests = [t for t in tests if expr.search(str(t))]
52 tbl = table(", ".join(files))
54 metrics = [s.strip() for s in options.columns.split(",")]
55 metrics = [m for m in metrics if m and not m.endswith("%") and m in metrix_table]
59 metrics = ["name", "samples", "outliers", "min", "median", "gmean", "mean", "stddev"]
60 if "name" not in metrics:
61 metrics.insert(0, "name")
65 tbl.newColumn(m, metrix_table[m][0])
67 tbl.newColumn(m, metrix_table[m][0], align = "center")
70 for case in sorted(tests, key=lambda x: str(x)):
73 if not options.showall:
75 status = case.get("status")
77 if status != "notrun":
81 tbl.newCell(m, str(case))
83 tbl.newCell(m, status, color = "red")
87 val = metrix_table[m][1](case, None, options.units)
88 if isinstance(val, float):
89 tbl.newCell(m, "%.2f %s" % (val, options.units), val)
91 tbl.newCell(m, val, val)
96 if options.generateHtml:
97 if options.format == "moinwiki":
98 tbl.htmlPrintTable(sys.stdout, True)
100 htmlPrintHeader(sys.stdout, "Report %s tests from %s" % (len(tests), ", ".join(files)))
101 tbl.htmlPrintTable(sys.stdout)
102 htmlPrintFooter(sys.stdout)
104 tbl.consolePrintTable(sys.stdout)