[Piglit] [PATCH 1/2] framework: add exception back to TestResult class

Dylan Baker baker.dylan.c at gmail.com
Wed Sep 30 16:51:57 PDT 2015

Like command, this somehow didn't get moved to the new TestResult class.
Generally this isn't a problem since this is a very uncommon path, but
in some cases this does get hit, and it would cause an exception in the
runner threads. Python has very bad exception handling in threads,
namely it doesn't have any; this results in an exception being raised
and remaining uncaught, terminating the thread, which in turn results in
the test result being incomplete, even though it should have been crash.

This patch fixes that situation.

cc: Mark Janes <mark.a.janes at intel.com>
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>

Mark, this should fix the problem where clipflat returns an incomplete
in jenkins. Basically what was happening is that it was returning
invalid JSON, and then trying to write that into the TestResult, which
it couldn't raising another exception.

 framework/results.py             |  7 +++++--
 framework/tests/results_tests.py | 10 ++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/framework/results.py b/framework/results.py
index 8d3fe17..26f4380 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -106,7 +106,8 @@ class StringDescriptor(object):  # pylint: disable=too-few-public-methods
 class TestResult(object):
     """An object represting the result of a single test."""
     __slots__ = ['returncode', '_err', '_out', 'time', 'command', 'traceback',
-                 'environment', 'subtests', 'dmesg', '__result', 'images']
+                 'environment', 'subtests', 'dmesg', '__result', 'images',
+                 'exception']
     err = StringDescriptor('_err')
     out = StringDescriptor('_out')
@@ -119,6 +120,7 @@ class TestResult(object):
         self.dmesg = str()
         self.images = None
         self.traceback = None
+        self.exception = None
         if result:
             self.result = result
@@ -155,6 +157,7 @@ class TestResult(object):
             'returncode': self.returncode,
             'subtests': self.subtests,
             'time': self.time,
+            'exception': self.exception,
         return obj
@@ -174,7 +177,7 @@ class TestResult(object):
         inst = cls()
         # TODO: There's probably a more clever way to do this
-        for each in ['returncode', 'time', 'command',
+        for each in ['returncode', 'time', 'command', 'exception',
                      'environment', 'result', 'dmesg']:
             if each in dict_:
                 setattr(inst, each, dict_[each])
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
index 728d479..1b11df0 100644
--- a/framework/tests/results_tests.py
+++ b/framework/tests/results_tests.py
@@ -194,6 +194,7 @@ class TestTestResult_to_json(object):
                 'b': 'fail',
             'result': 'crash',
+            'exception': 'an exception',
         test = results.TestResult.from_dict(cls.dict)
@@ -212,6 +213,10 @@ class TestTestResult_to_json(object):
         """results.TestResult.to_json: sets the out correctly"""
         nt.eq_(self.dict['out'], self.json['out'])
+    def test_out(self):
+        """results.TestResult.to_json: sets the exception correctly"""
+        nt.eq_(self.dict['exception'], self.json['exception'])
     def test_time(self):
         """results.TestResult.to_json: sets the time correctly"""
         nt.eq_(self.dict['time'], self.json['time'])
@@ -244,6 +249,7 @@ class TestTestResult_from_dict(object):
                 'b': 'fail',
             'result': 'crash',
+            'exception': 'an exception',
         cls.test = results.TestResult.from_dict(cls.dict)
@@ -268,6 +274,10 @@ class TestTestResult_from_dict(object):
         """results.TestResult.from_dict: sets environment properly"""
         nt.eq_(self.test.environment, self.dict['environment'])
+    def test_exception(self):
+        """results.TestResult.from_dict: sets exception properly"""
+        nt.eq_(self.test.exception, self.dict['exception'])
     def test_subtests(self):
         """results.TestResult.from_dict: sets subtests properly"""
         nt.eq_(self.test.subtests, self.dict['subtests'])

More information about the Piglit mailing list