Immediate Assertions, Action Blocks and Severity

Write immediate assert, assume and cover checks in procedures, choose their action blocks, and pick the right severity task.

You Will Be Able To

  • Write an immediate assert with a label, a pass action and an else action.
  • Predict when an immediate assertion in combinational code fires on a value that never settles.
  • Choose between immediate assert, assume and cover for a rule.
  • Pick $info, $warning, $error or $fatal for a failure, and say whether the run goes on.
Lesson
A1.4
Time
25 min
Runs on
Verilator
Check
5 questions

A decoder check failed once in a regression, at 10 ns. The waveform showed a = 0 and b = 1 at 10 ns, a legal one-hot pair. The check was right, and so was the waveform. Inside that one time step, a fell before b rose, and the check ran in between.

One time step, seen step by step
012moment in t=10beforea writtenb writtenaba ^ bcheck ran?noyes: failsyes: passesthe check sees a=0, b=0
Scroll horizontally ↔

A waveform shows only the last value of each time step. The check ran twice inside it, once on a value that lasted zero time.

An Immediate Assertion Is a Checked If

An immediate assertion is a statement inside a procedure: assert (expr) pass_action else fail_action;. It runs when the procedure reaches it, like an if. It reads the current values of its signals, not sampled ones, and it takes no time.

expr evaluates toResultAction that runs
1 (or any nonzero value)passthe pass action
0failthe else action
x or zfailthe else action

An unknown value is a failure, as in IEEE 1800-2023 16.3.

Give each assertion a label, such as one_hot: assert (...). Tools print the label in their messages, so a failure names its rule.

Glitches in Combinational Code

An always @(a or b) block runs every time a or b changes. When the two changes come from different steps of one time step, the block runs in between them. An immediate assertion inside it then checks a value that never settles.

Two Writes, Two Runs of the CheckThe time step at 10 ns of the lesson example. The bench writes a, waits with #0, then writes b. The check block wakes after each write.
  • Step
  • Storage
  • Property
  • Report
  • Data
  • Control
data: where the transaction goescall: who calls whom
CallValueReturnWaiting
Two writes, two runs of the checkThe time step at 10 ns of the lesson example. The bench writes `a`, waits with `#0`, then writes `b`. The check block wakes after each write. step Bench process a = 0; #0 b = 1; storage a and b The variables property Check block always @(a or b) report Log Fail action output writeswakesfails
  1. step Bench processa = 0; #0 b = 1;
    • writes → a and b
  2. storage a and bThe variables
    • wakes → Check block
  3. property Check blockalways @(a or b)
    • fails → Log
  4. report LogFail action output
  1. First write

    The bench writes a = 0, then waits with #0. Waiting lets other processes run in the same time step.

    Follow the calls, values and waits
    1. data a = 0: Bench process → a and b
  2. The check runs early

    The change on a wakes the check block. It reads a = 0 and b = 0, so a ^ b is 0 and the fail action runs.

    Follow the calls, values and waits
    1. call a=0 b=0: a and b → Check block
    2. data one_hot failed: Check block → Log
  3. Second write

    The bench resumes and writes b = 1. The pair is now legal again.

    Follow the calls, values and waits
    1. data b = 1: Bench process → a and b
  4. The check runs again

    The change on b wakes the block a second time. Now it passes. The failure has already been printed.

    More context

    When both writes come from one process with no wait between them, the block runs once, after both. How many times it runs in one time step depends on the scheduling, so such a check is fragile.

    Follow the calls, values and waits
    1. call a=0 b=1: a and b → Check block
Read the diagram as text
  • Bench process: a = 0; #0 b = 1;
  • a and b: The variables
  • Check block: always @(a or b)
  • Log: Fail action output
  • Bench process → a and b: writes
  • a and b → Check block: wakes
  • Check block → Log: fails

An immediate assertion checks the values of the moment it runs. In code that can run several times per time step, that moment may be in the middle.

There are two ways out. Check at a clock edge, where values are stable. Or use a deferred assertion, assert #0, which reports only the last result of the time step; a later lesson covers it.

Action Blocks

The pass action runs when the check passes, and the else action when it fails. Either can be one statement or a begin ... end block. Print the values you checked, so the message explains itself.

With no else, a failure calls $error with a message the tool chooses. Most checks leave the pass action out: a pass on every clock fills the log.

A message that says little

assert (a ^ b);

The tool prints its own text, without a or b.

A message that explains itself

one_hot: assert (a ^ b)
  else $error("a=%b b=%b", a, b);

The label names the rule; the values show why.

Immediate Assume

assume (expr) states a rule about the inputs of the block under check, such as "the bench never drives mode 3". In simulation it is checked exactly like assert, and its else action runs on a failure.

A formal tool treats it differently. It does not check an assumption; it only explores inputs that obey it. So use assume for rules about the environment, and assert for rules the design must keep.

