3

我正在寻找为某些测试禁用侧面 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
4

3 回答 3

2

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

对于某些模拟器,$assertoff 仅适用于模块而不适用于类,您可以使用一些指示启用/禁用断言的保护标志只有在设置标志时才会检查断言。您可以在基类中的任何位置声明此标志,并在启用/禁用来自不同扩展类的断言时使用相同的标志

也可以为这个保护标志开发一个通用的宏。以下代码通过使用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 第 16.4.4 节。

于 2017-12-23T04:05:47.977 回答
1

是的,您可以将$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
于 2017-12-22T20:44:15.777 回答
1

$assertoff系统任务可以关闭特定模块中的断言,但不能关闭特定类或对象。所以,你必须通过修改你的tb_env类来手动完成。

于 2017-12-22T09:29:59.933 回答