[llvm-branch-commits] [llvm-branch] r223250 - Merging r223163:
Duncan P. N. Exon Smith
dexonsmith at apple.com
Wed Dec 3 10:17:15 PST 2014
Author: dexonsmith
Date: Wed Dec 3 12:17:15 2014
New Revision: 223250
URL: http://llvm.org/viewvc/llvm-project?rev=223250&view=rev
Log:
Merging r223163:
------------------------------------------------------------------------
r223163 | cmatthews | 2014-12-02 14:19:21 -0800 (Tue, 02 Dec 2014) | 5 lines
Give lit a --xunit-xml-output option for saving results in xunit format
--xunit-xml-output saves test results to disk in JUnit's xml format. This will allow Jenkins to report the details of a lit run.
Based on a patch by David Chisnall.
------------------------------------------------------------------------
Modified:
llvm/branches/release_35/ (props changed)
llvm/branches/release_35/utils/lit/lit/Test.py
llvm/branches/release_35/utils/lit/lit/main.py
Propchange: llvm/branches/release_35/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Dec 3 12:17:15 2014
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216920,217257,218745,221408,221453
+/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216920,217257,218745,221408,221453,223163
Modified: llvm/branches/release_35/utils/lit/lit/Test.py
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/utils/lit/lit/Test.py?rev=223250&r1=223249&r2=223250&view=diff
==============================================================================
--- llvm/branches/release_35/utils/lit/lit/Test.py (original)
+++ llvm/branches/release_35/utils/lit/lit/Test.py Wed Dec 3 12:17:15 2014
@@ -1,4 +1,5 @@
import os
+from xml.sax.saxutils import escape
# Test result codes.
@@ -194,3 +195,17 @@ class Test:
return True
return False
+
+
+ def getJUnitXML(self):
+ test_name = self.path_in_suite[-1]
+ test_path = self.path_in_suite[:-1]
+
+ xml = "<testcase classname='" + self.suite.name + "." + "/".join(test_path) + "'" + " name='" + test_name + "'"
+ xml += " time='%.2f'" % (self.result.elapsed,)
+ if self.result.code.isFailure:
+ xml += ">\n\t<failure >\n" + escape(self.result.output)
+ xml += "\n\t</failure>\n</testcase>"
+ else:
+ xml += "/>"
+ return xml
\ No newline at end of file
Modified: llvm/branches/release_35/utils/lit/lit/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/utils/lit/lit/main.py?rev=223250&r1=223249&r2=223250&view=diff
==============================================================================
--- llvm/branches/release_35/utils/lit/lit/main.py (original)
+++ llvm/branches/release_35/utils/lit/lit/main.py Wed Dec 3 12:17:15 2014
@@ -194,6 +194,9 @@ def main(builtinParameters = {}):
group.add_option("", "--no-execute", dest="noExecute",
help="Don't execute any tests (assume PASS)",
action="store_true", default=False)
+ group.add_option("", "--xunit-xml-output", dest="xunit_output_file",
+ help=("Write XUnit-compatible XML test reports to the"
+ " specified file"), default=None)
parser.add_option_group(group)
group = OptionGroup(parser, "Test Selection")
@@ -285,10 +288,10 @@ def main(builtinParameters = {}):
if opts.showSuites or opts.showTests:
# Aggregate the tests by suite.
suitesAndTests = {}
- for t in run.tests:
- if t.suite not in suitesAndTests:
- suitesAndTests[t.suite] = []
- suitesAndTests[t.suite].append(t)
+ for result_test in run.tests:
+ if result_test.suite not in suitesAndTests:
+ suitesAndTests[result_test.suite] = []
+ suitesAndTests[result_test.suite].append(result_test)
suitesAndTests = list(suitesAndTests.items())
suitesAndTests.sort(key = lambda item: item[0].name)
@@ -321,8 +324,8 @@ def main(builtinParameters = {}):
except:
parser.error("invalid regular expression for --filter: %r" % (
opts.filter))
- run.tests = [t for t in run.tests
- if rex.search(t.getFullName())]
+ run.tests = [result_test for result_test in run.tests
+ if rex.search(result_test.getFullName())]
# Then select the order.
if opts.shuffle:
@@ -330,7 +333,7 @@ def main(builtinParameters = {}):
elif opts.incremental:
sort_by_incremental_cache(run)
else:
- run.tests.sort(key = lambda t: t.getFullName())
+ run.tests.sort(key = lambda result_test: result_test.getFullName())
# Finally limit the number of tests, if desired.
if opts.maxTests is not None:
@@ -415,6 +418,36 @@ def main(builtinParameters = {}):
if N:
print(' %s: %d' % (name,N))
+ if opts.xunit_output_file:
+ # Collect the tests, indexed by test suite
+ by_suite = {}
+ for result_test in run.tests:
+ suite = result_test.suite.config.name
+ if suite not in by_suite:
+ by_suite[suite] = {
+ 'passes' : 0,
+ 'failures' : 0,
+ 'tests' : [] }
+ by_suite[suite]['tests'].append(result_test)
+ if result_test.result.code.isFailure:
+ by_suite[suite]['failures'] += 1
+ else:
+ by_suite[suite]['passes'] += 1
+ xunit_output_file = open(opts.xunit_output_file, "w")
+ xunit_output_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
+ xunit_output_file.write("<testsuites>\n")
+ for suite_name, suite in by_suite.items():
+ xunit_output_file.write("<testsuite name='" + suite_name + "'")
+ xunit_output_file.write(" tests='" + str(suite['passes'] +
+ suite['failures']) + "'")
+ xunit_output_file.write(" failures='" + str(suite['failures']) +
+ "'>\n")
+ for result_test in suite['tests']:
+ xunit_output_file.write(result_test.getJUnitXML() + "\n")
+ xunit_output_file.write("</testsuite>\n")
+ xunit_output_file.write("</testsuites>")
+ xunit_output_file.close()
+
# If we encountered any additional errors, exit abnormally.
if litConfig.numErrors:
sys.stderr.write('\n%d error(s), exiting.\n' % litConfig.numErrors)
More information about the llvm-branch-commits
mailing list