Immediate Cover

cover (expr) statement; runs its statement each time it is reached with expr true. It has no else, because nothing is wrong when a scenario does not happen. Tools also count it, so you can show that a scenario occurred.

Standard behaviour: a cover statement in a loop
0123pass of the loop1234v00011011v[0]statement runsnoyesnoyeshits, standard012hits, measuredv[0] is 1: the statement runsand again
Scroll horizontally ↔

Standard behaviour, not run on these simulators. The loop sets v to 0, 1, 2 and 3, then runs cover (v[0]) hits++;. By IEEE 1800-2023 16.3 the statement runs on each true evaluation, so hits ends at 2. Verilator 5.052 and Icarus 12 both end at 0 (measured 2026-11-12).

Until a tool runs the statement, count the scenario yourself. An if (expr) hits++; beside the cover gives the standard's number on both simulators.

$info: A Note in the Log

Four severity tasks report a message: $info, $warning, $error and $fatal. You can call them in action blocks or anywhere in procedural code. Each message also carries the time and the scope.

TaskMeansStandard: the runIcarus 12Verilator 5.052
$infofor your informationgoes ongoes ongoes on
$warningsuspicious, maybe finegoes ongoes ongoes on
$errora rule was brokengoes ongoes onstops ($stop)
$fatalnothing after this is meaningfulends ($finish)ends, final blocks runstops ($stop), no final block

The severity ladder. Only $fatal ends a run in the standard (IEEE 1800-2023 20.10). The two tool columns are measured.

$info is the lowest step. It records something worth knowing, such as a mode change, and the run goes on. Here it sits in a pass action.

$warning: Suspicious, and the Run Goes On

$warning reports something that may be wrong, such as a value close to a limit. The run goes on. Many flows count warnings and review them after the regression.

$error: A Broken Rule, and the Run Goes On

Use $error for a broken rule. In the standard the run goes on, so one run can report every failure. An assertion with no else calls $error too.

$fatal: The Run Ends

Use $fatal only when going on is pointless, such as a missing configuration file. It ends the run by calling $finish, so final blocks still run.

$fatal(n, "msg") passes n to $finish, which chooses how much to print on the way out. A 0 prints nothing extra. A 1 adds the time and place, and a 2 adds memory and CPU use. Icarus 12 prints the same for all three.

Try It

At 10, the #0 lets the check block run between the two writes, so one_hot fails on a=0 b=0. At 20, both writes come from one process with no wait, so the block sees only the legal result.

The assume fails at 30 like an assertion would. In a formal tool, it would instead stop the tool from ever trying mode 3. Delete the #0, so both writes at 10 come from one step, and predict the new count.

RUNVerilator · simulator service
Edit the code, then run it
Expected: t=10 one_hot failed: a=0 b=0 t=30 mode_ok failed: mode=11 fails=1

Check Yourself

Predict the outputv starts unknown. Icarus is a four-state simulator. Predict the exact output.
module tb;
  logic v = 1'bx;
  initial begin
    #1 assert (v) $display("pass"); else $display("fail: v=%b", v);
  end
endmodule
Spot the bugEach option checks that a and b are one-hot. The legal traffic moves the 1 from a to b in two steps, between clock edges. Which option fails on legal traffic?
Spot the bugThe bench must keep running after a failed check, so it can count every failure. Which else action breaks that on a standard simulator?
ConceptA bench promises never to drive mode to 3. Which statement fits that promise, and why?
ConceptWhat does the number in $fatal(2, "no config") choose?

Common Mistakes

Wrong Put an immediate assertion in an always @(*) block to check a combinational output.

The block can run several times in one time step, so the check can fire on a value that never settles.

Fix Check at a clock edge, or use a deferred assertion that reports the last result of the time step.

Before
always @(*) begin
  y = dec(sel);
  assert ($onehot(y));
end
After
always @(posedge clk)
  y_ok: assert ($onehot(y))
    else $error("y=%b", y);

Wrong End every failed check with $fatal to make failures impossible to miss.

The run stops at the first failure, so every later bug in the same run stays hidden.

Fix Use $error for broken rules, and keep $fatal for states where going on means nothing.

Wrong Count scenarios with the statement of an immediate cover on Verilator or Icarus.

Neither tool runs that statement, so the count stays at 0 while the scenario happens.

Fix Count with if (expr) hits++;, and read the cover from a tool that supports it.

Remember

  • An immediate assertion runs when the procedure reaches it, on current values, and takes no time.
  • An expression that is 0, x or z fails; a known nonzero value passes.
  • In code that runs several times per time step, an immediate check can fire on a passing glitch.
  • assume is checked like assert in simulation; a formal tool obeys it instead.
  • Only $fatal ends the run in the standard; $error, $warning and $info report and go on.

Practice

Report a problem with this page