ext: Add failure node to JUnit xml file
authorGiacomo Travaglini <giacomo.travaglini@arm.com>
Wed, 5 Feb 2020 17:18:11 +0000 (17:18 +0000)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Thu, 13 Feb 2020 16:40:49 +0000 (16:40 +0000)
"failure" is a child of the testcase node:

https://llg.cubic.org/docs/junit/

It allows xml parsers to understand which testcase failed the run.
Otherwise CI frameworks like jenkins wouldn't be able to classify every
single testcase. Prior to this patch testlib was using
testsuites.failures and testsuite.failures only. These are simply
reporting the number of failures.

Change-Id: I0d498eca029c3232f2a588b153b6b6829b789394
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25083
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ciro Santilli <ciro.santilli@arm.com>
ext/testlib/result.py

index 22c0248ca84fcfd836b83335e48924649f6914ab..786c21b609168eb9137a1e5adc1a64e32ef8f8cc 100644 (file)
@@ -269,6 +269,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