top of page

Good catch โ€” youโ€™re right ๐Ÿ‘
Coverage without code feels abstract, and interviews do expect you to have at least seen and reasoned through covergroups.
Below is a revised Coverage โ€“ Part 1, still medium length, but now grounded with runnable SystemVerilog code, while keeping theory light and memorable.

Coverage in SystemVerilog (Part 1) โ€” Why Random Tests Alone Are Not Enough (With Code)

๐ˆ๐ง๐ญ๐ซ๐จ๐๐ฎ๐œ๐ญ๐ข๐จ๐ง

Alice has done a lot already:

  • random stimulus

  • constraints

  • assertions

Her simulation runs clean. No errors.

Bob now asks the uncomfortable question:

  โ€œHow do you know you actually tested anything meaningful?โ€

Silence usually follows.

This is why coverage exists โ€” to measure what really happened, not what could have happened.


๐–๐ก๐š๐ญ ๐ˆ๐ฌ ๐‚๐จ๐ฏ๐ž๐ซ๐š๐ ๐ž ๐ข๐ง ๐’๐ฒ๐ฌ๐ญ๐ž๐ฆ๐•๐ž๐ซ๐ข๐ฅ๐จ๐ ?

Google Featured Snippet Target)

๐‚๐จ๐ฏ๐ž๐ซ๐š๐ ๐ž ๐ข๐ง ๐’๐ฒ๐ฌ๐ญ๐ž๐ฆ๐•๐ž๐ซ๐ข๐ฅ๐จ๐  ๐ฆ๐ž๐š๐ฌ๐ฎ๐ซ๐ž๐ฌ ๐ฐ๐ก๐ข๐œ๐ก ๐ฏ๐š๐ฅ๐ฎ๐ž๐ฌ, ๐ฌ๐œ๐ž๐ง๐š๐ซ๐ข๐จ๐ฌ, ๐จ๐ซ ๐›๐ž๐ก๐š๐ฏ๐ข๐จ๐ซ๐ฌ ๐ก๐š๐ฏ๐ž ๐จ๐œ๐œ๐ฎ๐ซ๐ซ๐ž๐ ๐๐ฎ๐ซ๐ข๐ง๐  ๐ฌ๐ข๐ฆ๐ฎ๐ฅ๐š๐ญ๐ข๐จ๐ง, ๐ก๐ž๐ฅ๐ฉ๐ข๐ง๐  ๐ช๐ฎ๐š๐ง๐ญ๐ข๐Ÿ๐ฒ ๐ฏ๐ž๐ซ๐ข๐Ÿ๐ข๐œ๐š๐ญ๐ข๐จ๐ง ๐œ๐จ๐ฆ๐ฉ๐ฅ๐ž๐ญ๐ž๐ง๐ž๐ฌ๐ฌ.

Coverage does not check correctness.

Coverage checks exploration.


๐€๐ฅ๐ข๐œ๐ž & ๐๐จ๐› ๐Œ๐ž๐ง๐ญ๐š๐ฅ ๐Œ๐จ๐๐ž๐ฅ

  • Alice generates tests

  • Bob observes execution

  • Bob keeps counters:

โ€œThis happenedโ€

โ€œThis never happenedโ€

Coverage is Bobโ€™s notebook, not Aliceโ€™s logic.


๐…๐ข๐ซ๐ฌ๐ญ ๐“๐š๐ฌ๐ญ๐ž: ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐š๐ฅ ๐‚๐จ๐ฏ๐ž๐ซ๐š๐ ๐ž ๐ฐ๐ข๐ญ๐ก ๐‘๐ž๐š๐ฅ ๐‚๐จ๐๐ž

Letโ€™s start simple and concrete.

Alice wants to know:

  • Did addr ever take low values?

  • Did it ever take high values?

She doesnโ€™t care how it was generated โ€” only if it happened.


๐๐š๐ฌ๐ข๐œ ๐‚๐จ๐ฏ๐ž๐ซ๐ ๐ซ๐จ๐ฎ๐ฉ ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž (๐‘๐ฎ๐ง๐ง๐š๐›๐ฅ๐ž)

module basic_coverage;

  int addr;

  covergroup addr_cg;

    coverpoint addr {

      bins low  = {[0:3]};

      bins mid  = {[4:7]};

      bins high = {[8:15]};

    }

  endgroup

  addr_cg cg = new();

  initial begin

    repeat (10) begin

      addr = $urandom_range(0,15);

      cg.sample();

      $display("addr = %0d", addr);

    end

  end

endmodule

๐–๐ก๐š๐ญ ๐ˆ๐ฌ ๐‡๐š๐ฉ๐ฉ๐ž๐ง๐ข๐ง๐  ๐‡๐ž๐ซ๐ž (๐•๐ž๐ซ๐ฒ ๐ˆ๐ฆ๐ฉ๐จ๐ซ๐ญ๐š๐ง๐ญ)

  • covergroup defines what to observe

  • coverpoint defines which signal

  • bins define interesting value ranges

  • sample() records the current value

Alice does not force values.

She only measures what occurs.


๐–๐ก๐ฒ ๐“๐ก๐ข๐ฌ ๐ˆ๐ฌ ๐๐จ๐ฐ๐ž๐ซ๐Ÿ๐ฎ๐ฅ (๐ˆ๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ ๐ˆ๐ง๐ฌ๐ข๐ ๐ก๐ญ)

Even if:

  • addr never becomes 15

  • simulation passes

Coverage will clearly show:

