Reputation: 151
I want to instrument my system verilog model for collecting functional coverage on the packets it processes. Specifically, I want to see of the distribution of the packet length in the incoming packet. However, my naive attempt gives "null reference" on sample method below. What is the way to do this?
class packet;
rand bit[7:0] len;
covergroup packet_len_cg;
coverpoint len;
endgroup
endclass
class model;
// Scoreboard calls this to process the input packet
function void run(packet p1);
p1.packet_len_cg.sample(); //FAILS WITH NULL REFERENCE!!
endfunction
endclass
module test;
model m1;
packet p1;
initial begin
m1 = new();
p1 = new();
assert(p1.randomize());
m1.run(p1);
end
endmodule
My code on edaplayground https://www.edaplayground.com/x/2VPm
Upvotes: 1
Views: 1181
Reputation: 42738
You need to construct the covergroup.
class packet;
rand bit[7:0] len;
covergroup packet_len_cg;
coverpoint len;
endgroup
function new;
packet_len_cg = new;
endfunction
endclass
Upvotes: 2