system-veriloguvm

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


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

Solution

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