โ€œhigh bin was never hitโ€

This tells Alice:

  • testbench is incomplete

  • constraints or stimulus must improve

๐‚๐จ๐ฏ๐ž๐ซ๐š๐ ๐ž ๐ฏ๐ฌ ๐€๐ฌ๐ฌ๐ž๐ซ๐ญ๐ข๐จ๐ง๐ฌ (๐‚๐ฅ๐ž๐š๐ซ ๐ƒ๐ข๐Ÿ๐Ÿ๐ž๐ซ๐ž๐ง๐œ๐ž)

Letโ€™s compare with an assertion.

assert (addr < 16)

  else $error("Invalid addr");

  • Assertion checks correctness

  • Coverage checks occurrence

Interview-safe sentence:

Assertions catch bugs; coverage reveals blind spots.


๐‚๐จ๐๐ž ๐‚๐จ๐ฏ๐ž๐ซ๐š๐ ๐ž ๐ฏ๐ฌ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐š๐ฅ ๐‚๐จ๐ฏ๐ž๐ซ๐š๐ ๐ž (๐–๐ข๐ญ๐ก ๐‚๐จ๐ง๐ญ๐ž๐ฑ๐ญ)

Tools automatically collect code coverage:

  • line coverage

  • branch coverage

  • toggle coverage

Alice does not write code for that.

Functional coverage is:

  • written by Alice

  • based on design intent

  • scenario-driven

This is why functional coverage matters more in interviews.

๐€๐ฅ๐ข๐œ๐ž ๐Œ๐š๐ค๐ž๐ฌ ๐ˆ๐ญ ๐Œ๐จ๐ซ๐ž ๐‘๐ž๐š๐ฅ๐ข๐ฌ๐ญ๐ข๐œ

Now Alice wants to see:

  • read vs write operations

  • not just raw values

๐‘๐ฎ๐ง๐ง๐š๐›๐ฅ๐ž ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž โ€” ๐Œ๐ฎ๐ฅ๐ญ๐ข๐ฉ๐ฅ๐ž ๐‚๐จ๐ฏ๐ž๐ซ๐ฉ๐จ๐ข๐ง๐ญ๐ฌ

module op_coverage;

  bit write;

  int addr;

  covergroup op_cg;

    coverpoint write {

      bins read  = {0};

      bins write = {1};

    }

    coverpoint addr {

      bins low  = {[0:3]};

      bins high = {[12:15]};

    }

  endgroup

  op_cg cg = new();

  initial begin

    repeat (20) begin

      write = $urandom_range(0,1);

      addr  = $urandom_range(0,15);

      cg.sample();

      $display("write=%0d addr=%0d", write, addr);

    end

  end

endmodule

๐–๐ก๐š๐ญ ๐€๐ฅ๐ข๐œ๐ž ๐‹๐ž๐š๐ซ๐ง๐ฌ ๐Ÿ๐ซ๐จ๐ฆ ๐“๐ก๐ข๐ฌ

After simulation:

  • Did both read and write occur?

  • Were both low and high addresses exercised?

No guessing.

Coverage data answers directly.


๐‚๐จ๐ฆ๐ฆ๐จ๐ง ๐๐ž๐ ๐ข๐ง๐ง๐ž๐ซ ๐Œ๐ข๐ฌ๐ญ๐š๐ค๐ž๐ฌ (๐–๐ข๐ญ๐ก ๐‚๐จ๐๐ž ๐‚๐จ๐ง๐ญ๐ž๐ฑ๐ญ)

  • Forgetting to call sample()

  • Assuming coverage samples automatically

  • Writing coverage without knowing intent

  • Sampling at the wrong time

Interviewers often ask:

โ€œWhen does coverage get sampled?โ€

Correct answer:

When sample() is called (unless clocked).

๐Ž๐ง๐ž ๐•๐ž๐ซ๐ฒ ๐ˆ๐ฆ๐ฉ๐จ๐ซ๐ญ๐š๐ง๐ญ ๐ˆ๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ ๐๐จ๐ข๐ง๐ญ

Coverage does not improve tests automatically.

Alice must:

  1. look at coverage reports

  2. identify holes

  3. improve stimulus or constraints

Coverage is feedback, not magic.

๐ˆ๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ ๐๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง๐ฌ ๐˜๐จ๐ฎ ๐‚๐š๐ง ๐๐จ๐ฐ ๐€๐ง๐ฌ๐ฐ๐ž๐ซ

  • What is functional coverage?

  • What are covergroups and coverpoints?

  • What are bins?

  • How is coverage different from assertions?

  • Does coverage affect simulation behavior?

All answerable from this article.

๐Ž๐ง๐ž ๐’๐ž๐ง๐ญ๐ž๐ง๐œ๐ž ๐ญ๐จ ๐‘๐ž๐ฆ๐ž๐ฆ๐›๐ž๐ซ (๐’๐ง๐ข๐ฉ๐ฉ๐ž๐ญ + ๐ˆ๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ ๐…๐ซ๐ข๐ž๐ง๐๐ฅ๐ฒ)

Functional coverage measures which scenarios occurred during simulation, independent of correctness.


๐–๐ก๐š๐ญโ€™๐ฌ ๐๐ž๐ฑ๐ญ


๐Ÿ‘‰ ๐๐ž๐ฑ๐ญ ๐€๐ซ๐ญ๐ข๐œ๐ฅ๐ž:

Coverage in SystemVerilog (Part 2) โ€” Cross Coverage, Bins, and Interview Traps

bottom of page