Interacting with assertions in the UUT

93 views
Skip to first unread message

de...@sifive.com

unread,
Jul 26, 2018, 9:00:09 PM7/26/18
to SVUnit User Group
Hello,

I was wondering if there is a way to make an SVUnit test fail based on whether or not an assertion in the UUT is triggered.

Deborah

Christophe Rouaud

unread,
Sep 26, 2018, 12:13:15 PM9/26/18
to SVUnit User Group
I actually found a simple solution that consists in trigging SVUnit macros within my assertion fail statement. 
Hereunder is an example where I check that after deactivating a reset input, I expected reset output to be deactivated in a maximum of 20 clock cycles


    assert property (@(posedge qnet_aclk) (qnet0_rstn_in) |-> ##[1:20] qnet0_aresetn) else
    begin
        $display("# ERROR: Assertion - DUT does not get out of reset fast enough ");
        `FAIL_UNLESS(qnet0_aresetn == 1'b1);
    end;

I did reuse SVUnit messaging convention ("# ERROR:") since it allows me to ease SVUnit results parsing within my simulator log.

What I observe in log is : 
# ERROR: ASsertion - DUT does not get out of reset fast enough 
# ERROR: [3637142][qp_qnet_wrapper_c2c_ut]: fail_unless: qnet0_aresetn == 1'b1 (at /home/crouaud/QuickPlay/HDK/QuickPlayLibrary_RC/ip/QuickNet/ip/sim/test/qp_qnet_wrapper/qp_qnet_wrapper_c2c_unit_test.sv line:569)
# INFO:  [3637000][qp_qnet_wrapper_c2c_ut]: READ_VERSION::FAILED
# INFO:  [3637142][qp_qnet_wrapper_c2c_ut]: FAILED (0 of 1 tests passing)

Note that when such event is triggered, currently SVUnit running test (READ_VERSION) is marked as FAILED

Christophe


Tudor Timi

unread,
Sep 28, 2018, 3:52:53 AM9/28/18
to SVUnit User Group
What Christophe suggested requires editing the production code and you might not be keen on making the compile of production code dependent on compiling SVUnit. It's possible to interrogate the counter of each assertion in the simulation and check that the the desired assertion is pass/fail. Unfortunately, this isn't possible in the language itself. You can gen to these counters via the VPI, provided your tool supports the required object model elements.

I have the code on a different network and can't copy it here, but here's some pseudo-code for the required C code:

// Handle to the assertion being monitored
vpiHandle assert_handle;

// Global counters of how many time the monitored assertion has passed/failed
static int num_success;
static int num_failure;


// register this as a system function that takes the assertion as an argument
void monitor_assert() {
  // get handle to assertion from argument

  num_success = vpi_get(vpiAssertSuccessCovered, assert_handle);
  num_failure = vpi_get(vpiAssertFailureCovered, assert_handle);
}


// register as a system function that returns 'num_success'
void get_assert_pass {
  vpiHandle systfref = vpi_handle(vpiSysTfCall, NULL);
 
  s_vpi_value temp_val;
  temp_val.format = vpiIntVal;
  temp_val.value.integer = vpi_get(vpiAssertSuccessCovered, assert_handle) - num_success;
  vpi_put_value(systfref, &temp_val, NULL, vpiNoDelay);
}

// same for get_assert_fail
// ...


In SV:

`SVTEST(...)
  $monitor_assert(<path_to_assert>);
  // do stuff that makes assertion fail

  // give assert time to trigger, as they are triggered in the observed region
  #1;

  // Check that there was only one fail in between the time you started to monitor the assertion and now
  `FAIL_UNLESS($get_assert_fail() == 1)
Reply all
Reply to author
Forward
0 new messages