python: Flush the simulation stdout/stderr buffers
[gem5.git] / ext / testlib / result.py
index 8e3f38d25438f552caaa55454e730b3ca0146559..2d2c506a1384c76de21030e9608e7541635b276e 100644 (file)
@@ -30,10 +30,9 @@ import os
 import pickle
 import xml.sax.saxutils
 
-from config import config
-import helper
-import state
-import log
+from testlib.configuration import config
+import testlib.helper as helper
+import testlib.state as state
 
 def _create_uid_index(iterable):
     index = {}
@@ -58,11 +57,11 @@ class _CommonMetadataMixin:
         self._metadata.result = result
 
     @property
-    def unsucessful(self):
+    def unsuccessful(self):
         return self._metadata.result.value != state.Result.Passed
 
 
-class InternalTestResult(object, _CommonMetadataMixin):
+class InternalTestResult(_CommonMetadataMixin):
     def __init__(self, obj, suite, directory):
         self._metadata = obj.metadata
         self.suite = suite
@@ -77,7 +76,7 @@ class InternalTestResult(object, _CommonMetadataMixin):
         )
 
 
-class InternalSuiteResult(object, _CommonMetadataMixin):
+class InternalSuiteResult(_CommonMetadataMixin):
     def __init__(self, obj, directory):
         self._metadata = obj.metadata
         self.directory = directory
@@ -104,7 +103,7 @@ class InternalSuiteResult(object, _CommonMetadataMixin):
         return results
 
 
-class InternalLibraryResults(object, _CommonMetadataMixin):
+class InternalLibraryResults(_CommonMetadataMixin):
     def __init__(self, obj, directory):
         self.directory = directory
         self._metadata = obj.metadata
@@ -159,12 +158,12 @@ class InternalSavedResults:
                if exc.errno != errno.EEXIST:
                    raise
 
-        with open(path, 'w') as f:
+        with open(path, 'wb') as f:
             pickle.dump(results, f, protocol)
 
     @staticmethod
     def load(path):
-        with open(path, 'r') as f:
+        with open(path, 'rb') as f:
             return pickle.load(f)
 
 
@@ -269,6 +268,20 @@ class JUnitTestCase(XMLElement):
             LargeFileElement('system-out', test_result.stdout),
         ]
 
+        if str(test_result.result) == 'Failed':
+            self.elements.append(JUnitFailure('Test failed', 'ERROR'))
+
+
+class JUnitFailure(XMLElement):
+    name = 'failure'
+    def __init__(self, message, fail_type):
+        self.attributes = [
+            XMLAttribute('message', message),
+            XMLAttribute('type', fail_type),
+        ]
+        self.elements = []
+
+
 class LargeFileElement(XMLElement):
     def __init__(self, name, filename):
         self.name = name