Module 9: SystemVerilog for Design & Verification · 9.3 Assertions — SVA

Immediate Assertions

Section 6.4 implemented testbench verification checks using procedural if statements and $error tasks. SystemVerilog formalizes this checking methodology using the dedicated assert statement. Immediate assertions execute inline within procedural blocks and can reside directly inside synthesizable RTL modules.

Immediate Assertion Syntax

An immediate assertion evaluates a Boolean expression at the current simulation timestamp:

assert (result == expected)
else $error("Mismatch detected: result=%h expected=%h", result, expected);

The assertion syntax expresses design intent directly. Unlike an inverted if (!condition) block, the assertion states the required true condition explicitly. If the expression evaluates to false, the simulator executes the associated else action block.

Embedding Invariants in RTL Modules

External testbenches verify black-box input-to-output behavior. In contrast, embedded RTL assertions verify white-box internal invariants continuously:

module fifo_internal_check #(parameter DEPTH = 16) (
    input logic clk, rst_n
    // Standard FIFO interface signals
);
    // Internal FIFO implementation logic

    // Invariant check: pointer index must not exceed maximum depth
    always_ff @(posedge clk) begin
        if (rst_n) begin
            assert (wr_ptr <= (2 * DEPTH - 1))
            else $error("wr_ptr exceeded legal range: %0d", wr_ptr);
        end
    end
endmodule

This internal check executes across every testbench run. If a future code modification corrupts the pointer math, the assertion flags the defect immediately. The check detects the root cause at the point of failure rather than cycles later at an output port.

Assertion Severity Levels

Configure assertion action blocks with appropriate severity tasks:

// Fatal error: terminates simulation immediately
assert (queue_depth <= MAX_DEPTH)
else $fatal(1, "Queue overflow: critical system failure");

// Standard error: logs failure and increments error counter
assert (result == golden_value)
else $error("Functional computation mismatch");

// Warning: logs non-fatal anomaly
assert (latency_cycles <= EXPECTED_MAX_LATENCY)
else $warning("Latency exceeded expected threshold: %0d", latency_cycles);

Use $fatal for catastrophic failures that corrupt subsequent testbench execution. Use $error for functional mismatches, and $warning for non-critical performance anomalies.

Black-Box vs White-Box Verification

Combining external testbench scoreboards with embedded RTL assertions improves verification coverage. Scoreboards verify compliance with external functional specifications. Embedded assertions verify internal design constraints, such as one-hot state encodings and queue boundaries. This dual approach isolates defects rapidly during development and regression testing.

Practice Exercise

An FSM uses one-hot state encoding. Write an immediate assertion inside a clocked block to verify that exactly one state bit is asserted. Use the built-in $onehot system function.

Solution
always_ff @(posedge clk) begin
    if (rst_n) begin
        assert ($onehot(state))
        else $error("State register is not one-hot: %b", state);
    end
end

The $onehot() system function returns true if and only if exactly one bit is logic 1. The assertion validates this invariant on every active clock edge during simulation.

Immediate assertions evaluate Boolean expressions procedurally and trigger severity action blocks upon failure. Embedding assertions directly in RTL code validates internal invariants across all simulation runs. The next article introduces concurrent assertions for multi-cycle temporal protocol verification.

← Toward a UVM-Ready Testbench Concurrent Assertions and Temporal Logic →