Skip to content

Commit 48040f6

Browse files
wkkunakgugala
authored andcommitted
ver: Add test iteration variable
Signed-off-by: Wiktoria Kuna <[email protected]>
1 parent d79d2e2 commit 48040f6

File tree

2 files changed

+66
-56
lines changed

2 files changed

+66
-56
lines changed

tools/nox_utils/src/nox_utils.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,29 @@ class VerificationTest:
8787
Useful to manage files produced by Cocotb+Verilator in I3C_ROOT_DIR/verification/block
8888
"""
8989

90-
def __init__(self, blockName: str, blockPath: str, testName: str, coverage: str | None):
90+
def __init__(self, blockName: str, blockPath: str, testName: str, coverage: str | None, pfx=""):
9191
self.blockName = blockName
9292
self.blockPath = blockPath
9393
self.testName = testName
9494
self.coverage = coverage
95+
self.pfx = pfx
9596
self.testPath = os.path.join(blockPath, blockName)
97+
self.sim_build = "sim_build" if coverage is None else f"sim_build-{self.testName}-{coverage}"
9698

9799
# Convert NoneType to empty string
98100
coverage = "" if coverage is None else str(coverage)
99101

100102
# Defaults from verilator
101103
defaultNameVCD = "dump.vcd"
102104
defaultNameCoverage = "coverage.dat"
103-
defaultTestNameLog = f"{testName}.log"
104-
defaultNameVDB = f"sim_build-{testName}-{coverage}/simv.vdb"
105-
106-
testNameVCD = f"{testName}.vcd"
107-
testNameXML = f"{testName}.xml"
108-
testCoverageName = f"{testName}_{coverage}.dat"
109-
testNameLog = f"{testName}_{coverage}.log"
110-
testNameVDB = f"{testName}.vdb"
105+
defaultTestNameLog = f"{self.testName}{pfx}.log"
106+
defaultNameVDB = f"{self.sim_build}/simv.vdb"
107+
108+
testNameVCD = f"{self.testName}{pfx}.vcd"
109+
testNameXML = f"{self.testName}{pfx}.xml"
110+
testCoverageName = f"{self.testName}{pfx}_{coverage}.dat"
111+
testNameLog = f"{self.testName}{pfx}_{coverage}.log"
112+
testNameVDB = f"{self.testName}{pfx}.vdb"
111113

112114
self.filenames = {
113115
"vcd_default": defaultNameVCD,

verification/cocotb/noxfile.py

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
32
import os
43
import random
54
import time
5+
import shutil
66

77
import nox
88
from nox_utils import VerificationTest, isCocotbSimFailure, nox_config
@@ -23,55 +23,63 @@
2323
else:
2424
coverage_types = None
2525

26+
2627
def _verify(session, test_group, test_type, test_name, coverage=None, simulator=None):
2728
# session.install("-r", pip_requirements_path)
28-
test = VerificationTest(test_group, test_type, test_name, coverage)
29-
30-
# Translate session options to plusargs
31-
plusargs = list(session.posargs)
32-
33-
# Randomize seed for initialization of undefined signals in the simulation
34-
random.seed(time.time_ns())
35-
seed = random.randint(1, 10000)
36-
37-
with open(test.paths["log_default"], "w") as test_log:
38-
39-
args = [
40-
"make",
41-
"-C",
42-
test.testPath,
43-
"all",
44-
"MODULE=" + test_name,
45-
"COCOTB_RESULTS_FILE=" + test.filenames["xml"],
46-
]
47-
if simulator == "verilator":
48-
plusargs.extend(
49-
[
50-
"+verilator+rand+reset+2",
51-
f"+verilator+seed+{seed}",
52-
]
29+
30+
test_iterations = int(os.getenv("TEST_ITERATIONS", 1))
31+
for i in range(test_iterations):
32+
pfx = "" if test_iterations == 1 else f"_{i}"
33+
test = VerificationTest(test_group, test_type, test_name, coverage, pfx)
34+
# Translate session options to plusargs
35+
plusargs = list(session.posargs)
36+
37+
# Randomize seed for initialization of undefined signals in the simulation
38+
random.seed(time.time_ns())
39+
seed = random.randint(1, 10000)
40+
41+
with open(test.paths["log_default"], "w") as test_log:
42+
# Remove simulation build artifacts
43+
# When collecting coverage and renaming `vdb` database
44+
# the following simulations will fail due to non-existent database
45+
if simulator == "vcs" and i > 0:
46+
shutil.rmtree(os.path.join(test.testPath, test.sim_build))
47+
48+
args = [
49+
"make",
50+
"-C",
51+
test.testPath,
52+
"all",
53+
"MODULE=" + test_name,
54+
"COCOTB_RESULTS_FILE=" + test.filenames["xml"],
55+
]
56+
if simulator == "verilator":
57+
plusargs.extend(
58+
[
59+
"+verilator+rand+reset+2",
60+
f"+verilator+seed+{seed}",
61+
]
62+
)
63+
if coverage:
64+
args.append("COVERAGE_TYPE=" + coverage)
65+
66+
if simulator:
67+
args.append("SIM=" + simulator)
68+
69+
args.append("PLUSARGS=" + " ".join(plusargs))
70+
71+
session.run(
72+
*args,
73+
external=True,
74+
stdout=test_log,
75+
stderr=test_log,
5376
)
54-
if coverage:
55-
args.append("COVERAGE_TYPE=" + coverage)
56-
57-
if simulator:
58-
args.append("SIM=" + simulator)
59-
60-
args.append("PLUSARGS=" + " ".join(plusargs))
61-
62-
session.run(
63-
*args,
64-
external=True,
65-
stdout=test_log,
66-
stderr=test_log,
67-
)
68-
# Prevent coverage.dat and test log from being overwritten
69-
test.rename_defaults(coverage, simulator)
70-
71-
# Add check from results.xml to notify nox that test failed
72-
isTBFailure = isCocotbSimFailure(resultsFile=test.paths["xml"])
73-
if isTBFailure:
74-
raise Exception("SimFailure: cocotb failed. See test logs for more information.")
77+
# Prevent coverage.dat and test log from being overwritten
78+
test.rename_defaults(coverage, simulator)
79+
80+
# Add check from results.xml to notify nox that test failed
81+
if isCocotbSimFailure(resultsFile=test.paths["xml"]):
82+
raise Exception("SimFailure: cocotb failed. See test logs for more information.")
7583

7684

7785
def verify_block(session, test_group, test_name, coverage=None, simulator=None):

0 commit comments

Comments
 (0)