Hi, I am working on a coverage class in OVM. I have a covergroup, and an array (a hex value), and I only want to run a sample on my covergroup when the value of the array is greater than zero.
I have print statements in my if statement, so I know that I am hitting the if statement (data is getting set to the array). However, my covergroup has 0% coverage, which I don’t understand because I feel that the sample() call has to be happening since I’m hitting the if. Is there any way you can be sampling a covergroup and still get 0% coverage for the covergroup?
Also, note that when I did not have the sample() statement inside the if, I had 100% coverage. But whenever I encase it in the if, I cannot get it to have any coverage at all.
I simplified this as much as I could for this example, so this probably isn’t 100% syntactically correct, but here is the general idea:
class cov_example extends ovm_component;
bit coverage_enable = 1;
bit [63:0] array1;
covergroup example_cg;
option.per_instance = 1; // Will indicate that coverage is present, yielding coverage results
array1 : coverpoint array1 {
bins x = {array1[0]};
bins none = default;
}
endgroup : example_cg
`ovm_component_utils_begin(cov_example)
`ovm_field_int(coverage_enable, OVM_DEFAULT)
`ovm_component_utils_end
function new (string name, ovm_component parent);
super.new(name, parent);
example_cg = new();
example_cg.set_inst_name({get_full_name(), ".example_cg"});
endfunction : new
virtual function void build();
super.build();
endfunction : build
function void write(ovm_sequence_item pkt);
someFunction(); // Assume that this is a function that sets array1 to some nonzero value.
if (coverage_enable) begin
if( array1 > 0)begin
example_cg.sample();
end
end
endclass : cov_example