Welcome ! This website will help YOU (recent graduates/professionals) learn verification languages like SystemVerilog and UVM. Register for free and access more content !
2 minutes reading time (418 words)

Overriding covergroups

covergroup-inheritance

In a previous post, we saw that covergroups are also inherited by child classes and the result of sample() on coverage of both base and child classes. Although we can keep building new covergroups in each derived child class, it would be worth to explore if the same covergroup can be overridden with a new set of coverpoints and bins in the child class.

Let us define a class called A with a covergroup named cgA and a derived class called B with the same covergroup called cgA to see if the child covergroup is able to override the parent. Class A has 16 bins, one for each value of the coverpoint variable var1.

class A;
  rand bit[3:0] var1;
 
  covergroup cgA;
    coverpoint var1 {
      bins each[16] = {[0:$]};
      }
  endgroup
 
  function new ();
    cgA = new;
  endfunction
endclass
 

In class B, we'll redefine the same covergroup to have only a single bin to cover all the values of var1 so that it will be easily visible from the coverage report.

class B extends A;
  covergroup cgA;
    coverpoint var1 {
      bins all = {[0:$]}; 
    }
  endgroup
 
  function new ();
    super.new();
    cgA = new;     // IMPORTANT: cgA should be renewed
  endfunction
endclass
 

In our testbench, we'll randomize objects of both A and B and sample A first.

module tb;
  A a;
  B b;
  initial begin
    a = new();
    b = new();
 
    for (int i = 0;i < 5; i++) begin
      a.randomize();
      b.randomize();
      $display ("a.var1=0x%0h b.var1=0x%0h", a.var1, b.var1);
      a.cgA.sample();
    end
 
    $display ("A.cgA get_coverage = %0.2f %%   get_inst_coverage = %0.2f %%", a.cgA.get_coverage(), a.cgA.get_inst_coverage());
    $display ("B.cgA get_coverage = %0.2f %%   get_inst_coverage = %0.2f %%", b.cgA.get_coverage(), b.cgA.get_inst_coverage());
  end
endmodule
 
Simulation Log
ncsim> run
a.var1=0xf b.var1=0xe
a.var1=0xf b.var1=0xd
a.var1=0x2 b.var1=0xe
a.var1=0x9 b.var1=0xf
a.var1=0xe b.var1=0x5
A.cgA get_coverage = 25.00 %   get_inst_coverage = 25.00 %
B.cgA get_coverage = 0.00 %   get_inst_coverage = 0.00 %
ncsim: *W,RNQUIE: Simulation is complete.

Now, we'll try sampling both A and B covergroups.

    for (int i = 0;i < 5; i++) begin
      a.randomize();
      b.randomize();
      $display ("a.var1=0x%0h b.var1=0x%0h", a.var1, b.var1);
      a.cgA.sample();
      b.cgA.sample();
    end
 

It can be seen from the simulation results that cgA in B has overridden the covergroup in its parent class A, yielding a coverage of 100% because of a single bin for all values.

Simulation Log
ncsim> run
a.var1=0xf b.var1=0xe
a.var1=0xf b.var1=0xd
a.var1=0x2 b.var1=0xe
a.var1=0x9 b.var1=0xf
a.var1=0xe b.var1=0x5
A.cgA get_coverage = 25.00 %   get_inst_coverage = 25.00 %
B.cgA get_coverage = 100.00 %   get_inst_coverage = 100.00 %
ncsim: *W,RNQUIE: Simulation is complete.
Using a custom sample function for functional cove...

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Guest
Friday, 25 May 2018

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. You consent to our cookies if you continue to use our website. To find out more about the cookies we use and how to delete them, see our privacy policy.

  I accept cookies from this site.
Agree
EU Cookie Directive plugin by www.channeldigital.co.uk