From 3c80349dcce9c53b05ae60579fa598ac55fd493c Mon Sep 17 00:00:00 2001 From: chiggs Date: Fri, 10 Apr 2015 10:48:21 +0100 Subject: [PATCH] Issue #233: Cleanup exit code processing and remove dependency on xunitparser --- Makefile | 11 +++++++++-- bin/combine_results.py | 19 +++++++++++++++---- bin/report_results.py | 36 ------------------------------------ 3 files changed, 24 insertions(+), 42 deletions(-) delete mode 100755 bin/report_results.py diff --git a/Makefile b/Makefile index 8a20137de2..7f13c61d33 100644 --- a/Makefile +++ b/Makefile @@ -42,10 +42,17 @@ clean: -@find . -name "results.xml" | xargs rm -rf $(MAKE) -C examples clean -test: +do_tests: $(MAKE) -k -C examples + +# For jenkins we use the exit code to detect compile errors or catestrphic +# failures and the xml to track test results +jenkins: do_tests + ./bin/combine_results.py --squash_rc + +# By default want the exit code to indicate the test results +test: do_tests ./bin/combine_results.py - ./bin/report_results.py combined_results.xml pycode: @cp -R $(SIM_ROOT)/cocotb $(FULL_INSTALL_DIR)/ diff --git a/bin/combine_results.py b/bin/combine_results.py index 5c8d511d34..aca20421dd 100755 --- a/bin/combine_results.py +++ b/bin/combine_results.py @@ -3,11 +3,10 @@ Simple script to combine JUnit test results into a single XML file. Useful for Jenkins. - -TODO: Pretty indentation """ import os +import sys from xml.etree import cElementTree as ET def find_all(name, path): @@ -17,7 +16,7 @@ def find_all(name, path): yield os.path.join(root, name) def main(path, output): - + rc = 0 testsuite = ET.Element("testsuite", name="all", package="all", tests="0") for fname in find_all("results.xml", path): @@ -25,11 +24,23 @@ def main(path, output): for element in tree.getiterator("testcase"): testsuite.append(element) + for child in element: + if child.tag in ["failure", "error"]: + sys.stderr.write("FAILURE: %s.%s\n" % ( + element.attrib["classname"], element.attrib["name"])) + rc = 1 + result = ET.Element("testsuites", name="results") result.append(testsuite) ET.ElementTree(result).write(output, encoding="UTF-8") + return rc if __name__ == "__main__": - main(".", "combined_results.xml") + rc = main(".", "combined_results.xml") + # Suppress exit code if run with any arguments + # Slightly hacky but argparse isnt' in 2.6 + if len(sys.argv) > 1: + sys.exit(0) + sys.exit(rc) diff --git a/bin/report_results.py b/bin/report_results.py deleted file mode 100755 index ff2de2b3e5..0000000000 --- a/bin/report_results.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python -""" -Simple script to report JUnit test results - -""" - -from __future__ import print_function -import sys - -def report_results(xml_filename): - xunitparser = None - try: - import xunitparser - except ImportError as e: - sys.stderr.write("xunitparser module not availble results report not avaliable\n") - sys.stderr.write("Import error was: %s\n" % repr(e)) - - - if xunitparser is not None: - ts, tr = xunitparser.parse(open(xml_filename)) - report = {'skipped': len(tr.skipped), 'failed': len(tr.failures), 'errored': len(tr.errors), 'all': tr.testsRun} - - print('Test Report:', report) - if report['failed'] or report['errored'] or not report['all']: - return 1 - - return 0 - -if __name__ == "__main__": - if len(sys.argv) is not 2: - print("Please specify a result file") - exit(1) - - exit(report_results(sys.argv[1])) - -