-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes due to mistake and Aldec integration (#53)
- Loading branch information
Showing
8 changed files
with
324 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,5 @@ waves.shm/ | |
/.dvt | ||
|
||
/cocotb_test/libs | ||
.cocotb-results | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
import shutil | ||
from xml.etree import cElementTree as ET | ||
|
||
|
||
class ResultsCocotb(object): | ||
def __init__(self, results_xml_output): | ||
self.results_xml_output = results_xml_output | ||
self.names = [] | ||
self.results_xml_dir = os.path.abspath(".cocotb-results") | ||
|
||
def get_results_xml_file(self, nodeid): | ||
return os.path.join(self.results_xml_dir, nodeid.replace(os.sep, "_").replace("/", "_").replace(":", "-") + ".xml") | ||
|
||
def pytest_runtest_logreport(self, report): | ||
if report.when == "call" and report.outcome != "skipped": | ||
self.names.append(report.nodeid) | ||
|
||
def pytest_sessionstart(self, session): | ||
|
||
if os.path.exists(self.results_xml_dir): | ||
shutil.rmtree(self.results_xml_dir) | ||
|
||
os.makedirs(self.results_xml_dir) | ||
|
||
def pytest_runtest_setup(self, item): | ||
|
||
os.environ["COCOTB_RESULTS_FILE"] = self.get_results_xml_file(item._nodeid) | ||
os.environ["RESULT_TESTPACKAGE"] = item._nodeid | ||
|
||
def pytest_sessionfinish(self, session): | ||
|
||
result = ET.Element("testsuites", name="results") | ||
|
||
for nodeid in self.names: | ||
fname = self.get_results_xml_file(nodeid) | ||
|
||
if os.path.isfile(fname): | ||
tree = ET.parse(fname) | ||
for testsuite in tree.getiterator("testsuite"): | ||
use_element = None | ||
|
||
for testcase in testsuite.getiterator("testcase"): | ||
testcase.set("classname", "cocotb." + testcase.get("classname")) # add cocotb. for easeir selection | ||
|
||
for existing in result: | ||
if existing.get("name") == testsuite.get("name") and (existing.get("package") == testsuite.get("package")): | ||
use_element = existing | ||
break | ||
if use_element is None: | ||
result.append(testsuite) | ||
else: | ||
use_element.extend(list(testsuite)) | ||
|
||
ET.ElementTree(result).write(self.results_xml_output, encoding="UTF-8") | ||
|
||
def pytest_runtest_teardown(self, item, nextitem): | ||
results_xml_file = self.get_results_xml_file(item._nodeid) | ||
results_xml_file_defulat = os.path.join("sim_build", "results.xml") | ||
|
||
if os.path.isfile(results_xml_file_defulat): | ||
os.rename(results_xml_file_defulat, results_xml_file) | ||
|
||
|
||
def pytest_unconfigure(config): | ||
cocotb = getattr(config, "_cocotb", None) | ||
if cocotb: | ||
config.pluginmanager.unregister(cocotb) | ||
|
||
|
||
def pytest_configure(config): | ||
if config.option.cocotb_xml: | ||
config._cocotb = ResultsCocotb(config.option.cocotb_xml) | ||
config.pluginmanager.register(config._cocotb) | ||
|
||
|
||
def pytest_addoption(parser): | ||
group = parser.getgroup("terminal reporting") | ||
group.addoption( | ||
"--cocotbxml", | ||
"--cocotb-xml", | ||
action="store", | ||
dest="cocotb_xml", | ||
default=None, | ||
metavar="path", | ||
help="create junit-xml style report file for cocotb reports at given path.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.