opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[dv] Use of asserton/off without specifying the design hierarchy

Open sriyerg opened this issue 6 years ago • 5 comments

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 $assertoff without providing a design hierarchy
  • Leave the assert keyword for real design assertions. To check if a condition in DV code was satisfied, stick to plain old if (!something) $error(...) or use `DV_CHECK_EQ(..)

@weicaiyang @cindychip @rasmus-madsen @rswarbrick @udinator @senelson7 @tunghoang290780

sriyerg avatar Sep 29 '20 00:09 sriyerg

I agree with your suggestion. I think it would be good to add it to the coding style guide.

cindychip avatar Sep 29 '20 00:09 cindychip

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.

udinator avatar Sep 29 '20 00:09 udinator

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 avatar Sep 29 '20 18:09 weicaiyang

@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).

sriyerg avatar Sep 29 '20 18:09 sriyerg

@weicaiyang, I fixed it in this commit using the uvm_config_db::wait_modified approach: 190a637

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).

oh, uvm violates our style guide. Then at least we need to add tb.dut to avoid it. Thanks for the pointer.

weicaiyang avatar Sep 29 '20 19:09 weicaiyang