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.
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.
Most designers test the green zone first. Production bugs come from the red boundary conditions.
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.
| ID | Scenario | Stimulus | Expected | Priority |
|---|---|---|---|---|
| T01 | Happy path ADD | s_valid=1, a=10, b=20, op=ADD | result=30, m_valid=1 | P0 |
| T02 | Happy path MUL | a=6, b=7, op=MUL | result=42 | P0 |
| T03 | Reset mid-transfer | Assert s_valid, drop rst_n before result | No spurious m_valid; clean after reset | P1 |
| T04 | Backpressure | Hold m_ready=0 for N cycles | m_valid stays high; result stable | P1 |
| T05 | Overflow / max values | a=16'hFFFF, b=1, op=ADD | result=0 (wrap) | P1 |
| T06 | Illegal opcode | op=2'b11 (reserved) | result=0 or error flag per spec | P2 |
| T07 | s_valid without s_ready | Drive valid when full | Data not accepted; no corruption | P1 |
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.
Start a transaction, then yank reset before the result appears. The DUT must return to idle with no phantom outputs.
// 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
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.
When downstream isn't ready (m_ready=0), the DUT must hold the result without dropping or duplicating it.
// 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
// 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
Test 0, 1, MAX, MAX-1, MAX+1. Overflow bugs hide at bit-width edges.
Reserved opcodes, out-of-range addresses — define expected behavior in spec, then test it.
After each corner, run a happy-path test to confirm recovery.
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
Corner-case tests share the same drive/check infrastructure. Factor these into tasks once:
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