CODE WORKING:
module tb;
bit W, X, Y, Z, Q;
// Covergroup with all inputs passed in constructor or sample
covergroup cg with function sample( int W_in,ref bit c);
option.per_instance = 1;
// Coverpoints using sampled inputs
cp1: coverpoint W_in {
bins hit = {1};
bins hited = {0};
}
cp3: coverpoint c{ // Sample argument
bins hit = {1};
bins hited = {0};
}
endgroup
// Covergroup instances
cg cg1 = new(); // instance 1 uses a=0, ref to X
cg cg2 = new(); // instance 2 uses a=1, ref to Y
initial begin
// Stimulus
Z = 0; Q = 0;W=0;
// Pass all as inputs when sampling
cg1.sample( 0,Z); // W_in=W, c=Z
cg2.sample( 0,Q); // W_in=W, c=Q
// Change referenced vars
$display("cg1 coverage = %0.2f%%", cg1.get_inst_coverage());
$display("cg2 coverage = %0.2f%%", cg2.get_inst_coverage());
// Dump all coverage data (tool-dependent)
end
endmodule
**
CODE_NOT_WORKING
**
module tb;
bit W, X, Y, Z, Q;
// Covergroup with all inputs passed in constructor or sample
covergroup cg with function sample( ref bit c,int W_in);
option.per_instance = 1;
// Coverpoints using sampled inputs
cp1: coverpoint W_in {
bins hit = {1};
bins hited = {0};
}
cp3: coverpoint c{ // Sample argument
bins hit = {1};
bins hited = {0};
}
endgroup
// Covergroup instances
cg cg1 = new(); // instance 1 uses a=0, ref to X
cg cg2 = new(); // instance 2 uses a=1, ref to Y
initial begin
// Stimulus
Z = 0; Q = 0;W=0;
// Pass all as inputs when sampling
cg1.sample( Z,0); // W_in=W, c=Z
cg2.sample( Q,0); // W_in=W, c=Q
$display("cg1 coverage = %0.2f%%", cg1.get_inst_coverage());
$display("cg2 coverage = %0.2f%%", cg2.get_inst_coverage());
// Dump all coverage data (tool-dependent)
end
endmodule

