Skip to content

Commit 0a7cd7a

Browse files
committed
fix: Raise a helpful error on a bogus testplan
I found this because I had added a problem to a testplan and running dvsim on the resulting block didn't work. But it failed silently! Now, you get a backtrace: ... File "/home/rjs/work/dvsim/src/dvsim/sim/flow.py", line 324, in _create_objects self.testplan = Testplan( ^^^^^^^^^ File "/home/rjs/work/dvsim/src/dvsim/testplan.py", line 350, in __init__ self._parse_testplan(filename, tags, repo_top) File "/home/rjs/work/dvsim/src/dvsim/testplan.py", line 463, in _parse_testplan self.covergroups = self._create_testplan_elements("covergroup", covergroups, set()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rjs/work/dvsim/src/dvsim/testplan.py", line 284, in _create_testplan_elements raise ValueError(err_msg) ValueError: Duplicate items with name handshake_complete_cg. (which also tells me what I did wrong in my OpenTitan patch!) Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
1 parent 5b6890a commit 0a7cd7a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/dvsim/testplan.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,31 @@ def _parse_hjson(filename):
255255
sys.exit(1)
256256

257257
@staticmethod
258-
def _create_testplan_elements(kind: str, raw_dicts_list: list, tags: set):
259-
"""Creates testplan elements from the list of raw dicts.
258+
def _create_testplan_elements(kind: str, raw_dicts_list: list, tags: set) -> list[Element]:
259+
"""Create testplan elements from the list of raw dicts.
260260
261261
kind is either 'testpoint' or 'covergroup'.
262262
raw_dicts_list is a list of dictionaries extracted from the HJson file.
263263
"""
264264
items = []
265265
item_names = set()
266+
267+
try:
268+
elem_cls = Testplan.element_cls[kind]
269+
except KeyError:
270+
err_msg = f"No known class for kind={kind}"
271+
raise RuntimeError(err_msg) from None
272+
266273
for dict_entry in raw_dicts_list:
267274
try:
268-
item = Testplan.element_cls[kind](dict_entry)
269-
except KeyError:
270-
sys.exit(1)
271-
except ValueError:
272-
sys.exit(1)
275+
item = elem_cls(dict_entry)
276+
except (KeyError, ValueError) as e:
277+
err_msg = f"Failed to create {kind} from dictionary."
278+
raise RuntimeError(err_msg) from e
273279

274280
if item.name in item_names:
275-
sys.exit(1)
281+
err_msg = f"Duplicate items with name {item.name}."
282+
raise ValueError(err_msg)
276283

277284
# Filter out the item by tags if provided.
278285
if item.has_tags(tags):

0 commit comments

Comments
 (0)