[Piglit] [PATCH 07/16] summary.py: Adds method to NewSummary to generate junit XML

Dylan Baker baker.dylan.c at gmail.com
Thu Jun 13 08:36:14 PDT 2013


This method is about 50% faster than the existing implementation which
uses junit.py.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/summary.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/framework/summary.py b/framework/summary.py
index 40f5ec0..9ceb3ba 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -808,3 +808,58 @@ class NewSummary:
                 file.write(empty_status.render(page=page, pages=pages))
 
             file.close()
+
+    def generateJUnit(self, destination):
+        """
+        Public: Generate JUnit XML output with mako
+
+        This method only works when a single resultsfile is given, and has no
+        way to do comparisons.
+        """
+        # Since JUnit only hanles one result, set a short name for that result
+        result = self.results[0].tests
+
+        xmlOutput = []
+
+        def get_class(input):
+            """
+            Helper method that takes the test as an input and returns in in
+            class form (foo.bar.oink)
+
+            Essentially replaces '/' with '.', but also replaces any '.'
+            already in the test names with '_', since '.' is special in JUnit.
+            """
+
+            input.replace('.', '_')  # replace . with _
+            out = input.split('/')   # create a list splitting on /
+            out.insert(0, 'piglit')  # insert piglit at the front
+            out.pop()                # Remove the extrea ''
+            return ".".join(out)
+
+        def get_name(input):
+            """
+            Helper that splits just the name out of the full test path
+            """
+
+            return input.split('/')[-1]
+
+        # Build a list with all of the information that mako is going to need
+        # to generate the XML
+        for test in self.tests['all']:
+            xmlOutput.append({'classname': get_class(test).
+                                  encode('utf-8', 'xmlcharrefreplace'),
+                              'testname': get_name(test).
+                                  encode('utf-8', 'xmlcharrefreplace'),
+                              'time': result[test]['time'],
+                              'system-out': result[test]['command'].
+                                  encode('utf-8', 'xmlcharrefreplace'),
+                              'system-err': result[test]['info'].
+                                  encode('utf-8', 'xmlcharrefreplace')})
+
+        # Use mako to generate the XML
+        template = Template(filename="templates/junit.mako",
+                            output_encoding="utf-8",
+                            module_directory=".makotmp")
+        file = open(destination, 'w')
+        file.write(template.render(tests=xmlOutput))
+        file.close()
-- 
1.8.1.4



More information about the Piglit mailing list