RTL Design / Module 10: Verification for RTL Designers
Lesson 10.2

Directed tests → corner cases

Happy-path tests prove your design works when everything goes right. Corner-case tests prove it survives when things go wrong — reset mid-transfer, backpressure, overflow, and illegal inputs. Bugs live at the edges.

Definition

A directed test is a hand-crafted scenario: you choose exact inputs, timing, and expected outputs. Start with the nominal path, then systematically attack each boundary condition listed in your test plan.

1

Happy path vs corner cases

Happy path vs corner case test space

Most designers test the green zone first. Production bugs come from the red boundary conditions.

Read spec→Write test plan→Happy path→Corner cases→Review gaps
2

Test plan table — our example DUT

We'll verify a small valid-ready ALU (same family as Module 8 lab). The test plan maps every scenario to stimulus, expected result, and priority.

IDScenarioStimulusExpectedPriority
T01Happy path ADDs_valid=1, a=10, b=20, op=ADDresult=30, m_valid=1P0
T02Happy path MULa=6, b=7, op=MULresult=42P0
T03Reset mid-transferAssert s_valid, drop rst_n before resultNo spurious m_valid; clean after resetP1
T04BackpressureHold m_ready=0 for N cyclesm_valid stays high; result stableP1
T05Overflow / max valuesa=16'hFFFF, b=1, op=ADDresult=0 (wrap)P1
T06Illegal opcodeop=2'b11 (reserved)result=0 or error flag per specP2
T07s_valid without s_readyDrive valid when fullData not accepted; no corruptionP1

Test plan discipline: write the table before coding tests. Review it with your spec. If a row has no expected column, the spec is incomplete.

3

Corner case: reset mid-transfer

Start a transaction, then yank reset before the result appears. The DUT must return to idle with no phantom outputs.

test_reset_mid_xfer.v
// T03 — reset arrives while operation is in flight
task test_reset_mid_xfer;
  begin
    @(posedge clk);
    s_valid = 1; a = 16'd100; b = 16'd50; op = 2'b00;
    @(posedge clk);  // accepted into pipe

    // Reset BEFORE result emerges
    rst_n = 0;
    repeat (2) @(posedge clk);
    rst_n = 1;
    repeat (3) @(posedge clk);

    // After reset: no valid output, no stale data
    if (m_valid !== 1'b0) begin
      $display("FAIL T03: m_valid should be 0 after reset");
      errors = errors + 1;
    end else
      $display("PASS T03: clean idle after reset mid-xfer");
  end
endtask
Trap

After reset mid-transfer, don't just check m_valid — also verify internal state (FSM state, counters) if you have hierarchical access. A quiet output with a dirty FSM will fail on the next transaction.

4

Corner case: backpressure

When downstream isn't ready (m_ready=0), the DUT must hold the result without dropping or duplicating it.

test_backpressure.v
// T04 — hold m_ready low; result must not change
task test_backpressure;
  reg [31:0] captured;
  begin
    drive_op(16'd7, 16'd3, 2'b00);  // ADD → 10
    wait(m_valid);
    captured = result;
    m_ready = 0;

    repeat (5) @(posedge clk);
    if (result !== captured) begin
      $display("FAIL T04: result changed under backpressure");
      errors = errors + 1;
    end
    if (m_valid !== 1'b1) begin
      $display("FAIL T04: m_valid dropped while stalled");
      errors = errors + 1;
    end

    m_ready = 1;
    @(posedge clk);
    if (result !== 32'd10) begin
      $display("FAIL T04: wrong result after release");
      errors = errors + 1;
    end else
      $display("PASS T04: backpressure held correctly");
  end
endtask
5

Corner cases: overflow & illegal opcode

test_overflow_illegal.v
// T05 — 16-bit overflow wrap
task test_overflow;
  begin
    drive_op(16'hFFFF, 16'd1, 2'b00);
    check_result(32'd0, "T05_overflow_wrap");
  end
endtask

// T06 — illegal opcode (must match YOUR spec)
task test_illegal_opcode;
  begin
    drive_op(16'd5, 16'd5, 2'b11);  // reserved op
    wait(m_valid);
    @(posedge clk);
    // Spec says: default → 0. Adjust if your spec differs!
    if (result !== 32'd0) begin
      $display("FAIL T06: illegal op returned %0d", result);
      errors = errors + 1;
    end else
      $display("PASS T06: illegal opcode handled");
  end
endtask
📏

Boundary values

Test 0, 1, MAX, MAX-1, MAX+1. Overflow bugs hide at bit-width edges.

🚫

Illegal inputs

Reserved opcodes, out-of-range addresses — define expected behavior in spec, then test it.

🔁

Back-to-back stress

After each corner, run a happy-path test to confirm recovery.

6

Test suite runner — tying it together

corner_case_suite.v — main initial block
initial begin
  errors = 0;
  rst_n = 0; m_ready = 1; s_valid = 0;
  repeat (3) @(posedge clk);
  rst_n = 1;

  $display("=== P0: Happy path ===");
  drive_op(16'd10, 16'd20, 2'b00);
  check_result(32'd30, "T01_add");
  drive_op(16'd6, 16'd7, 2'b01);
  check_result(32'd42, "T02_mul");

  $display("=== P1: Corner cases ===");
  test_reset_mid_xfer();
  test_backpressure();
  test_overflow();

  $display("=== P2: Edge / illegal ===");
  test_illegal_opcode();

  $display("===================================");
  if (errors == 0) $display("=== ALL DIRECTED TESTS PASSED ===");
  else             $display("=== %0d CORNER TEST(S) FAILED ===", errors);
  $finish;
end
▶ Run corner-case suite in simulator
7

Reusable TB tasks — drive and check

Corner-case tests share the same drive/check infrastructure. Factor these into tasks once:

tb_tasks.v — shared infrastructure
task drive_op(input [15:0] ta, tb; input [1:0] top);
  begin
    @(posedge clk);
    s_valid = 1; a = ta; b = tb; op = top;
    wait(s_ready);
    @(posedge clk);
    s_valid = 0;
  end
endtask

task check_result(input [31:0] exp; input string name);
  begin
    wait(m_valid);
    @(posedge clk);
    #1;
    if (result !== exp) begin
      $display("FAIL [%s]: got %0d expected %0d at t=%0t",
               name, result, exp, $time);
      errors = errors + 1;
    end else
      $display("PASS [%s]", name);
  end
endtask

// Every corner test calls these — consistent timing, consistent errors
8

How to find corners you missed

  • Spec walk: every "shall", "if", "when" in the spec → at least one test row.
  • Interface signals: toggle each handshake signal independently (valid without ready, ready without valid).
  • State coverage: visit every FSM state; enter/exit each via at least two paths.
  • Peer review: ask a colleague "what would break this?" — they'll name a corner you missed.
9

Directed test checklist

  • Test plan table written with ID, stimulus, expected, priority
  • P0 happy-path tests pass before attacking corners
  • Reset mid-operation tested for every block with internal state
  • Backpressure / flow control tested on every valid-ready interface
  • Overflow and boundary values tested at bit-width limits
  • Illegal / reserved inputs have defined expected behavior
  • Recovery test (happy path) runs after each destructive corner

🎯 What to remember

  • Happy path proves it works; corner cases prove it doesn't break.
  • Write a test plan table — bugs hide in rows you never wrote.
  • Reset mid-xfer, backpressure, overflow, illegal opcode: the big four for most blocks.
  • Always verify recovery — a corner test that leaves dirty state is incomplete.
Advertisement