From 535727703945f44b08ab251bdc243a54c63cf51f Mon Sep 17 00:00:00 2001 From: Gabriel Busnot Date: Tue, 3 Jan 2023 15:33:44 +0000 Subject: [PATCH] ext-testlib: Improve error reporting when test definition fails The error reason is now reported as an element in the XML testing result summary. Change-Id: I18b84422bb9580709cf1c5f2a14a5cbb0caf1876 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/66892 Reviewed-by: Bobby Bruce Maintainer: Bobby Bruce Tested-by: kokoro --- ext/testlib/result.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/ext/testlib/result.py b/ext/testlib/result.py index 5c60342c11..786febde2a 100644 --- a/ext/testlib/result.py +++ b/ext/testlib/result.py @@ -191,17 +191,23 @@ class XMLElement(object): def begin(self, file_): file_.write('<') file_.write(self.name) - for attr in self.attributes: - file_.write(' ') - attr.write(file_) + if hasattr(self, 'attributes'): + for attr in self.attributes: + file_.write(' ') + attr.write(file_) file_.write('>') self.body(file_) def body(self, file_): - for elem in self.elements: - file_.write('\n') - elem.write(file_) + if hasattr(self, 'elements'): + for elem in self.elements: + file_.write('\n') + elem.write(file_) + if hasattr(self, 'content'): + file_.write('\n') + file_.write( + xml.sax.saxutils.escape(self.content)) file_.write('\n') def end(self, file_): @@ -286,17 +292,22 @@ class JUnitTestCase(XMLElement): ] if str(test_result.result) == 'Failed': - self.elements.append(JUnitFailure('Test failed', 'ERROR')) + self.elements.append(JUnitFailure( + 'Test failed', + str(test_result.result.reason)) + ) class JUnitFailure(XMLElement): name = 'failure' - def __init__(self, message, fail_type): + def __init__(self, message, cause): self.attributes = [ XMLAttribute('message', message), - XMLAttribute('type', fail_type), ] - self.elements = [] + cause_element = XMLElement() + cause_element.name = 'cause' + cause_element.content = cause + self.elements = [cause_element] class LargeFileElement(XMLElement):