I am trying to make functional coverage make work as toggle coverage but instead getting 0 hits please help
CODE :-
class cov_class;
bit [31:0] rand_var;
bit sample;
covergroup toggle(ref bit value)
@(sample);
option.per_instance = 1;
coverpoint value
{
bins bins_of_toggle = (1=>0=>1),(0=>1=>0);
}
endgroup
function new ;
for (int i = 0; i < $bits(rand_var); i++) begin
automatic bit v;
v=rand_var[i];
toggle = new(v);
toggle.set_inst_name("TOGGLE");
toggle.start();
end
endfunction
endclass
// Testbench
module tb;
cov_class c;
initial begin
c = new();
repeat(10)
begin
c.rand_var = {$random};
c.sample=~c.sample;
#1;
end
$display("Coverage collection done!");
end
endmodule
You have a class embedded covergroup that you construct multiple times, erasing the previous covegroup instance. You want an array of covergroups, and that needs to be declared outside the class.
The value of v never changes.
You probably want multiple bins to cover toggles directions separately.
Try this:
covergroup tgl_cg(int index, ref bit [31:0] value, event sample)
@(sample);
option.per_instance = 1;
coverpoint value[index]
{
bins bins_of_toggle[] = (1=>0=>1),(0=>1=>0);
}
endgroup
class cov_class;
event sample;
bit [31:0] rand_var;
tgl_cg toggle[32];
function new ;
foreach(toggle[i]) begin
toggle[i] = new(i,rand_var, sample);
toggle[i].set_inst_name($sformatf("TOGGLE%0d",i));
end
endfunction
endclass
// Testbench
module tb;
cov_class c;
initial begin
c = new();
repeat(10)
begin
c.rand_var = {$urandom};
->c.sample;
$displayb(c.rand_var);
foreach(c.toggle[i]) $display(c.toggle[i].get_inst_coverage());
#1;
end
$display("Coverage collection done!");
end
endmodule
You have a class embedded covergroup that you construct multiple times, erasing the previous covegroup instance. You want an array of covergroups, and that needs to be declared outside the class.
The value of v never changes.
I did Following changes in my previous code only , But getting 100% coverage as if its not possible and not even accurate ,i guess last value is overriding others:-
My doubt was if we have already made array of 32 covergroup and gave separate memory for each in new constructer and passed every bit from out side in loop while event sampling, so is it really necessary to make coverpoint as ( value[index] ) inside covergroup
why so?
CODE :-
covergroup tgl_cg(int index, ref bit value, event sample)
@(sample);
option.per_instance = 1;
coverpoint value
{
bins bins_of_toggle= (1=>0=>1),(0=>1=>0);
}
endgroup
class cov_class;
event sample;
bit [31:0] rand_var;
bit temp;
tgl_cg toggle[32];
function new ;
foreach(toggle[i]) begin
temp=rand_var[i];
toggle[i] = new(i,temp, sample);
toggle[i].set_inst_name($sformatf("TOGGLE%0d",i));
end
endfunction
endclass
// Testbench
module tb;
cov_class c;
initial begin
c = new();
repeat(10)
begin
c.rand_var = {$urandom};
foreach (c.rand_var[i])
begin
c.temp=c.rand_var[i];
->c.sample;
#1;
end
$displayb(c.rand_var);
foreach(c.toggle[i]) $display(c.toggle[i].get_inst_coverage());
end
$display("Coverage collection done!");
end
endmodule
The way your latest code is written, the -> c.sample triggers the sampling of all 32 instances of the covergroup with the same coverpoint temp value.
If you use a single sampling triggger, each instance needs to know which bit index is being covered. Alternatively you can individually sample each of the 32 covergroups.