如何使用测试中的 assertoff 来禁用 side uvm 对象中的断言

how to use assertoff from test to disable assertion in side uvm object

我正在寻找方法来禁用 side uvm 组件中的断言以进行某些测试。 下面的简单代码代表我的环境,并附有要求注释。 我以为我可以使用 $assertoff。 如果需要额外的工具来实现这一点,我可以修改 uvm 组件。

    import uvm_pkg::*;
    `include "uvm_macros.svh"

    class tb_env extends uvm_component;

       `uvm_component_utils(tb_env)

       int exp_val = 0;
       int act_val = 0;

       function new(string name = "tb_env", uvm_component parent = null);
          super.new(name, parent);
       endfunction

       virtual task run_phase (uvm_phase phase);
         super.run_phase(phase);
         phase.raise_objection(this);
         #10us;
         ASRT: assert ( exp_val == act_val) else
           `uvm_error(get_name(), "Error");
         #10us;
         `uvm_info(get_name(), "Done env", UVM_LOW);
         phase.drop_objection(this);
       endtask : run_phase

    endclass

    program tb_run;

    initial
    begin
       tb_env env = new("env");

       // Requirement: Disable assertion env.ASRT with system call $assertoff(...)

       fork
         run_test();
         begin
          #5us;
          env.exp_val = 1;
         end
       join
    end

    endprogram

$assertoff 系统任务可以关闭特定模块中的断言,但不能关闭特定的 classes 或对象。因此,您必须通过修改 tb_env class 来手动执行此操作。

是的,您可以将 $assertoff 用于您的目的。

这是没有 $assertoff 的代码。

class tb_env;
  int exp_val = 0;
  int act_val = 0;

  virtual task run_phase ();
    #10;
    ASRT: assert ( exp_val == act_val) else
      $error("Error");
  endtask : run_phase
endclass

program tb_run;
  tb_env env = new();

  initial
  begin      
     // $assertoff(0, env.run_phase.ASRT);

     fork
       env.run_phase();
       begin
         #5;
         env.exp_val = 1;
         $display("@%0t : exp_val - %0b, act_val - %0b", $time(), env.exp_val, env.act_val);
       end
     join
  end
endprogram

// Output -
@5 : exp_val - 1, act_val - 0
"a.sv", 7: $unit::\tb_env::run_phase .ASRT: started at 10s failed at 10s
        Offending '(this.exp_val == this.act_val)'
Error: "a.sv", 7: $unit.tb_env::run_phase.ASRT: at time 10
Error
$finish at simulation time                   10

这是你的代码$assertoff

class tb_env;
  int exp_val = 0;
  int act_val = 0;

  virtual task run_phase ();
    #10;
    ASRT: assert ( exp_val == act_val) else
      $error("Error");
  endtask : run_phase
endclass

program tb_run;
  tb_env env = new();

  initial
  begin
     $assertoff(0, env.run_phase.ASRT);

     fork
       env.run_phase();
       begin
         #5;
         env.exp_val = 1;
         $display("@%0t : exp_val - %0b, act_val - %0b", $time(), env.exp_val, env.act_val);
       end
     join
  end
endprogram

// Output -
Stopping new assertion attempts at time 0s: level = 0 arg = $unit::\tb_env::run_phase .ASRT (from inst tb_run (a.sv:17))
@5 : exp_val - 1, act_val - 0
$finish at simulation time                   10

我想让事情简单易懂。所以,更喜欢使用一些胶合逻辑来抑制断言。

对于某些模拟器,$assertoff 仅适用于模块而不适用于 类,您可以使用一些保护标志指示enable/disable 的断言。仅当标志为 set 时才会检查断言。您可以 在基 类 中的任何地方声明此标志,并在来自不同扩展 类 的 enabling/disabling 断言中使用相同的标志。

还可以为这个保护标志开发通用宏。以下代码通过使用 guard 禁用断言。 如果守卫是一个静态变量,那么它可以通过作用域解析 (::) 还有。

import uvm_pkg::*;
`include "uvm_macros.svh"

`define ASSERT(VAL,ERR) \
  assert(!assert_guard || (VAL))  else begin // If assert_guard=0, then assertion passes without checking other condition \
      `uvm_error(get_name(),ERR); \
end \

class tb_env extends uvm_component;
  `uvm_component_utils(tb_env)
  bit assert_guard;

  int exp_val = 0;
  int act_val = 0;

  function new(string name = "tb_env", uvm_component parent = null);
     super.new(name, parent);
     assert_guard = 1; // by default assertions are on
  endfunction

  virtual task run_phase (uvm_phase phase);
     super.run_phase(phase);
     phase.raise_objection(this);
     #10us;
     ASRT: `ASSERT( exp_val == act_val, "Error");       
     #10us;
     `uvm_info(get_name(), "Done env", UVM_LOW);
     phase.drop_objection(this);
  endtask : run_phase

endclass

module tb_run;
 initial begin
   tb_env env = new("env");
   env.assert_guard = 0;
   //tb_env::assert_guard = ; // If assert_guard was static
   //$assertoff(0,env.run_phase.ASRT); // Works only for VCS
   fork
     run_test();
     begin
      #5us;
      env.exp_val = 1;
     end
   join
 end
endmodule
// Output:
UVM_INFO @ 0: reporter [RNTST] Running test ...
UVM_INFO testbench.sv(31) @ 20000: env [env] Done env

作为另一种方法,还可以使用 disable 语句 禁用延迟断言 。但在这种情况下,需要知道触发断言的确切时间。有关此方法的更多信息,请参阅 IEEE 1800-2012 Section 16.4.4