[Piglit] [PATCH 1/3] framework/backends/junit.py: restore time for stderr

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Thu Oct 8 17:21:28 PDT 2015


From: Dylan Baker <baker.dylan.c at gmail.com>

This allows time to be fully restored.
---
 framework/backends/junit.py             | 12 ++++++++++++
 framework/tests/junit_backends_tests.py | 22 +++++++++++++++++-----
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/framework/backends/junit.py b/framework/backends/junit.py
index 11fb09e..ce6a27a 100644
--- a/framework/backends/junit.py
+++ b/framework/backends/junit.py
@@ -255,6 +255,9 @@ def _load(results_file):
             name = name[:-1]
 
         result.result = test.attrib['status']
+
+        # This is the fallback path, we'll try to overwrite this with the value
+        # in stderr
         result.time = results.TimeAttribute(end=float(test.attrib['time']))
         result.err = test.find('system-err').text
 
@@ -264,6 +267,15 @@ def _load(results_file):
         result.command = out[0]
         result.out = '\n'.join(out[1:])
 
+        # Try to get the values in stderr for time
+        if 'time start' in result.err:
+            for line in result.err.split('\n'):
+                if line.startswith('time start:'):
+                    result.time.start = float(line[len('time start: '):])
+                elif line.startswith('time end:'):
+                    result.time.end = float(line[len('time end: '):])
+                    break
+
         run_result.tests[name] = result
 
     return run_result
diff --git a/framework/tests/junit_backends_tests.py b/framework/tests/junit_backends_tests.py
index 96335f3..1a4be0e 100644
--- a/framework/tests/junit_backends_tests.py
+++ b/framework/tests/junit_backends_tests.py
@@ -47,7 +47,11 @@ _XML = """\
     <testsuite name="piglit" tests="1">
       <testcase classname="piglit.foo.bar" name="a-test" status="pass" time="1.12345">
         <system-out>this/is/a/command\nThis is stdout</system-out>
-        <system-err>this is stderr</system-err>
+        <system-err>this is stderr
+
+time start: 1.0
+time end: 4.5
+        </system-err>
       </testcase>
     </testsuite>
   </testsuites>
@@ -234,11 +238,17 @@ class TestJUnitLoad(utils.StaticDirectory):
         nt.assert_is_instance(self.xml().tests[self.testname].result,
                               status.Status)
 
-    def test_time(self):
-        """backends.junit._load: Time is loaded correctly."""
+    def test_time_start(self):
+        """backends.junit._load: Time.start is loaded correctly."""
         time = self.xml().tests[self.testname].time
         nt.assert_is_instance(time, results.TimeAttribute)
-        nt.assert_equal(time.total, 1.12345)
+        nt.eq_(time.start, 1.0)
+
+    def test_time_end(self):
+        """backends.junit._load: Time.end is loaded correctly."""
+        time = self.xml().tests[self.testname].time
+        nt.assert_is_instance(time, results.TimeAttribute)
+        nt.eq_(time.end, 4.5)
 
     def test_command(self):
         """backends.junit._load: command is loaded correctly."""
@@ -253,7 +263,9 @@ class TestJUnitLoad(utils.StaticDirectory):
     def test_err(self):
         """backends.junit._load: stderr is loaded correctly."""
         test = self.xml().tests[self.testname].err
-        nt.assert_equal(test, 'this is stderr')
+        nt.eq_(
+            test, 'this is stderr\n\ntime start: 1.0\ntime end: 4.5\n        ')
+
 
     @utils.no_error
     def test_load_file(self):
-- 
2.6.1



More information about the Piglit mailing list