[Piglit] [PATCH] summary: add a csv output option

Thomas Wood thomas.wood at intel.com
Wed Oct 1 06:56:10 PDT 2014


Signed-off-by: Thomas Wood <thomas.wood at intel.com>
---
 framework/programs/summary.py | 32 +++++++++++++++++++++++++++++++-
 piglit                        |  4 ++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index 81f6d3d..7a008e8 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -22,6 +22,7 @@
 import argparse
 import shutil
 import os.path as path
+import sys
 
 import framework.summary as summary
 import framework.status as status
@@ -31,7 +32,8 @@ import framework.junit
 
 __all__ = ['html',
            'junit',
-           'console']
+           'console',
+           'csv']
 
 
 def html(input_):
@@ -244,3 +246,31 @@ def console(input_):
     # Generate the output
     output = summary.Summary(args.results)
     output.generate_text(args.diff, args.summary)
+
+
+def csv(input_):
+    parser = argparse.ArgumentParser()
+    parser.add_argument("-o", "--output",
+                        metavar="<Output File>",
+                        action="store",
+                        dest="output",
+                        default="stdout",
+                        help="Output filename")
+    parser.add_argument("testResults",
+                        metavar="<Input Files>",
+                        help="JSON results file to be converted")
+    args = parser.parse_args(input_)
+
+    testrun = framework.results.load_results(args.testResults)
+
+    def write_results(output):
+        for name, result in testrun.tests.iteritems():
+            output.write("{},{},{},{}\n".format(name, result['time'],
+                                                result['returncode'],
+                                                result['result']))
+
+    if (args.output != "stdout"):
+        with open(args.output, 'w') as output:
+            write_results(output)
+    else:
+        write_results(sys.stdout)
diff --git a/piglit b/piglit
index 8538f81..c1c2520 100755
--- a/piglit
+++ b/piglit
@@ -135,6 +135,10 @@ def main():
                                       add_help=False,
                                       help='generate junit xml from results')
     junit.set_defaults(func=summary.junit)
+    csv = summary_parser.add_parser('csv',
+                                    add_help=False,
+                                    help='generate csv from results')
+    csv.set_defaults(func=summary.csv)
 
     # Parse the known arguments (piglit run or piglit summary html for
     # example), and then pass the arguments that this parser doesn't know about
-- 
2.1.0



More information about the Piglit mailing list