[Piglit] [PATCH v2 1/2] framework: Add new formatted summary.

Rafael Antognolli rafael.antognolli at intel.com
Sat Nov 18 00:06:38 UTC 2017


Similarly to print-cmd, this option allows one to specify a format
string to output each test in the summary. It can be used to easily
generate a list of only tests that failed, with something like:

./piglit summary formatted -e pass -e skip -e notrun --format {name} \
      results.json.bz2 > ../piglit-summary.txt

This file can then be used as input to piglit run --test-list.

v2: Fix typo and s/testResults/test_results/ (Dylan)

Signed-off-by: Rafael Antognolli <rafael.antognolli at intel.com>
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>
---
 framework/programs/summary.py | 58 ++++++++++++++++++++++++++++++++++++++++++-
 piglit                        |  4 +++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index e400d9a76..954a86c48 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -40,6 +40,7 @@ __all__ = [
     'csv',
     'html',
     'feature'
+    'formatted'
 ]
 
 
@@ -122,7 +123,7 @@ def console(input_):
     """Combine files in a tests/ directory into a single results file."""
     unparsed = parsers.parse_config(input_)[1]
 
-    # Adding the parent is necissary to get the help options
+    # Adding the parent is necessary to get the help options
     parser = argparse.ArgumentParser(parents=[parsers.CONFIG])
 
     # Set the -d and -s options as exclusive, since it's silly to call for diff
@@ -200,6 +201,61 @@ def csv(input_):
     else:
         write_results(sys.stdout)
 
+ at exceptions.handler
+def formatted(input_):
+    # Make a copy of the status text list and add all. This is used as the
+    # argument list for -e/--exclude
+    statuses = set(str(s) for s in status.ALL)
+
+    unparsed = parsers.parse_config(input_)[1]
+
+    # Adding the parent is necissary to get the help options
+    parser = argparse.ArgumentParser(parents=[parsers.CONFIG])
+    parser.add_argument("--format",
+                        dest="format_string",
+                        metavar="<format string>",
+                        default="{name} ::: {time} ::: "
+                                "{returncode} ::: {result}",
+                        action="store",
+                        help="A template string that defines the format. "
+                             "Replacement tokens are {name}, {time}, "
+                             "{returncode} and {result}")
+    parser.add_argument("-e", "--exclude-details",
+                        default=[],
+                        action="append",
+                        choices=statuses,
+                        help="Optionally exclude the listing of tests with "
+                             "the status(es) given as arguments. "
+                             "May be used multiple times")
+    parser.add_argument("-o", "--output",
+                        metavar="<Output File>",
+                        action="store",
+                        dest="output",
+                        default="stdout",
+                        help="Output filename")
+    parser.add_argument("test_results",
+                        metavar="<Input Files>",
+                        help="JSON results file to be converted")
+    args = parser.parse_args(unparsed)
+
+    testrun = backends.load(args.test_results)
+
+    def write_results(output):
+        for name, result in six.iteritems(testrun.tests):
+            if result.result in args.exclude_details:
+                continue
+            output.write((args.format_string + "\n").format(
+                name=name,
+                time=result.time.total,
+                returncode=result.returncode,
+                result=result.result))
+
+    if args.output != "stdout":
+        with open(args.output, 'w') as output:
+            write_results(output)
+    else:
+        write_results(sys.stdout)
+
 
 @exceptions.handler
 def aggregate(input_):
diff --git a/piglit b/piglit
index 6c1d30ae8..0bc753402 100755
--- a/piglit
+++ b/piglit
@@ -149,6 +149,10 @@ def main():
                                     add_help=False,
                                     help='generate csv from results')
     csv.set_defaults(func=summary.csv)
+    formatted = summary_parser.add_parser('formatted',
+                                    add_help=False,
+                                    help='generate formatted output from results')
+    formatted.set_defaults(func=summary.formatted)
     aggregate = summary_parser.add_parser('aggregate',
                                           add_help=False,
                                           help="Aggregate incomplete piglit run.")
-- 
2.13.6



More information about the Piglit mailing list