如何从继承的 uvm_test 类中仅执行特定的函数?

huangapple go评论56阅读模式
英文:

How do I execute only targeted function from inherited uvm_test class?

问题

您可以在child_class_cprintInfo函数中添加一个条件,以仅在需要时执行该函数。您可以使用以下代码来实现这一点:

virtual function integer printInfo(integer arraySize = 32);
    integer dummy;
    dummy = super.printInfo(arraySize);
    if (my_num == 3) begin
        $write(" ------------------------------------------------------------------------------\n");
        $write("  %0s printInfo (Time: %0t) : \n", this.get_type_name(), $realtime);
        $write(" ------------------------------------------------------------------------------\n");
        $write("  D : %s\n", D.data());
        $write("  E : %s\n", E.data());
        $write("  F : %s\n", F.data());
    end
endfunction : printInfo

通过在printInfo函数中添加条件检查my_num的值,您可以控制是否执行child_class_cprintInfo函数。当my_num的值等于3时,将执行该函数,否则将继续执行父类的函数。这样,您可以实现只执行child_class_cprintInfo函数。

英文:

There is a UVM sequence item class which has multiple inherited classes.

class my_frame_c extends uvm_sequence_item;
   rand logic [31:0] A;
   rand logic [31:0] B;
   rand logic [31:0] C;
   ...
  `uvm_object_utils_begin(my_frame_c)
    ...
  `uvm_object_utils_end

  function new(string name = "my_frame_c");
    super.new(name);
  endfunction
  
  virtual function integer printInfo(integer arraySize = 32) ;
    $write(" ------------------------------------------------------------------------------\n");
    $write("  %0s printInfo (Time: %0t) : \n", this.get_type_name(), $realtime);
    $write(" ------------------------------------------------------------------------------\n");
    $write("  A : %s\n", A.data());
    $write("  B : %s\n", B.data());
    $write("  C : %s\n", C.data());
  endfunction : printInfo

  // pre_randomize()
  function void pre_randomize();
        super.pre_randomize();
  endfunction : pre_randomize    
endclass 
    
class child_class_c extends my_frame_c ;
   rand logic [31:0] D;
   rand logic [31:0] E;
   rand logic [31:0] F;    
  ...
  int my_num = 3;

  `uvm_object_utils_begin(child_class_c)
   ...
  `uvm_object_utils_end

  function new(input string name = "child_class_c");
    super.new(name);
  endfunction :  new

  ...
  virtual function integer printInfo(integer arraySize = 32) ;
    integer dummy;
    dummy = super.printInfo(arraySize);
    $write(" ------------------------------------------------------------------------------\n");
    $write("  %0s printInfo (Time: %0t) : \n", this.get_type_name(), $realtime);
    $write(" ------------------------------------------------------------------------------\n");
    $write("  D : %s\n", D.data());
    $write("  E : %s\n", E.data());
    $write("  F : %s\n", F.data());        
  endfunction : printInfo

  // pre_randomize()
  function void pre_randomize();
    super.pre_randomize();
  endfunction : pre_randomize    
endclass 

I execute child_init_seq_c class which is inherited my_base_seq.

class my_base_seq extends uvm_sequence #(my_frame_c);
  my_frame_c req;

  function new(string name="my_base_seq");
    super.new(name);
  endfunction      
                   
  `uvm_object_utils(my_base_seq)
  `uvm_declare_p_sequencer(my_sequencer_c)
  
  virtual task pre_body(); 
     if (starting_phase != null) 
        starting_phase.raise_objection(this, {"Running my sequence '",
                                              get_full_name(), "'"});  
  endtask          
                   
  virtual task post_body();
     if (starting_phase != null) 
        starting_phase.drop_objection(this, {"Completed my sequence '", 
                                             get_full_name(), "'"});  
  endtask

endclass : my_base_seq

class child_init_seq_c extends my_base_seq;

  rand logic [31:0] val;
  
  child_class_c req;
  
  `uvm_object_utils(child_init_seq_c)
  `uvm_declare_p_sequencer(my_sequencer_c)
  
  function new(string name = "child_init_seq_c");
    super.new(name);
  endfunction

  virtual task body();
    req = child_class_c::type_id::create("req");
    start_item(req);
    req.printInfo;// I expected only child_class_c's printInfo.
    finish_item(req);
    
  endtask
  
endclass

After I execute req.printInfo;, I got the below result. But, I expected that only one printInfo function print out from the child_class_c printInfo, not the parent class's printInfo.

How do I execute only the function of child_class_c printInfo?

 ------------------------------------------------------------------------------
  my_frame_c printInfo (Time: 80000000) : 
 ------------------------------------------------------------------------------
  A: 32'h0000004a
  B: 32'h00004631
  C: 32'h01e6ef5f
 ------------------------------------------------------------------------------
  my_frame_c printInfo (Time: 80000000) : 
 ------------------------------------------------------------------------------
  D: 32'h0000004a
  E: 32'h00005411
  F: 32'h10000000

答案1

得分: 1

child_class_cprintInfo函数中,请不要调用super.printInfo

virtual function integer printInfo(integer arraySize = 32) ;
  $write(" ------------------------------------------------------------------------------\n");
  $write("  %0s printInfo (Time: %0t) : \n", this.get_type_name(), $realtime);
  $write(" ------------------------------------------------------------------------------\n");
  $write("  D : %s\n", D.data());
  $write("  E : %s\n", E.data());
  $write("  F : %s\n", F.data());
endfunction : printInfo

调用`super`是可选的。
英文:

In the child_class_c printInfo function, don't call super.printInfo:

  virtual function integer printInfo(integer arraySize = 32) ;
    $write(" ------------------------------------------------------------------------------\n");
    $write("  %0s printInfo (Time: %0t) : \n", this.get_type_name(), $realtime);
    $write(" ------------------------------------------------------------------------------\n");
    $write("  D : %s\n", D.data());
    $write("  E : %s\n", E.data());
    $write("  F : %s\n", F.data());
  endfunction : printInfo

Calling super is optional.

huangapple
  • 本文由 发表于 2023年5月10日 15:31:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215937.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定