[dv] Use of asserton/off without specifying the design hierarchy
Example instance: https://github.com/lowRISC/opentitan/blob/e1184aa6096aace591802b1b0cb2d9b8c0d36f0c/hw/dv/sv/dv_lib/dv_base_vseq.sv#L196
Use of $assertoff without specifying the design hierarchy may lead to debug overhead. The intention here clearly is to disable design assertions because of the unconstrained random stimulus. The side effect here is any code that uses assert to check if a condition was satisfied will get disabled as well - which means the check will not trigger and the sequence will silently fall through.
Example where it is implemented in our DV code:
https://github.com/lowRISC/opentitan/blob/e1184aa6096aace591802b1b0cb2d9b8c0d36f0c/hw/ip/otbn/dv/model/otbn_core_model.sv#L65
IMO we should:
- Never use
$assertoffwithout providing a design hierarchy - Leave the
assertkeyword for real design assertions. To check if a condition in DV code was satisfied, stick to plain oldif (!something) $error(...)or use`DV_CHECK_EQ(..)
@weicaiyang @cindychip @rasmus-madsen @rswarbrick @udinator @senelson7 @tunghoang290780
I agree with your suggestion. I think it would be good to add it to the coding style guide.
I agree with the suggestion also, imo assertions should be left for the design-side. If there is a consensus, I can get a PR ready in the DV style guide regarding enhanced assertion usage.
In this example, we do want to disable all assertions in design. The hierarchy we can use may be tb or tb.dut. Looks like the 2nd rule is more important to prevent this issue.
https://github.com/lowRISC/opentitan/blob/e1184aa6096aace591802b1b0cb2d9b8c0d36f0c/hw/dv/sv/dv_lib/dv_base_vseq.sv#L196
@weicaiyang, I fixed it in this commit using the uvm_config_db::wait_modified approach:
https://github.com/lowRISC/opentitan/pull/3425/commits/190a6375f6c17cefebf76ee43e12322f4ff40dfa
This is in the same PR #3425. PTAL again if possible.
The CI was failing without this change - the $assertoff was causing cast and clone operations in the UVM code to be completely skipped, resulting in NOA error. See line 1735 of UVM reg map:
http://www.studio-muzzi.com/project/docs/UVMdocs_smu/uvm-1.1d/uvm__reg__map_8svh_source.html
It was painful to debug this (which is why I filed this issue).
@weicaiyang, I fixed it in this commit using the
uvm_config_db::wait_modifiedapproach: 190a637This is in the same PR #3425. PTAL again if possible.
The CI was failing without this change - the
$assertoffwas causing cast and clone operations in the UVM code to be completely skipped, resulting in NOA error. See line 1735 of UVM reg map: http://www.studio-muzzi.com/project/docs/UVMdocs_smu/uvm-1.1d/uvm__reg__map_8svh_source.htmlIt was painful to debug this (which is why I filed this issue).
oh, uvm violates our style guide. Then at least we need to add tb.dut to avoid it. Thanks for the pointer.