coverage_examples_for_practice
coverage_examples_for_practice
Code snippet
class ram;
covergroup cov;
endgroup
func on new();
endfunc on
endclass
module rakesh;
ram pkt;
ini al begin
repeat(201) begin
end
$finish;
end
endmodule
Code snippet
class ram;
cp1_eve: coverpoint a { bins even_bin[] = {[0:100]} with (item % 2 == 0 && item % 10 == 0);}
cp2_odd: coverpoint a { bins odd_bin[] = {[0:100]} with (item % 2 == 1 && item % 10 == 0);}
endgroup
func on new();
endfunc on
endclass
module rakesh;
ram pkt;
ini al begin
repeat(100) begin
end
$finish;
end
endmodule
Code snippet
class ram;
EIGHT = 7, NINE = 8, TEN = 9, JACK = 10, QUEEN = 11, KING = 12} values;
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ram pkt ;
ini al begin
repeat(100) begin
pkt = new();
void'(pkt.randomize());
pkt.cov.sample();
end
end
endmodule
Code snippet
class ram;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ram pkt ;
ini al begin
repeat(100) begin
pkt = new();
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
5) Cover dice 1 to 6
Code snippet
class ram;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ram pkt ;
ini al begin
repeat(100) begin
pkt = new();
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
6) Cover traffic light dura ons green (30-60) yellow (5-10) red (50-90)
Code snippet
class ram;
covergroup cov();
cp1: coverpoint dura on {
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ram pkt ;
ini al begin
repeat(100) begin
pkt = new();
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
Code snippet
class ram;
covergroup temp_cov;
cp_temp: coverpoint temperature {
endgroup
func on new();
temp_cov = new();
endfunc on
endclass
module rakesh;
ini al begin
pkt.temp_cov.sample();
end
$finish;
end
endmodule
Code snippet
class ram;
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
10) Cover all combina ons of signal A (0/1) and signal B (0/1)
Code snippet
class ram;
rand bit a, b;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
Code snippet
class ram;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
Code snippet
class ram;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
13) Cover all valid IP address ranges (first byte: 10, 172, 192).
Code snippet
class ram;
rand bit [7:0] valid_addr;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
Code snippet
class ram;
covergroup cov();
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
Code snippet
class ram;
endgroup
func on new();
cov = new();
endfunc on
endclass
module rakesh;
ini al begin
void'(pkt.randomize());
pkt.cov.sample();
end
$finish;
end
endmodule
Code snippet
class explicit;
rand bit[2:0] a;
rand bit[2:0] b;
rand bit[2:0] c;
endclass
module rakesh;
bit clk;
explicit p1 = new();
op on.goal = 50;
op on.weight = 10;
op on.name = "rakesh";
op on.per_instance = 0;
op on.at_least = 2;
s1: coverpoint p1.a { bins b1[] = (1, 2 => 3, 4); } // set off transi on
s4: coverpoint p1.a { bins b111 = (2 [<=2] => 4 [=2] => 3); } // non-consecu ve repe on
s5: coverpoint p1.b { bins b7 = (2 [<=1] => 3 [->2] => 2); } // goto repe on, both are same
/* s1:coverpoint p1.a;
s2:coverpoint p1.b;
s3:coverpoint p1.c;
s2_s3:cross s1,s2; */
endgroup
op on.goal = 70;
op on.weight = 5;
op on.name = "rakesh3";
op on.per_instance = 1;
op on.at_least = 1;
endgroup
ini al begin
cg p2 = new();
cgr p3 = new();
repeat(200) begin
p1.randomize();
p2.sample();
p3.sample();
end