Tutorials

Protocols

Learn More

The expect statement is a procedural blocking statement that is similar to an assert statement and used to block the execution until the property is evaluated. It must be used with procedural blocks like always, initial blocks, tasks, and functions.

What Does an Expect Statement Do?

The statement is useful when procedural code must wait for a timed behavior to complete before moving to the next instruction. It can be placed in procedural code such as an initial block, an always block, or a task.

When execution reaches expect, the property begins one evaluation. The process waits while the property is active. After the property passes or fails, the matching action runs and normal execution continues with the following statement.

Expect Statement Syntax

expect (property_spec)
  pass_statement;
else
  fail_statement;
  • property_spec describes the temporal behavior to evaluate.
  • pass_statement runs when the property succeeds.
  • fail_statement runs when the property fails.

Difference between assert and expect statement

assert property is a concurrent assertion. It runs as an independent monitor and does not stop the surrounding procedural code from continuing.

expect is a procedural blocking statement. It evaluates one attempt when reached and pauses only the process that executed it. Other simulation processes continue to run normally.

Syntax:

expect (property or sequence) <statements>

Usage: To execute some procedural code after a series of sequences.

Note: The “expect” statement does not infer the clock from its procedural block, it has to be explicitly specified in the sequence/ property or within the expect statement.

Example 1: clock specified within the expect statement

What this example explains: after 100 time units, the process waits for the clocked property to finish before printing the final message.

initial begin
  #100;
  expect(@(posedge clk) req1 ##2 req2) else $error "expect failure");
  <statement>;
end

At the first relevant rising edge after the expect starts, req1 is sampled. If req1 is false, the attempt fails at that point. If req1 is true, the statement waits two more rising edges and then checks req2.

The last $display executes only after the pass or fail action has finished, which demonstrates the blocking behavior.

Example 2: clock specified within the property block

The same temporal expression can be declared as a named property. The expect statement then evaluates that property.

property prop;
  @(posedge clk) req1 ##2 req2;
endproperty

initial begin
  #100;
  expect prop else $error "expect failure");
  <statement>;
end

After 100 time units, whenever posedge of a clock happens, req1 is true, followed by 2 clock cycles, req2 is true to pass the expect statement (otherwise, it fails), and then only <statement> can be executed.

Clock Requirement

An expect statement does not obtain its assertion clock from the procedural block around it. Specify the clock inside the expect property expression or inside the named property, as shown above.