From 5f74591847db036f2fb23cf568886a6a71af3522 Mon Sep 17 00:00:00 2001 From: Chris Matthews Date: Fri, 11 May 2018 00:25:42 +0000 Subject: [PATCH] Refactor xunit test case builder to not use as much str addition String concatenation in python is slow. Refactor to not concatenate the possibly large strings of test output and instead write them directly to the output file. llvm-svn: 332064 --- llvm/utils/lit/lit/Test.py | 20 ++++++++++---------- llvm/utils/lit/lit/main.py | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/llvm/utils/lit/lit/Test.py b/llvm/utils/lit/lit/Test.py index d87906c..c68b6d9 100644 --- a/llvm/utils/lit/lit/Test.py +++ b/llvm/utils/lit/lit/Test.py @@ -360,7 +360,8 @@ class Test: """ return self.suite.config.is_early - def getJUnitXML(self): + def writeJUnitXML(self, fil): + """Write the test's report xml representation to a file handle.""" test_name = escape(self.path_in_suite[-1]) test_path = self.path_in_suite[:-1] safe_test_path = [x.replace(".","_") for x in test_path] @@ -370,14 +371,13 @@ class Test: class_name = safe_name + "." + "/".join(safe_test_path) else: class_name = safe_name + "." + safe_name - - xml = "\n\t\n") + fil.write(escape(self.result.output)) + fil.write("\n\t\n") else: - xml += "/>" - return xml + fil.write("/>") diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 6c16737..d20b881 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -614,7 +614,8 @@ def main_with_tmp(builtinParameters): xunit_output_file.write(" failures='" + str(suite['failures']) + "'>\n") for result_test in suite['tests']: - xunit_output_file.write(result_test.getJUnitXML() + "\n") + result_test.writeJUnitXML(xunit_output_file) + xunit_output_file.write("\n") xunit_output_file.write("\n") xunit_output_file.write("") xunit_output_file.close() -- 2.7.4