Skip to content

Commit e1beb81

Browse files
jan-malekmgielda
authored andcommitted
Enable collecting coverage from VCS
1 parent d87b864 commit e1beb81

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

testbench/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ BUILD_ARGS += -debug_access+all +memcbk -timescale=1ns/1ps
1111
SIM_ARGS += +dumpon
1212
EXTRA_ARGS += +vcs+vcdpluson +vpdfile+dump.vpd +warn=noLINX_KRNL
1313

14+
ifneq ($(COVERAGE_TYPE),)
15+
EXTRA_ARGS += -cm line+cond+fsm+tgl+branch
16+
endif
17+
1418
.PHONY: all vcs-build vcs-sim clean
1519
all: vcs-sim
1620

tools/nox_utils/src/nox_utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ def __init__(self, blockName: str, blockPath: str, testName: str, coverage: str
101101
defaultNameVCD = "dump.vcd"
102102
defaultNameCoverage = "coverage.dat"
103103
defaultTestNameLog = f"{testName}.log"
104+
defaultNameVDB = f"sim_build-{testName}-{coverage}/simv.vdb"
104105

105106
testNameVCD = f"{testName}.vcd"
106107
testNameXML = f"{testName}.xml"
107-
testCoverageName = f"coverage_{testName}_{coverage}.dat"
108+
testCoverageName = f"{testName}_{coverage}.dat"
108109
testNameLog = f"{testName}_{coverage}.log"
110+
testNameVDB = f"{testName}.vdb"
109111

110112
self.filenames = {
111113
"vcd_default": defaultNameVCD,
@@ -115,6 +117,8 @@ def __init__(self, blockName: str, blockPath: str, testName: str, coverage: str
115117
"log": testNameLog,
116118
"cov_default": defaultNameCoverage,
117119
"cov": testCoverageName,
120+
"vdb_default": defaultNameVDB,
121+
"vdb": testNameVDB,
118122
}
119123

120124
def get_path(name):
@@ -128,19 +132,25 @@ def get_path(name):
128132
"log": get_path(testNameLog),
129133
"cov_default": get_path(defaultNameCoverage),
130134
"cov": get_path(testCoverageName),
135+
"vdb_default": get_path(defaultNameVDB),
136+
"vdb": get_path(testNameVDB),
131137
}
132138

133139
def rename_default(self, dest: str):
134140
source = self.paths[f"{dest}_default"]
135-
if not os.path.isfile(source):
141+
if (not os.path.isfile(source)) and (not os.path.isdir(source)):
136142
print(f"Warning! Can't find file to rename: {source}")
137143
return
138144
os.rename(source, self.paths[dest])
139145

140-
def rename_defaults(self, coverage: str | None):
146+
def rename_defaults(self, coverage: str | None, simulator: str | None):
141147
if coverage:
142-
self.rename_default("cov")
143148
self.rename_default("log")
149+
if simulator is not None and "vcs" in simulator:
150+
# VDB files are specific to VCS and will not be generated by other simulators
151+
self.rename_default("vdb")
152+
else:
153+
self.rename_default("cov")
144154
self.rename_default("vcd")
145155

146156

verification/cocotb/common.mk

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,28 @@ ifeq ($(SIM), vcs)
5757
COMPILE_ARGS += -debug_access+all +memcbk
5858
SIM_ARGS += +dumpon
5959
EXTRA_ARGS += +vcs+vcdpluson +vpdfile+dump.vpd
60+
61+
ifneq ($(COVERAGE_TYPE),)
62+
EXTRA_ARGS += -cm line+cond+fsm+tgl+branch
63+
endif
6064
endif
6165

6266
COCOTB_HDL_TIMEUNIT = 1ns
6367
COCOTB_HDL_TIMEPRECISION = 10ps
6468

6569
# Build directory
70+
comma := ,
6671
ifneq ($(COVERAGE_TYPE),)
67-
SIM_BUILD := sim-build-$(COVERAGE_TYPE)
72+
# Check if more than one test is provided
73+
ifeq ($(findstring $(comma),$(MODULE)),$(comma))
74+
# To collect accurate coverage results each tests needs to have a unique SIM_BUILD directory to store
75+
# the results. If multiple tests were to use the same directory they would override each others coverage reports
76+
# causing the reported values to be incorrect.
77+
$(error Collecting coverage for multiple tests is not supported. Either unset 'COVERAGE_TYPE' to run tests without coverage reporting or use nox.)
78+
else
79+
# Construct a unique directory for each test and coverage type
80+
SIM_BUILD := sim_build-$(MODULE)-$(COVERAGE_TYPE)
81+
endif
6882
endif
6983

7084
include $(shell cocotb-config --makefiles)/Makefile.sim

verification/cocotb/noxfile.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
# Test configuration
1616
pip_requirements_path = "../../requirements.txt"
1717

18-
# Coverage types to collect
19-
coverage_types = ["all", "branch", "toggle"] if os.getenv("TEST_COVERAGE_ENABLE") else None
20-
2118
simulators = [os.getenv("SIMULATOR", "verilator")]
2219

20+
# Coverage types to collect
21+
if os.getenv("TEST_COVERAGE_ENABLE", "0") == "1":
22+
coverage_types = ["vcs"] if "vcs" in simulators else ["branch", "toggle"]
23+
else:
24+
coverage_types = None
2325

2426
def _verify(session, test_group, test_type, test_name, coverage=None, simulator=None):
2527
# session.install("-r", pip_requirements_path)
@@ -64,7 +66,7 @@ def _verify(session, test_group, test_type, test_name, coverage=None, simulator=
6466
stderr=test_log,
6567
)
6668
# Prevent coverage.dat and test log from being overwritten
67-
test.rename_defaults(coverage)
69+
test.rename_defaults(coverage, simulator)
6870

6971
# Add check from results.xml to notify nox that test failed
7072
isTBFailure = isCocotbSimFailure(resultsFile=test.paths["xml"])

0 commit comments

Comments
 (0)