Coverage Practice Questions

  1. Write functional coverage for address between 1000 and 2000 only for read transactions.
module test();
  bit rd_wr;
  bit[31:0] addr;
  covergroup cg;
    coverpoint rd_wr {bins b1 = {1};}
    coverpoint addr {bins b2[] == {[1000:2000]};}
    cross rd_wr,addr {bins b1_b2 = binsof(addr.b2) && binsof(rd_wr.b1);}
  endgroup
  cg cg_inst;
  initial begin
    cg_inst = new();
    cg_inst.sample();
  end
endmodule

2. Write SV code using coverage for 4-bit variable such that all bits toggle at least once.

module tb();
  bit[3:0] data;
  covergroup toggle;
    coverpoint data[0] {bins b1 = (0=>1) or (1=>0);}
    coverpoint data[1] {bins b2 = (0=>1) or (1=>0);}
    coverpoint data[2] {bins b3 = (0=>1) or (1=>0);}
    coverpoint data[3] {bins b4 = (0=>1) or (1=>0);}
  endgroup
  initial begin
    toggle cg = new();
    repeat (10) begin
      data = $urandom_range(0,15);
      cg.sample();
    end
  end
endmodule

3. Write a SV code using cross coverage for 4 bit variable x  and 2 bit variable a excluding below possibilities.

X=5 && a=0,1

X=7 && a=2,3

module m1();
  bit[3:0] x;
  bit[1:0] a;

  initial begin
    covergroup cg @(posedge clk);
      c1: coverpoint x;
      c2: coverpoint a;
      cross c1,c2 {ignore_bins exclude_5 = binsof(x) intersect {5} && binsof(a) intersect {0,1};
                 ignore_bins exclude_7 = binsof(x) intersect {7} && binsof(a) intersect {2,3};}
      endgroup
  end

  cg cover_inst = new();
endmodule