Skip to content

Commit

Permalink
post_run: add report data to 'Results' object/class
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Nov 7, 2019
1 parent 6958f27 commit 8c249d8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
11 changes: 11 additions & 0 deletions vunit/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import socket
import re
from os.path import dirname
from vunit.color_printer import COLOR_PRINTER
from vunit.ostools import read_file

Expand Down Expand Up @@ -322,3 +323,13 @@ def to_xml(self, xunit_xml_format):
skipped = ElementTree.SubElement(test, "skipped")
skipped.attrib["message"] = "Skipped"
return test

def to_dict(self):
"""
Convert a subset of the test result to a dictionary
"""
return {
"status": self._status.name,
"time": self.time,
"path": dirname(self._output_file_name),
}
2 changes: 2 additions & 0 deletions vunit/ui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

LOGGER = getLogger(__name__)

TEST_OUTPUT_PATH = "test_output"


def select_vhdl_standard(vhdl_standard=None):
"""
Expand Down
49 changes: 47 additions & 2 deletions vunit/ui/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
UI class Results
"""

from os.path import join, basename, normpath
from .common import TEST_OUTPUT_PATH


class Results(object):
"""
Gives access to results after running tests.
"""

def __init__(self, simulator_if):
def __init__(self, output_path, simulator_if, report):
self._output_path = output_path
self._simulator_if = simulator_if
self._report = report

def merge_coverage(self, file_name, args=None):
"""
Expand All @@ -24,5 +29,45 @@ def merge_coverage(self, file_name, args=None):
:param file_name: The resulting coverage file name.
:param args: The tool arguments for the merge command. Should be a list of strings.
"""

self._simulator_if.merge_coverage(file_name=file_name, args=args)

def get_report(self):
"""
Get a report (dictionary) of tests: status, time and output path
"""

def get_relative_test_path(test_path):
"""
If the test_path is relative to the default TEST_OUTPUT_PATH, return the subdir only
"""
base = basename(test_path)
return (
base
if normpath(join(self._output_path, TEST_OUTPUT_PATH, base))
== normpath(test_path)
else test_path
)

class Report(object):
"""
Gives access to test results and paths after running tests.
"""

def __init__(self, output_path):
self.output_path = output_path
self.tests = {}

def get_full_path(self, test_path, file_path=""):
"""
Return the full path to a test subdir or to a file within it
"""
return join(self.output_path, TEST_OUTPUT_PATH, test_path, file_path)

report = Report(self._output_path)
for (
test
) in self._report._test_results_in_order(): # pylint: disable=protected-access
obj = test.to_dict()
obj["path"] = get_relative_test_path(obj["path"])
report.tests.update({test.name: obj})
return report
6 changes: 3 additions & 3 deletions vunit/ui/vunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ..builtins import Builtins
from ..vhdl_standard import VHDL

from .common import LOGGER, select_vhdl_standard, check_not_empty
from .common import LOGGER, TEST_OUTPUT_PATH, select_vhdl_standard, check_not_empty
from .source import SourceFile, SourceFileList
from .test import Test # pylint: disable=unused-import
from .testbench import TestBench # pylint: disable=unused-import
Expand Down Expand Up @@ -772,7 +772,7 @@ def _main_run(self, post_run):
report.print_str()

if post_run is not None:
post_run(results=Results(simulator_if))
post_run(results=Results(self._output_path, simulator_if, report))

del simulator_if

Expand Down Expand Up @@ -932,7 +932,7 @@ def _run_test(self, test_cases, report):

runner = TestRunner(
report,
join(self._output_path, "test_output"),
join(self._output_path, TEST_OUTPUT_PATH),
verbosity=verbosity,
num_threads=self._args.num_threads,
fail_fast=self._args.fail_fast,
Expand Down

0 comments on commit 8c249d8

Please sign in to comment.