Skip to content

Commit

Permalink
Issue cocotb#233: Cleanup exit code processing and remove dependency …
Browse files Browse the repository at this point in the history
…on xunitparser
  • Loading branch information
chiggs committed Apr 10, 2015
1 parent c1d0d4e commit 3c80349
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)/
Expand Down
19 changes: 15 additions & 4 deletions bin/combine_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -17,19 +16,31 @@ 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):
tree = ET.parse(fname)
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)

36 changes: 0 additions & 36 deletions bin/report_results.py

This file was deleted.

0 comments on commit 3c80349

Please sign in to comment.